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
This commit is contained in:
André Pönitz 2001-08-10 10:39:56 +00:00
parent 7a058f4f03
commit 431543cc20
4 changed files with 35 additions and 9 deletions

View File

@ -206,14 +206,34 @@ void MathGridInset::draw(Painter & pain, int x, int y) const
void MathGridInset::write(std::ostream & os, bool fragile) const void MathGridInset::write(std::ostream & os, bool fragile) const
{ {
for (int row = 0; row < nrows(); ++row) { for (int row = 0; row < nrows(); ++row) {
if (row)
os << " \\\\\n";
for (int col = 0; col < ncols(); ++col) { for (int col = 0; col < ncols(); ++col) {
if (col)
os << " & ";
cell(index(row, col)).write(os, fragile); 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 " & ";
} }

View File

@ -125,6 +125,11 @@ public:
std::vector<int> idxBetween(int from, int to) const; std::vector<int> idxBetween(int from, int to) const;
protected: 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 /// row info
std::vector<RowInfo> rowinfo_; std::vector<RowInfo> rowinfo_;
/// column info /// column info

View File

@ -141,11 +141,8 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const
bool n = numberedType(); bool n = numberedType();
for (int row = 0; row < nrows(); ++row) { for (int row = 0; row < nrows(); ++row) {
if (row)
os << " \\\\\n";
for (int col = 0; col < ncols(); ++col) { for (int col = 0; col < ncols(); ++col) {
if (col) os << eocString(col);
os << " & ";
cell(index(row, col)).write(os, fragile); cell(index(row, col)).write(os, fragile);
} }
if (n) { if (n) {
@ -154,6 +151,7 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const
if (nonum_[row]) if (nonum_[row])
os << "\\nonumber "; os << "\\nonumber ";
} }
os << eolString(row);
} }
footer_write(os); footer_write(os);

View File

@ -303,7 +303,7 @@ int Parser::yylex()
while (is_.good()) { while (is_.good()) {
unsigned char c = getuchar(); unsigned char c = getuchar();
//lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl; lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
if (lexcode[c] == LexNewLine) { if (lexcode[c] == LexNewLine) {
++lineno_; ++lineno_;
@ -672,6 +672,8 @@ void Parser::parse_into(MathArray & array, unsigned flags)
break; break;
case LM_TK_NEWLINE: case LM_TK_NEWLINE:
{
lexArg('['); // ignore things like \\[5pt] for a while
if (flags & FLAG_NEWLINE) { if (flags & FLAG_NEWLINE) {
flags &= ~FLAG_NEWLINE; flags &= ~FLAG_NEWLINE;
--plevel; --plevel;
@ -680,6 +682,7 @@ void Parser::parse_into(MathArray & array, unsigned flags)
lyxerr[Debug::MATHED] lyxerr[Debug::MATHED]
<< "found newline unexpectedly, array: '" << array << "'\n"; << "found newline unexpectedly, array: '" << array << "'\n";
break; break;
}
case LM_TK_PROTECT: case LM_TK_PROTECT:
break; break;