mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-14 09:32:20 +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. 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().
This commit is contained in:
parent
15d1349847
commit
edc1ce4068
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user