Repository: Khan/KaTeX
Pull request #796 (2017-08-16 08:04:52)

Add latin-1 letters as math symbols
Currently katex throws an EOF parse error when receiving an input of latin-1 letters that is not inside a `\text{}` clause. To prevent this the latin-1 letters are added as math-symbols as well. 

![skarmavbild 2017-08-16 kl 09 47 12](https://user-images.githubusercontent.com/9054842/29352910-c6415b1e-8268-11e7-9d77-1321359dbcf0.png)


khanbot: CLA signature looks good :+1:
spicyj: I can't tell, is that Computer Modern in your screenshot? Not sure if our fonts support these chars.
chrismessiah: Good catch. Didn't notice that they were using different fonts. What is the procedure for adding such letters to the font? 

<img width="406" alt="skarmavbild 2017-08-16 kl 21 46 54" src="https://user-images.githubusercontent.com/9054842/29382311-76c80f7e-82cc-11e7-8263-66c61a66bb45.png">

kevinbarabash: Oh noes... we aren't using CM for latin-1 chars inside `\text` either.  Having this work correctly will require #632 and the some additional work to actually render combining marks for each of the accent types.  We'll also need to update how we calculate the height (ascent) and depth (descent) for the combined glyphs that we construct.  There's a fair amount of work involved so it's probably best to split it up.  I'm okay with this diff as is, but we should aim for rendering CM glyphs for latin-1 eventually.
edemaine: Given that KaTeX already supports math-mode accents, we should be able to macro each Latin-1 Unicode character in math mode to the corresponding accent command (ideally with a loop over the characters and a call to some Unicode splitting).

To fix Latin-1 characters in text mode, we should first do #638 (text-mode accent functions).  Then we can follow the above approach.
kevinbarabash: @edemaine can a macro be defined for something without a leading `\`?
kevinbarabash: I've added a project to track work relating to latin-1 support.
edemaine: @kevinbarabash No, macros currently need to start with `\`. But we could easily add support for single-character macros (in the spirit of TeX active characters). I'll give it a try... 
edemaine: Moving discussion to #801

Patch:
diff --git a/src/symbols.js b/src/symbols.js
index 192ed744..0cda21ce 100644
--- a/src/symbols.js
+++ b/src/symbols.js
@@ -671,16 +671,19 @@ for (let i = 0; i < letters.length; i++) {
 // Latin-1 letters
 for (let i = 0x00C0; i <= 0x00D6; i++) {
     const ch = String.fromCharCode(i);
+    defineSymbol(math, main, mathord, ch, ch);
     defineSymbol(text, main, textord, ch, ch);
 }
 
 for (let i = 0x00D8; i <= 0x00F6; i++) {
     const ch = String.fromCharCode(i);
+    defineSymbol(math, main, mathord, ch, ch);
     defineSymbol(text, main, textord, ch, ch);
 }
 
 for (let i = 0x00F8; i <= 0x00FF; i++) {
     const ch = String.fromCharCode(i);
+    defineSymbol(math, main, mathord, ch, ch);
     defineSymbol(text, main, textord, ch, ch);
 }
 


Test patch:
diff --git a/test/unicode-spec.js b/test/unicode-spec.js
index dca0b873..6037ec84 100644
--- a/test/unicode-spec.js
+++ b/test/unicode-spec.js
@@ -70,8 +70,8 @@ describe("unicode", function() {
         expect('\\text{ÀàÇçÉéÏïÖöÛû}').toParse();
     });
 
-    it("should not parse Latin-1 outside \\text{}", function() {
-        expect('ÀàÇçÉéÏïÖöÛû').toNotParse();
+    it("should parse Latin-1 outside \\text{}", function() {
+        expect('ÀàÇçÉéÏïÖöÛû').toParse();
     });
 
     it("should parse Cyrillic inside \\text{}", function() {