Fix bug #1337: LyX confused on $ symbol in math equations

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@35066 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-08-06 21:00:21 +00:00
parent 13ec8f7b1b
commit 22879bac7a
2 changed files with 30 additions and 17 deletions

View File

@ -848,9 +848,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();
@ -871,8 +878,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);
}
}
}
@ -1216,12 +1234,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
}
else if (t.cs() == "(") {
if (mode == InsetMath::MATH_MODE) {
error("bad math environment");
break;
}
cell->push_back(MathAtom(new InsetMathHull(buf, hullSimple)));
parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false);
cell->push_back(MathAtom(new InsetMathEnsureMath(buf)));
parse(cell->back().nucleus()->cell(0), FLAG_SIMPLE2, InsetMath::MATH_MODE);
}
else if (t.cs() == "[") {
@ -1493,12 +1507,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
}
else if (name == "math") {
if (mode == InsetMath::MATH_MODE) {
error("bad math environment");
break;
}
cell->push_back(MathAtom(new InsetMathHull(buf, hullSimple)));
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true);
cell->push_back(MathAtom(new InsetMathEnsureMath(buf)));
parse(cell->back().nucleus()->cell(0), FLAG_END, InsetMath::MATH_MODE);
}
else if (name == "equation" || name == "equation*"

View File

@ -75,6 +75,9 @@ What's new
- Fix mouse wheel scrolling on Mac OS 10.6 (bug 6775).
- Fix parsing of in-line math environments nested in (unknown to LyX)
text-mode user macros (bug 1337).
* DOCUMENTATION AND LOCALIZATION