fix bug 2067

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10553 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2005-10-14 10:50:23 +00:00
parent 55c5fcb30c
commit 4341a88656
7 changed files with 58 additions and 18 deletions

View File

@ -1,3 +1,17 @@
2005-10-13 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* math_gridinset.[Ch] (eolString, write): Output \\ at the end of the last
line if it is empty (fixes bug 2067)
* math_hullinset.[Ch] (eolString): Adjust to the changes above
* math_hullinset.C (delRow): Allow to delete the last dummy row
* math_parser.C (delEmptyLastRow): Delete the last dummy row.
The last hline appears in the wrong row otherwise.
* math_parser.C (parse1): Call delEmptyLastRow for all matrix like
insets. This fixes bug 2067 and avoids data loss on load/save cycles.
* math_parser.C (parse1): Ignore the number of columns of alignedat
* math_splitinset.C (write): Write the number of column of alignedat.
This prevents data loss together with the math parser change above.
2005-10-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* math_gridinset.C (doDispatch): adjust paste to match paste in text

View File

@ -606,7 +606,7 @@ void MathGridInset::drawT(TextPainter & pain, int x, int y) const
}
string MathGridInset::eolString(row_type row, bool fragile) const
string MathGridInset::eolString(row_type row, bool emptyline, bool fragile) const
{
string eol;
@ -622,7 +622,7 @@ string MathGridInset::eolString(row_type row, bool fragile) const
}
// only add \\ if necessary
if (eol.empty() && row + 1 == nrows())
if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
return string();
return (fragile ? "\\protect\\\\" : "\\\\") + eol;
@ -951,6 +951,7 @@ void MathGridInset::mathmlize(MathMLStream & os) const
void MathGridInset::write(WriteStream & os) const
{
string eol;
for (row_type row = 0; row < nrows(); ++row) {
os << verboseHLine(rowinfo_[row].lines_);
// don't write & and empty cells at end of line
@ -963,17 +964,21 @@ void MathGridInset::write(WriteStream & os) const
}
for (col_type col = 0; col < lastcol; ++col)
os << cell(index(row, col)) << eocString(col, lastcol);
os << eolString(row, os.fragile());
eol = eolString(row, emptyline, os.fragile());
os << eol;
// append newline only if line wasn't completely empty
// and this was not the last line in the grid
if (!emptyline && row + 1 < nrows())
os << "\n";
}
string const s = verboseHLine(rowinfo_[nrows()].lines_);
if (!s.empty() && s != " ") {
if (os.fragile())
os << "\\protect";
os << "\\\\" << s;
if (!s.empty()) {
if (eol.empty()) {
if (os.fragile())
os << "\\protect";
os << "\\\\";
}
os << s;
}
}

View File

@ -219,7 +219,8 @@ protected:
/// returns y offset of cell compared to inset
int cellYOffset(idx_type idx) const;
/// returns proper 'end of line' code for LaTeX
virtual std::string eolString(row_type row, bool fragile = false) const;
virtual std::string eolString(row_type row, bool emptyline,
bool fragile) const;
/// returns proper 'end of column' code for LaTeX
virtual std::string eocString(col_type col, col_type lastcol) const;
/// extract number of columns from alignment string
@ -227,7 +228,6 @@ protected:
/// splits cells and shifts right part to the next cell
void splitCell(LCursor & cur);
public:
/// row info.
/// rowinfo_[nrows()] is a dummy row used only for hlines.
std::vector<RowInfo> rowinfo_;

View File

@ -588,6 +588,10 @@ void MathHullInset::delRow(row_type row)
if (nrows() <= 1 || !rowChangeOK())
return;
MathGridInset::delRow(row);
// The last dummy row has no number info nor a label.
// Test nrows() + 1 because we have already erased the row.
if (row == nrows() + 1)
row--;
nonum_.erase(nonum_.begin() + row);
label_.erase(label_.begin() + row);
}
@ -850,7 +854,7 @@ void MathHullInset::mutate(string const & newtype)
}
string MathHullInset::eolString(row_type row, bool fragile) const
string MathHullInset::eolString(row_type row, bool emptyline, bool fragile) const
{
string res;
if (numberedType()) {
@ -859,7 +863,7 @@ string MathHullInset::eolString(row_type row, bool fragile) const
if (nonum_[row] && (type_ != "multline"))
res += "\\nonumber ";
}
return res + MathGridInset::eolString(row, fragile);
return res + MathGridInset::eolString(row, emptyline, fragile);
}

View File

@ -56,7 +56,7 @@ public:
std::vector<std::string> & list) const;
///
void validate(LaTeXFeatures & features) const;
/// identifies MatrixInsets
/// identifies HullInset
MathHullInset const * asHullInset() const { return this; }
/// identifies HullInset
MathHullInset * asHullInset() { return this; }
@ -126,7 +126,7 @@ protected:
bool getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & status) const;
///
std::string eolString(row_type row, bool fragile) const;
std::string eolString(row_type row, bool emptyline, bool fragile) const;
private:
virtual std::auto_ptr<InsetBase> doClone() const;

View File

@ -181,7 +181,9 @@ void delEmptyLastRow(MathGridInset & grid)
if (!grid.cell(grid.index(row, col)).empty())
return;
}
grid.delRow(row);
// Remove the dummy row, so that the previous last row (that would
// contain the last hline in the example above) becomes the dummy row.
grid.delRow(row + 1);
}
@ -935,8 +937,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
environments_.back() + "}'");
else {
environments_.pop_back();
if (name == "array" ||
name == "subarray")
// Delete empty last row in matrix
// like insets.
// If you abuse MathGridInset for
// non-matrix like structures you
// probably need to refine this test.
// Right now we only have to test for
// single line hull insets.
if (grid.nrows() > 1)
delEmptyLastRow(grid);
return;
}
@ -1089,8 +1097,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
else if (name == "split" || name == "cases" ||
name == "gathered" || name == "aligned" ||
name == "alignedat") {
name == "gathered" || name == "aligned") {
cell->push_back(createMathInset(name));
parse2(cell->back(), FLAG_END, mode, false);
}
else if (name == "alignedat") {
// ignore this for a while
getArg('{', '}');
cell->push_back(createMathInset(name));
parse2(cell->back(), FLAG_END, mode, false);
}
@ -1187,6 +1201,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
else if (t.cs() == "label") {
// FIXME: This is swallowed in inline formulas
string label = parse_verbatim_item();
MathArray ar;
asArray(label, ar);

View File

@ -88,6 +88,8 @@ void MathSplitInset::write(WriteStream & ws) const
if (ws.fragile())
ws << "\\protect";
ws << "\\begin{" << name_ << '}';
if (name_ == "alignedat")
ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
MathGridInset::write(ws);
if (ws.fragile())
ws << "\\protect";