commit 7f373e8de1eb02e869128b7376196e461747b2c4
Author: Georg Baum <[email protected]>
Date:   Wed Feb 26 21:54:09 2014 +0100

    Fix misparsing of alternative simple formulas
    
    This comes from trying to run tex2lyx on the AMS math test document
    testmath.tex. Both \(...\) and \begin{math}...\end{math} are defined as
    inline math formulas in standard LaTeX. tex2lyx recognizes this, but the
    math parser in LyX did not handle "\begin_inset Formula \(" and
    "\begin_inset Formula \begin{math}" correctly.
    The fix is simple and safe: If we are in undecided mode (this is only true
    for the first token of a math inset), create a hull inset of the respective
    kind. Otherwise, handle the commands as before.

diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 317e7b0..ca66f1c 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -861,7 +861,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                        } else {
                                                // This is not an outer hull 
and display math is
                                                // not allowed inside text mode 
environments.
-                                               error("bad math environment");
+                                               error("bad math environment 
$$");
                                                break;
                                        }
                                } else {
@@ -1240,13 +1240,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned 
flags,
                }
 
                else if (t.cs() == "(") {
-                       cell->push_back(MathAtom(new InsetMathEnsureMath(buf)));
-                       parse(cell->back().nucleus()->cell(0), FLAG_SIMPLE2, 
InsetMath::MATH_MODE);
+                       if (mode == InsetMath::UNDECIDED_MODE) {
+                               cell->push_back(MathAtom(new InsetMathHull(buf, 
hullSimple)));
+                               parse2(cell->back(), FLAG_SIMPLE2, 
InsetMath::MATH_MODE, false);
+                       } else {
+                               // Don't create nested math hulls (bug #5392)
+                               cell->push_back(MathAtom(new 
InsetMathEnsureMath(buf)));
+                               parse(cell->back().nucleus()->cell(0), 
FLAG_SIMPLE2, InsetMath::MATH_MODE);
+                       }
                }
 
                else if (t.cs() == "[") {
                        if (mode != InsetMath::UNDECIDED_MODE) {
-                               error("bad math environment");
+                               error("bad math environment [");
                                break;
                        }
                        cell->push_back(MathAtom(new InsetMathHull(buf, 
hullEquation)));
@@ -1567,14 +1573,20 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned 
flags,
                        }
 
                        else if (name == "math") {
-                               cell->push_back(MathAtom(new 
InsetMathEnsureMath(buf)));
-                               parse(cell->back().nucleus()->cell(0), 
FLAG_END, InsetMath::MATH_MODE);
+                               if (mode == InsetMath::UNDECIDED_MODE) {
+                                       cell->push_back(MathAtom(new 
InsetMathHull(buf, hullSimple)));
+                                       parse2(cell->back(), FLAG_END, 
InsetMath::MATH_MODE, false);
+                               } else {
+                                       // Don't create nested math hulls (bug 
#5392)
+                                       cell->push_back(MathAtom(new 
InsetMathEnsureMath(buf)));
+                                       parse(cell->back().nucleus()->cell(0), 
FLAG_END, InsetMath::MATH_MODE);
+                               }
                        }
 
                        else if (name == "equation" || name == "equation*"
                                        || name == "displaymath") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullEquation)));
@@ -1583,7 +1595,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "eqnarray" || name == "eqnarray*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullEqnArray)));
@@ -1592,7 +1604,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "align" || name == "align*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       // FIXME this is wrong: amsmath supports
+                                       //       align* inside gather, see 
testmath.tex.
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullAlign)));
@@ -1601,7 +1615,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "flalign" || name == "flalign*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullFlAlign)));
@@ -1610,7 +1624,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "alignat" || name == "alignat*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                // ignore this for a while
@@ -1621,7 +1635,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "xalignat" || name == "xalignat*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                // ignore this for a while
@@ -1632,7 +1646,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "xxalignat") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                // ignore this for a while
@@ -1643,7 +1657,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "multline" || name == "multline*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullMultline)));
@@ -1652,7 +1666,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else if (name == "gather" || name == "gather*") {
                                if (mode != InsetMath::UNDECIDED_MODE) {
-                                       error("bad math environment");
+                                       error("bad math environment " + name);
                                        break;
                                }
                                cell->push_back(MathAtom(new InsetMathHull(buf, 
hullGather)));

Reply via email to