commit edc1ce40688d95402cfde1217bb6a51cae87fa4d
Author: Georg Baum <[email protected]>
Date:   Thu Feb 12 21:36:01 2015 +0100

    Fix unwanted curly braces in formula (bug #8679)
    
    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().

diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 20c1ac6..8dc6a9d 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -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())
diff --git a/status.21x b/status.21x
index 200521b..c589e70 100644
--- a/status.21x
+++ b/status.21x
@@ -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

Reply via email to