]> git.lyx.org Git - features.git/commitdiff
Refine fix for bug #1337.
authorEnrico Forestieri <forenr@lyx.org>
Fri, 23 Jul 2010 07:34:26 +0000 (07:34 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 23 Jul 2010 07:34:26 +0000 (07:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35009 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/MathParser.cpp

index 8ad3173d224206c95064847bf0ffb8d1606d3a96..1803da7f3a217917912e1989bf0b2bfb2e37eea4 100644 (file)
@@ -849,9 +849,16 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                Token const & n = getToken();
                                if (n.cat() == catMath) {
                                        // TeX's $$...$$ syntax for displayed math
-                                       cell->push_back(MathAtom(new InsetMathHull(buf, hullEquation)));
-                                       parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
-                                       getToken(); // skip the second '$' token
+                                       if (mode == InsetMath::UNDECIDED_MODE) {
+                                               cell->push_back(MathAtom(new InsetMathHull(buf, hullEquation)));
+                                               parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
+                                               getToken(); // skip the second '$' token
+                                       } else {
+                                               // This is not an outer hull and display math is
+                                               // not allowed inside text mode environments.
+                                               error("bad math environment");
+                                               break;
+                                       }
                                } else {
                                        // simple $...$  stuff
                                        putback();
@@ -872,8 +879,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        }
 
                        else {
-                               error("something strange in the parser");
-                               break;
+                               Token const & n = getToken();
+                               if (n.cat() == catMath) {
+                                       error("something strange in the parser");
+                                       break;
+                               } else {
+                                       // This is inline math ($...$), but the parser thinks we are
+                                       // already in math mode and latex would issue an error, unless we
+                                       // are inside a text mode user macro. We have no way to tell, so
+                                       // let's play safe by using \ensuremath, as it will work in any case.
+                                       putback();
+                                       cell->push_back(MathAtom(new InsetMathEnsureMath(buf)));
+                                       parse(cell->back().nucleus()->cell(0), FLAG_SIMPLE, InsetMath::MATH_MODE);
+                               }
                        }
                }