mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
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.
This commit is contained in:
parent
0e0746c703
commit
0385ef0e19
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user