]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.C
Convert to unicode.
[lyx.git] / src / mathed / MathParser.C
index c3a17c2875b72b2bf7d4706754789b307f444fd7..cb208ffca3c78798280fe2cb0b0a89a2f54185af 100644 (file)
@@ -213,11 +213,19 @@ enum CatCode {
        catInvalid     // 15   <delete>
 };
 
-CatCode theCatcode[256];
+CatCode theCatcode[128];
 
 
-inline CatCode catcode(unsigned char c)
+inline CatCode catcode(lyx::char_type c)
 {
+       /* The fact that we use unicode internally does not change Knuth's TeX
+       engine. It is still 7bit only, not even latin1 or something like that.
+       Therefore, the catcode table needs only to have 128 entries.
+       Everything not in that range is catOther.
+       */
+       if (c >= 128)
+               return catOther;
+
        return theCatcode[c];
 }
 
@@ -816,9 +824,13 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                cell->back() = MathAtom(new InsetMathScript(cell->back(), up));
                        InsetMathScript * p = cell->back().nucleus()->asScriptInset();
                        // special handling of {}-bases
+                       // Test for empty brace inset, otherwise \xxx{\vec{H}}_{0}
+                       // where \xxx is an unknown command gets misparsed to
+                       // \xxx\vec{H}_{0}, and that is invalid LaTeX.
                        // is this always correct?
-                       if (p->nuc().size() == 1 
-                           && p->nuc().back()->asBraceInset())
+                       if (p->nuc().size() == 1 &&
+                           p->nuc().back()->asBraceInset() &&
+                           p->nuc().back()->asBraceInset()->cell(0).empty())
                                p->nuc() = p->nuc().back()->asNestInset()->cell(0);
                        parse(p->cell(p->idxOfScript(up)), FLAG_ITEM, mode);
                        if (limits) {
@@ -1444,7 +1456,7 @@ void mathed_parse_normal(InsetMathGrid & grid, string const & str)
 
 void initParser()
 {
-       fill(theCatcode, theCatcode + 256, catOther);
+       fill(theCatcode, theCatcode + 128, catOther);
        fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
        fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);