]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
A little cleanup of the layout files.
[lyx.git] / src / mathed / MathParser.cpp
index c16e3cfe06d9b59fc0b48b482ac042691f595fa1..36be12c2ec94a29a5c4508013c7016e45af82b96 100644 (file)
@@ -46,6 +46,7 @@ following hack as starting point to write some macros:
 #include "InsetMathColor.h"
 #include "InsetMathComment.h"
 #include "InsetMathDelim.h"
+#include "InsetMathEnsureMath.h"
 #include "InsetMathEnv.h"
 #include "InsetMathFrac.h"
 #include "InsetMathKern.h"
@@ -804,8 +805,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                } else {
                                        // simple $...$  stuff
                                        putback();
-                                       cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
-                                       parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
+                                       if (mode == InsetMath::UNDECIDED_MODE) {
+                                               cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
+                                               parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
+                                       } else {
+                                               // Don't create nested math hulls (bug #5392)
+                                               cell->push_back(MathAtom(new InsetMathEnsureMath));
+                                               parse(cell->back().nucleus()->cell(0), FLAG_SIMPLE, InsetMath::MATH_MODE);
+                                       }
                                }
                        }
 
@@ -909,14 +916,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)));
                                }
@@ -1302,6 +1311,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;
@@ -1316,6 +1326,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);