From 4341a886562990b995c1409e2ae5435d8ca232c0 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 14 Oct 2005 10:50:23 +0000 Subject: [PATCH] fix bug 2067 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10553 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 14 ++++++++++++++ src/mathed/math_gridinset.C | 19 ++++++++++++------- src/mathed/math_gridinset.h | 4 ++-- src/mathed/math_hullinset.C | 8 ++++++-- src/mathed/math_hullinset.h | 4 ++-- src/mathed/math_parser.C | 25 ++++++++++++++++++++----- src/mathed/math_splitinset.C | 2 ++ 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index b138600eec..263899e302 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,17 @@ +2005-10-13 Georg Baum + + * 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 * math_gridinset.C (doDispatch): adjust paste to match paste in text diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 29c1d1200a..3ca1497450 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -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; } } diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 525eb8c43d..6a64fed561 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -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_; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 972f0d0364..b264756962 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -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); } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 98d9ae869b..a9d2387ba6 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -56,7 +56,7 @@ public: std::vector & 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 doClone() const; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 216c49df55..cd7fd101b3 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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); diff --git a/src/mathed/math_splitinset.C b/src/mathed/math_splitinset.C index e372b5d658..b5ccfe3706 100644 --- a/src/mathed/math_splitinset.C +++ b/src/mathed/math_splitinset.C @@ -88,6 +88,8 @@ void MathSplitInset::write(WriteStream & ws) const if (ws.fragile()) ws << "\\protect"; ws << "\\begin{" << name_ << '}'; + if (name_ == "alignedat") + ws << '{' << static_cast((ncols() + 1)/2) << '}'; MathGridInset::write(ws); if (ws.fragile()) ws << "\\protect"; -- 2.39.2