]> git.lyx.org Git - features.git/commitdiff
Fix unwanted curly braces in formula (bug #8679)
authorGeorg Baum <baum@lyx.org>
Thu, 12 Feb 2015 20:36:01 +0000 (21:36 +0100)
committerGeorg Baum <baum@lyx.org>
Thu, 12 Feb 2015 20:36:01 +0000 (21:36 +0100)
There was an unsymmetry between reading and writing: InsetMathGrid::eolString()
adds curly braces if the first cell of the next line starts with [ to prevent
misparsing as optional argument of \\. These braces were not removed on reading.

Thanks to Enrico, who noticed that the previous fix did not take into account
the case of nonempty length argument + the next line beginning with [.
Now the parsing is exactly the inverse of InsetMathGrid::eolString().

src/mathed/MathParser.cpp
status.21x

index 20c1ac67a51bbc3a8ee5a73bb8111a7576424949..8dc6a9d26d19092a44d05badc8d22081162f5dfd 100644 (file)
@@ -400,6 +400,12 @@ public:
        int lineno() const { return lineno_; }
        ///
        void putback();
+       /// store current position
+       void pushPosition();
+       /// restore previous position
+       void popPosition();
+       /// forget last saved position
+       void dropPosition();
 
 private:
        ///
@@ -447,6 +453,8 @@ private:
        vector<Token> tokens_;
        ///
        unsigned pos_;
+       ///
+       std::vector<unsigned> positions_;
        /// Stack of active environments
        vector<docstring> environments_;
        ///
@@ -528,6 +536,25 @@ void Parser::putback()
 }
 
 
+void Parser::pushPosition()
+{
+       positions_.push_back(pos_);
+}
+
+
+void Parser::popPosition()
+{
+       pos_ = positions_.back();
+       positions_.pop_back();
+}
+
+
+void Parser::dropPosition()
+{
+       positions_.pop_back();
+}
+
+
 bool Parser::good() const
 {
        return pos_ < tokens_.size();
@@ -1307,14 +1334,36 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                else if (t.cs() == "\\") {
                        if (flags & FLAG_ALIGN)
                                return success_;
-                       bool added = false;
+                       bool starred = false;
+                       docstring arg;
                        if (nextToken().asInput() == "*") {
                                getToken();
-                               added = addRow(grid, cellrow, docstring(), false);
-                       } else if (good())
-                               added = addRow(grid, cellrow, getArg('[', ']'));
-                       else
+                               starred = true;
+                       } else if (nextToken().asInput() == "[")
+                               arg = getArg('[', ']');
+                       else if (!good())
                                error("missing token after \\\\");
+                       // skip "{}" added in front of "[" (the
+                       // counterpart is in InsetMathGrid::eolString())
+                       // skip spaces because formula could come from tex2lyx
+                       bool skipBraces = false;
+                       pushPosition();
+                       if (nextToken().cat() == catBegin) {
+                               getToken();
+                               if (nextToken().cat() == catEnd) {
+                                       getToken();
+                                       pushPosition();
+                                       skipSpaces();
+                                       if (nextToken().asInput() == "[")
+                                               skipBraces = true;
+                                       popPosition();
+                               }
+                       }
+                       if (skipBraces)
+                               dropPosition();
+                       else
+                               popPosition();
+                       bool const added = addRow(grid, cellrow, arg, !starred);
                        if (added) {
                                cellcol = 0;
                                if (grid.asHullInset())
index 200521b7f73dbf5bf846b2eabd2765a9c2ca522d..c589e7039b747476e4b7951c3bcdc9bf8f6296d1 100644 (file)
@@ -73,6 +73,9 @@ What's new
 
 - Work around limitations of external image viewers on windows (bug 8892).
 
+- Do not display unwanted curly brackets in multi-line formulas (happened if
+  the first character in a row was a '[') (bug 8679).
+
 
 
 * INTERNALS