[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-cvs
Subject: [LyX/master] Fix unwanted curly braces in formula (bug #8679)
From: Georg Baum <baum () lyx ! org>
Date: 2014-11-20 21:06:45
Message-ID: 20141120210645.85FFA28078A () lyx ! lyx ! org
[Download RAW message or body]
commit 0385ef0e192a779aed13aab0fd4a9bd4a03f37e0
Author: Georg Baum <baum@lyx.org>
Date: Thu Nov 20 22:05:05 2014 +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.
diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 21621a3..ef8cc0b 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();
@@ -1311,10 +1338,35 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
if (nextToken().asInput() == "*") {
getToken();
added = addRow(grid, cellrow, docstring(), false);
- } else if (good())
- added = addRow(grid, cellrow, getArg('[', ']'));
- else
- error("missing token after \\\\");
+ } else {
+ // skip "{}" added in front of "[" (the
+ // counterpart is in InsetMathGrid::eolString())
+ // skip spaces because formula could come from tex2lyx
+ bool skipBraces = false;
+ pushPosition();
+ skipSpaces();
+ if (nextToken().cat() == catBegin) {
+ getToken();
+ skipSpaces();
+ if (nextToken().cat() == catEnd) {
+ getToken();
+ skipSpaces();
+ if (nextToken().asInput() == "[")
+ skipBraces = true;
+ }
+ }
+ if (skipBraces)
+ dropPosition();
+ else
+ popPosition();
+ if (good()) {
+ docstring arg;
+ if (!skipBraces)
+ arg = getArg('[', ']');
+ added = addRow(grid, cellrow, arg);
+ } else
+ error("missing token after \\\\");
+ }
if (added) {
cellcol = 0;
if (grid.asHullInset())
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic