]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
InsetMathFrac: reimplement \cfrac with its optional argument the way Enrico proposed...
[lyx.git] / src / mathed / MathParser.cpp
index 7456fce668c5800f1b42fb41496ceeffdeb0fd84..757458cc88329a83cafe70db7ba35576578675b9 100644 (file)
@@ -909,14 +909,16 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                else if (t.cat() == catOther) {
                        char_type c = t.character();
-                       if (c < 0x80 || mode_ & Parse::VERBATIM
-                           || !(mode_ & Parse::USETEXT)) {
+                       if (isAsciiOrMathAlpha(c)
+                           || mode_ & Parse::VERBATIM
+                           || !(mode_ & Parse::USETEXT)
+                           || mode == InsetMath::TEXT_MODE) {
                                cell->push_back(MathAtom(new InsetMathChar(c)));
                        } else {
                                MathAtom at = createInsetMath("text");
                                at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c)));
                                while (nextToken().cat() == catOther
-                                      && nextToken().character() >= 0x80) {
+                                      && !isAsciiOrMathAlpha(nextToken().character())) {
                                        c = getToken().character();
                                        at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c)));
                                }
@@ -1318,15 +1320,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                }
 
                else if (t.cs() == "cfrac") {
-                       // Here allowed formats are \cfrac[pos]{num}{denom}
-                       MathData ar;
-                       parse(ar, FLAG_OPTION, mode);
-                       if (ar.size()) {
-                               cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRAC, 3)));
-                               cell->back().nucleus()->cell(2) = ar;
-                       } else {
-                               cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRAC)));
-                       }
+                       // allowed formats are \cfrac[pos]{num}{denom}
+                       docstring const arg = getArg('[', ']');
+                       //lyxerr << "got so far: '" << arg << "'" << endl;                              
+                               if (arg == "l")
+                                       cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRACLEFT)));
+                               else if (arg == "r")
+                                       cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRACRIGHT)));
+                               else if (arg.empty() || arg == "c")
+                                       cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRAC)));
+                               else {
+                                       error("found invalid optional argument");
+                                       break;
+                               }
                        parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
                        parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
                }