From 0d78b793118589f468cee4117d237d2247bfa0be Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 23 Jul 2010 07:34:26 +0000 Subject: [PATCH] Refine fix for bug #1337. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35009 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/MathParser.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 8ad3173d22..1803da7f3a 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -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); + } } } -- 2.39.2