]> 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 673c29322477494420821a68d2ba83d4f32f69f0..757458cc88329a83cafe70db7ba35576578675b9 100644 (file)
@@ -907,8 +907,24 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        return success_;
                }
 
-               else if (t.cat() == catOther)
-                       cell->push_back(MathAtom(new InsetMathChar(t.character())));
+               else if (t.cat() == catOther) {
+                       char_type c = t.character();
+                       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
+                                      && !isAsciiOrMathAlpha(nextToken().character())) {
+                                       c = getToken().character();
+                                       at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c)));
+                               }
+                               cell->push_back(at);
+                       }
+               }
 
                else if (t.cat() == catComment) {
                        docstring s;
@@ -1288,6 +1304,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
                        }
                }
+
                else if (t.cs() == "unitfrac") {
                        // Here allowed formats are \unitfrac[val]{num}{denom}
                        MathData ar;
@@ -1302,6 +1319,24 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
                }
 
+               else if (t.cs() == "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);
+               }
+
                else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
                        cell->push_back(createInsetMath(t.cs()));
                        parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
@@ -1639,9 +1674,6 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                else if (t.cs() == "lyxmathsym") {
                        skipSpaces();
-                       if (nextToken().character() == '*')
-                               getToken();
-                       skipSpaces();
                        if (getToken().cat() != catBegin) {
                                error("'{' expected in \\" + t.cs());
                                return success_;