From: André Pönitz Date: Fri, 10 Aug 2001 10:39:56 +0000 (+0000) Subject: improve end-of-line handling in the presence of optional args to \\ X-Git-Tag: 1.6.10~20868 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=431543cc20679f5eec2835c19a22fa7f25568c90;p=features.git improve end-of-line handling in the presence of optional args to \\ git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2477 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 33b211b9ff..95d76d4262 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -206,17 +206,37 @@ void MathGridInset::draw(Painter & pain, int x, int y) const void MathGridInset::write(std::ostream & os, bool fragile) const { for (int row = 0; row < nrows(); ++row) { - if (row) - os << " \\\\\n"; for (int col = 0; col < ncols(); ++col) { - if (col) - os << " & "; cell(index(row, col)).write(os, fragile); + os << eocString(row); } + os << eolString(row); } } +string MathGridInset::eolString(int row) const +{ + if (row == nrows() - 1) + return ""; + + // make sure an upcoming '[' does not break anything + MathArray const & c = cell(index(row + 1, 0)); + if (c.size() && (*c.begin())->getChar() == '[') + return "\\\\[0pt]\n"; + + return "\\\\\n"; +} + + +string MathGridInset::eocString(int col) const +{ + if (col == ncols() - 1) + return ""; + return " & "; +} + + void MathGridInset::addRow(int row) { rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo()); diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 101d506fc3..45356556a6 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -125,6 +125,11 @@ public: std::vector idxBetween(int from, int to) const; protected: + /// returns proper 'end of line' code for LaTeX + string eolString(int row) const; + /// returns proper 'end of column' code for LaTeX + string eocString(int col) const; + /// row info std::vector rowinfo_; /// column info diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index c521e819b0..30b38627c6 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -141,11 +141,8 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const bool n = numberedType(); for (int row = 0; row < nrows(); ++row) { - if (row) - os << " \\\\\n"; for (int col = 0; col < ncols(); ++col) { - if (col) - os << " & "; + os << eocString(col); cell(index(row, col)).write(os, fragile); } if (n) { @@ -154,6 +151,7 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const if (nonum_[row]) os << "\\nonumber "; } + os << eolString(row); } footer_write(os); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 37e3d4be95..86270f47ac 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -303,7 +303,7 @@ int Parser::yylex() while (is_.good()) { unsigned char c = getuchar(); - //lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl; + lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl; if (lexcode[c] == LexNewLine) { ++lineno_; @@ -672,6 +672,8 @@ void Parser::parse_into(MathArray & array, unsigned flags) break; case LM_TK_NEWLINE: + { + lexArg('['); // ignore things like \\[5pt] for a while if (flags & FLAG_NEWLINE) { flags &= ~FLAG_NEWLINE; --plevel; @@ -680,6 +682,7 @@ void Parser::parse_into(MathArray & array, unsigned flags) lyxerr[Debug::MATHED] << "found newline unexpectedly, array: '" << array << "'\n"; break; + } case LM_TK_PROTECT: break;