mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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.
This commit is contained in:
parent
9130bdb5ec
commit
7f373e8de1
@ -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)));
|
||||
|
Loading…
Reference in New Issue
Block a user