re-enable the mathcursor->normalize() safety belt.

This trades Asserts() against a console warning


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3103 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-11-28 13:09:40 +00:00
parent cb52251ccf
commit 9b0945a47f
8 changed files with 279 additions and 102 deletions

View File

@ -647,6 +647,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
result = UNDISPATCHED; result = UNDISPATCHED;
} }
mathcursor->normalize();
lyx::Assert(mathcursor); lyx::Assert(mathcursor);
if (mathcursor->selection() || was_selection) if (mathcursor->selection() || was_selection)

View File

@ -24,6 +24,11 @@ MathArrayInset::MathArrayInset(int m, int n, char valign, string const & halign)
{} {}
MathArrayInset::MathArrayInset(char valign, string const & halign)
: MathGridInset(valign, halign)
{}
MathArrayInset::MathArrayInset(string const & str) MathArrayInset::MathArrayInset(string const & str)
: MathGridInset(1, 1) : MathGridInset(1, 1)
{ {
@ -72,11 +77,7 @@ void MathArrayInset::write(WriteStream & os) const
if (v_align_ == 't' || v_align_ == 'b') if (v_align_ == 't' || v_align_ == 'b')
os << '[' << char(v_align_) << ']'; os << '[' << char(v_align_) << ']';
os << '{' << halign().c_str() << "}\n";
os << '{';
for (col_type col = 0; col < ncols(); ++col)
os << colinfo_[col].align_;
os << "}\n";
MathGridInset::write(os); MathGridInset::write(os);

View File

@ -15,6 +15,8 @@ public:
MathArrayInset(int m, int n); MathArrayInset(int m, int n);
/// ///
MathArrayInset(int m, int n, char valign, string const & halign); MathArrayInset(int m, int n, char valign, string const & halign);
///
MathArrayInset(char valign, string const & halign);
/// convienience constructor from whitespace/newline seperated data /// convienience constructor from whitespace/newline seperated data
MathArrayInset(string const & str); MathArrayInset(string const & str);
/// ///

View File

@ -572,6 +572,9 @@ void MathCursor::delLine()
if (par()->nrows() > 1) if (par()->nrows() > 1)
par()->delRow(row()); par()->delRow(row());
if (idx() > par()->nargs())
idx() = par()->nargs();
if (pos() > size()) if (pos() > size())
pos() = size(); pos() = size();
} }

View File

@ -5,17 +5,31 @@
#include "math_gridinset.h" #include "math_gridinset.h"
#include "math_mathmlstream.h" #include "math_mathmlstream.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "Painter.h"
#include "debug.h" #include "debug.h"
namespace { namespace {
/// ///
int const MATH_COLSEP = 10; int const COLSEP = 6;
/// ///
int const MATH_ROWSEP = 10; int const ROWSEP = 6;
/// ///
int const MATH_BORDER = 2; int const HLINESEP = 3;
///
int const VLINESEP = 3;
///
int const BORDER = 2;
string verboseHLine(int n)
{
string res;
for (int i = 0; i < n; ++i)
res += "\\hline";
return res + ' ';
}
} }
@ -24,7 +38,7 @@ int const MATH_BORDER = 2;
MathGridInset::RowInfo::RowInfo() MathGridInset::RowInfo::RowInfo()
: upperline_(false), lowerline_(false) : skip_(0), lines_(0)
{} {}
@ -34,7 +48,7 @@ int MathGridInset::RowInfo::skipPixels() const
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
#warning fix this once the interface to LyXLength has improved #warning fix this once the interface to LyXLength has improved
#endif #endif
return int(skip_.value()); return int(crskip_.value());
} }
@ -43,22 +57,31 @@ int MathGridInset::RowInfo::skipPixels() const
MathGridInset::ColInfo::ColInfo() MathGridInset::ColInfo::ColInfo()
: align_('c'), leftline_(false), rightline_(false), skip_(MATH_COLSEP) : align_('c'), leftline_(false), rightline_(false), lines_(0)
{} {}
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
MathGridInset::MathGridInset(char v, string const & h)
: MathNestInset(guessColumns(h)), rowinfo_(2), colinfo_(guessColumns(h) + 1)
{
setDefaults();
valign(v);
halign(h);
}
MathGridInset::MathGridInset(col_type m, row_type n) MathGridInset::MathGridInset(col_type m, row_type n)
: MathNestInset(m * n), rowinfo_(n), colinfo_(m), v_align_('c') : MathNestInset(m * n), rowinfo_(n + 1), colinfo_(m + 1), v_align_('c')
{ {
setDefaults(); setDefaults();
} }
MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h) MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
: MathNestInset(m * n), rowinfo_(n), colinfo_(m), v_align_(v) : MathNestInset(m * n), rowinfo_(n + 1), colinfo_(m + 1), v_align_(v)
{ {
setDefaults(); setDefaults();
valign(v); valign(v);
@ -75,9 +98,9 @@ MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
void MathGridInset::setDefaults() void MathGridInset::setDefaults()
{ {
if (ncols() <= 0) if (ncols() <= 0)
lyxerr << "positve number of columns expected\n"; lyxerr << "positive number of columns expected\n";
if (nrows() <= 0) if (nrows() <= 0)
lyxerr << "positve number of rows expected\n"; lyxerr << "positive number of rows expected\n";
for (col_type col = 0; col < ncols(); ++col) { for (col_type col = 0; col < ncols(); ++col) {
colinfo_[col].align_ = defaultColAlign(col); colinfo_[col].align_ = defaultColAlign(col);
colinfo_[col].skip_ = defaultColSpace(col); colinfo_[col].skip_ = defaultColSpace(col);
@ -87,11 +110,37 @@ void MathGridInset::setDefaults()
void MathGridInset::halign(string const & hh) void MathGridInset::halign(string const & hh)
{ {
col_type col = 0;
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
char c = *it;
if (c == '|') {
colinfo_[col].lines_++;
} else if (c == 'c' || c == 'l' || c == 'r') {
colinfo_[col].align_ = c;
++col;
colinfo_[col].lines_ = 0;
} else {
lyxerr << "unkown column separator: '" << c << "'\n";
}
}
/*
col_type n = hh.size(); col_type n = hh.size();
if (n > ncols()) if (n > ncols())
n = ncols(); n = ncols();
for (col_type col = 0; col < n; ++col) for (col_type col = 0; col < n; ++col)
colinfo_[col].align_ = hh[col]; colinfo_[col].align_ = hh[col];
*/
}
MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
{
col_type col = 0;
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
if (*it == 'c' || *it == 'l' || *it == 'r')
++col;
return col;
} }
@ -107,6 +156,16 @@ char MathGridInset::halign(col_type col) const
} }
string MathGridInset::halign() const
{
string res;
for (col_type col = 0; col < ncols(); ++col) {
res += string(colinfo_[col].lines_, '|');
res += colinfo_[col].align_;
}
return res + string(colinfo_[ncols()].lines_, '|');
}
void MathGridInset::valign(char c) void MathGridInset::valign(char c)
{ {
@ -120,16 +179,39 @@ char MathGridInset::valign() const
} }
MathGridInset::col_type MathGridInset::ncols() const
void MathGridInset::vskip(LyXLength const & skip, row_type row)
{ {
rowinfo_[row].skip_ = skip; return colinfo_.size() - 1;
} }
LyXLength MathGridInset::vskip(row_type row) const MathGridInset::row_type MathGridInset::nrows() const
{ {
return rowinfo_[row].skip_; return rowinfo_.size() - 1;
}
MathGridInset::col_type MathGridInset::col(idx_type idx) const
{
return idx % ncols();
}
MathGridInset::row_type MathGridInset::row(idx_type idx) const
{
return idx / ncols();
}
void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
{
rowinfo_[row].crskip_ = crskip;
}
LyXLength MathGridInset::vcrskip(row_type row) const
{
return rowinfo_[row].crskip_;
} }
@ -139,6 +221,7 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const
MathNestInset::metrics(mi); MathNestInset::metrics(mi);
// adjust vertical structure // adjust vertical structure
rowinfo_[0].offset_ = 0;
for (row_type row = 0; row < nrows(); ++row) { for (row_type row = 0; row < nrows(); ++row) {
int asc = 0; int asc = 0;
int desc = 0; int desc = 0;
@ -149,59 +232,70 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const
} }
rowinfo_[row].ascent_ = asc; rowinfo_[row].ascent_ = asc;
rowinfo_[row].descent_ = desc; rowinfo_[row].descent_ = desc;
rowinfo_[row].offset_ += asc + HLINESEP * rowinfo_[row].lines_;
if (row) rowinfo_[row + 1].offset_ =
rowinfo_[row].offset_ = rowinfo_[row].offset_ +
rowinfo_[row - 1].offset_ + rowinfo_[row].descent_ +
rowinfo_[row - 1].descent_ + rowinfo_[row].skipPixels() +
rowinfo_[row - 1].skipPixels() + ROWSEP;
MATH_ROWSEP +
rowinfo_[row].ascent_;
else
rowinfo_[row].offset_ = 0;
} }
rowinfo_[nrows()].ascent_ = 0;
rowinfo_[nrows()].descent_ = 0;
rowinfo_[nrows()].offset_ += HLINESEP * rowinfo_[nrows()].lines_;
// adjust vertical offset // adjust vertical offset
int h = 0; int h = 0;
switch (v_align_) { switch (v_align_) {
case 't': case 't':
h = 0; h = 0;
break; break;
case 'b': case 'b':
h = rowinfo_.back().offset_; h = rowinfo_[nrows()].offset_;
break; break;
default: default:
h = rowinfo_.back().offset_ / 2; h = rowinfo_[nrows()].offset_ / 2;
//lyxerr << "\nnrows: " << nrows() << ' ' << ncols() << '\n';
} }
for (row_type row = 0; row <= nrows(); ++row)
for (row_type row = 0; row < nrows(); ++row) {
rowinfo_[row].offset_ -= h; rowinfo_[row].offset_ -= h;
rowinfo_[row].offset_ += MATH_BORDER;
}
// adjust horizontal structure // adjust horizontal structure
colinfo_[0].offset_ = BORDER;
for (col_type col = 0; col < ncols(); ++col) { for (col_type col = 0; col < ncols(); ++col) {
int wid = 0; int wid = 0;
for (row_type row = 0; row < nrows(); ++row) for (row_type row = 0; row < nrows(); ++row)
wid = std::max(wid, xcell(index(row, col)).width()); wid = std::max(wid, xcell(index(row, col)).width());
colinfo_[col].width_ = wid; colinfo_[col].width_ = wid;
colinfo_[col].offset_ = colinfo_[col].width_; colinfo_[col].offset_ += VLINESEP * colinfo_[col].lines_;
if (col) colinfo_[col + 1].offset_ =
colinfo_[col].offset_ = colinfo_[col].offset_ +
colinfo_[col - 1].offset_ + colinfo_[col].width_ +
colinfo_[col - 1].width_ + colinfo_[col].skip_ +
colinfo_[col - 1].skip_; COLSEP;
else
colinfo_[col].offset_ = 0;
colinfo_[col].offset_ += MATH_BORDER;
} }
colinfo_[ncols()].width_ = 0;
colinfo_[ncols()].offset_ += VLINESEP * colinfo_[ncols()].lines_;
width_ = colinfo_[ncols() - 1].offset_
+ colinfo_[ncols() - 1].width_
+ VLINESEP * colinfo_[ncols()].lines_
+ BORDER;
ascent_ = - rowinfo_[0].offset_
+ rowinfo_[0].ascent_
+ HLINESEP * rowinfo_[0].lines_
+ BORDER;
descent_ = rowinfo_[nrows() - 1].offset_
+ rowinfo_[nrows() - 1].descent_
+ HLINESEP * rowinfo_[nrows()].lines_
+ BORDER;
width_ = colinfo_.back().offset_ + colinfo_.back().width_;
ascent_ = - rowinfo_.front().offset_ + rowinfo_.front().ascent_;
descent_ = rowinfo_.back().offset_ + rowinfo_.back().descent_;
/* /*
// Increase ws_[i] for 'R' columns (except the first one) // Increase ws_[i] for 'R' columns (except the first one)
for (int i = 1; i < nc_; ++i) for (int i = 1; i < nc_; ++i)
@ -213,9 +307,9 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const
ws_[0] = 7 * workwidth / 8; ws_[0] = 7 * workwidth / 8;
// Adjust local tabs // Adjust local tabs
width = MATH_COLSEP; width = COLSEP;
for (cxrow = row_.begin(); cxrow; ++cxrow) { for (cxrow = row_.begin(); cxrow; ++cxrow) {
int rg = MATH_COLSEP; int rg = COLSEP;
int lf = 0; int lf = 0;
for (int i = 0; i < nc_; ++i) { for (int i = 0; i < nc_; ++i) {
bool isvoid = false; bool isvoid = false;
@ -245,9 +339,9 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const
} }
int const ww = (isvoid) ? lf : lf + cxrow->getTab(i); int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
cxrow->setTab(i, lf + rg); cxrow->setTab(i, lf + rg);
rg = ws_[i] - ww + MATH_COLSEP; rg = ws_[i] - ww + COLSEP;
if (cxrow == row_.begin()) if (cxrow == row_.begin())
width += ws_[i] + MATH_COLSEP; width += ws_[i] + COLSEP;
} }
cxrow->setBaseline(cxrow->getBaseline() - ascent); cxrow->setBaseline(cxrow->getBaseline() - ascent);
} }
@ -259,30 +353,51 @@ void MathGridInset::draw(Painter & pain, int x, int y) const
{ {
for (idx_type idx = 0; idx < nargs(); ++idx) for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx)); xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
for (row_type row = 0; row <= nrows(); ++row)
for (int i = 0; i < rowinfo_[row].lines_; ++i) {
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
- i * HLINESEP - HLINESEP/2 - ROWSEP/2;
//lyxerr << "i: " << i << " yy: " << yy << '\n';
pain.line(x + 1, yy, x + width_ - 1, yy);
}
for (col_type col = 0; col <= ncols(); ++col)
for (int i = 0; i < colinfo_[col].lines_; ++i) {
int xx = x + colinfo_[col].offset_
- i * VLINESEP - VLINESEP/2 - COLSEP/2;
//lyxerr << "i: " << i << " xx: " << xx << '\n';
pain.line(xx, y - ascent_ + 1, xx, y + descent_ - 1);
}
} }
string MathGridInset::eolString(row_type row) const string MathGridInset::eolString(row_type row) const
{ {
if (row + 1 == nrows()) string eol;
return "";
if (rowinfo_[row].skip_.value() != 0) if (rowinfo_[row].crskip_.value() != 0)
return "\\\\[" + rowinfo_[row].skip_.asLatexString() + "]\n"; eol += "[" + rowinfo_[row].crskip_.asLatexString() + "]";
// make sure an upcoming '[' does not break anything // make sure an upcoming '[' does not break anything
MathArray const & c = cell(index(row + 1, 0)); if (row + 1 < nrows()) {
if (c.size() && (*c.begin())->getChar() == '[') MathArray const & c = cell(index(row + 1, 0));
return "\\\\[0pt]\n"; if (c.size() && c.front()->getChar() == '[')
eol += "[0pt]";
}
return "\\\\\n"; // only add \\ if necessary
if (eol.empty() && row + 1 == nrows())
return string();
return "\\\\" + eol + '\n';
} }
string MathGridInset::eocString(col_type col) const string MathGridInset::eocString(col_type col) const
{ {
if (col + 1 == ncols()) if (col + 1 == ncols())
return ""; return string();
return " & "; return " & ";
} }
@ -297,6 +412,7 @@ void MathGridInset::addRow(row_type row)
void MathGridInset::appendRow() void MathGridInset::appendRow()
{ {
rowinfo_.push_back(RowInfo()); rowinfo_.push_back(RowInfo());
//cells_.insert(cells_.end(), ncols(), MathXArray());
for (col_type col = 0; col < ncols(); ++col) for (col_type col = 0; col < ncols(); ++col)
cells_.push_back(cells_type::value_type()); cells_.push_back(cells_type::value_type());
} }
@ -587,10 +703,14 @@ void MathGridInset::mathmlize(MathMLStream & os) const
void MathGridInset::write(WriteStream & os) const void MathGridInset::write(WriteStream & os) const
{ {
for (row_type row = 0; row < nrows(); ++row) { for (row_type row = 0; row < nrows(); ++row) {
os << verboseHLine(rowinfo_[row].lines_).c_str();
for (col_type col = 0; col < ncols(); ++col) for (col_type col = 0; col < ncols(); ++col)
os << cell(index(row, col)) << eocString(col).c_str(); os << cell(index(row, col)) << eocString(col).c_str();
os << eolString(row).c_str(); os << eolString(row).c_str();
} }
string s = verboseHLine(rowinfo_[nrows()].lines_);
if (s.size())
os << "\\\\" << s.c_str();
} }

View File

@ -30,12 +30,12 @@ class MathGridInset : public MathNestInset {
mutable int ascent_; mutable int ascent_;
/// cached offset /// cached offset
mutable int offset_; mutable int offset_;
/// hline abow this row? /// how many hlines above this row?
bool upperline_; int lines_;
/// hline below this row? /// parameter to the line break
bool lowerline_; LyXLength crskip_;
/// distance /// extra distance between lines
LyXLength skip_; int skip_;
}; };
// additional per-row information // additional per-row information
@ -54,11 +54,15 @@ class MathGridInset : public MathNestInset {
bool leftline_; bool leftline_;
/// do we need a line to the right? /// do we need a line to the right?
bool rightline_; bool rightline_;
/// how many lines to the left of this column?
int lines_;
/// additional amount to be skipped when drawing /// additional amount to be skipped when drawing
int skip_; int skip_;
}; };
public: public:
/// constructor from columns description, creates one row
MathGridInset(char valign, string const & halign);
/// Note: columns first! /// Note: columns first!
MathGridInset(col_type m, row_type n); MathGridInset(col_type m, row_type n);
/// ///
@ -74,30 +78,32 @@ public:
/// ///
char halign(col_type col) const; char halign(col_type col) const;
/// ///
string halign() const;
///
void valign(char c); void valign(char c);
/// ///
char valign() const; char valign() const;
/// ///
void vskip(LyXLength const &, row_type row); void vcrskip(LyXLength const &, row_type row);
/// ///
LyXLength vskip(row_type row) const; LyXLength vcrskip(row_type row) const;
/// ///
void resize(short int type, col_type cols); void resize(short int type, col_type cols);
/// ///
const RowInfo & rowinfo(row_type row) const; const RowInfo & rowinfo(row_type row) const;
/// /// returns topmost row if passed (-1)
RowInfo & rowinfo(row_type row); RowInfo & rowinfo(row_type row);
/// identifies GridInset /// identifies GridInset
virtual MathGridInset * asGridInset() { return this; } virtual MathGridInset * asGridInset() { return this; }
/// ///
col_type ncols() const { return colinfo_.size(); } col_type ncols() const;
/// ///
row_type nrows() const { return rowinfo_.size(); } row_type nrows() const;
/// ///
col_type col(idx_type idx) const { return idx % ncols(); } col_type col(idx_type idx) const;
/// ///
row_type row(idx_type idx) const { return idx / ncols(); } row_type row(idx_type idx) const;
/// ///
int cellXOffset(idx_type idx) const; int cellXOffset(idx_type idx) const;
/// ///
@ -139,7 +145,7 @@ public:
/// ///
std::vector<idx_type> idxBetween(idx_type from, idx_type to) const; std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
/// ///
virtual int defaultColSpace(col_type) { return 10; } virtual int defaultColSpace(col_type) { return 0; }
/// ///
virtual char defaultColAlign(col_type) { return 'c'; } virtual char defaultColAlign(col_type) { return 'c'; }
/// ///
@ -161,6 +167,8 @@ protected:
string eolString(row_type row) const; string eolString(row_type row) const;
/// returns proper 'end of column' code for LaTeX /// returns proper 'end of column' code for LaTeX
string eocString(col_type col) const; string eocString(col_type col) const;
/// extract number of columns from alignment string
col_type guessColumns(string const & halign) const;
/// row info /// row info
std::vector<RowInfo> rowinfo_; std::vector<RowInfo> rowinfo_;

View File

@ -136,7 +136,7 @@ int MathHullInset::defaultColSpace(col_type col)
return (col & 1) ? 40 : 0; return (col & 1) ? 40 : 0;
default:; default:;
} }
return 10; return 0;
} }

View File

@ -275,6 +275,10 @@ private:
Token const & nextToken() const; Token const & nextToken() const;
/// ///
Token const & getToken(); Token const & getToken();
/// skips spaces if any
void skipSpaces();
/// counts a sequence of hlines
int readHLines();
/// ///
void lex(string const & s); void lex(string const & s);
/// ///
@ -339,10 +343,31 @@ Token const & Parser::nextToken() const
Token const & Parser::getToken() Token const & Parser::getToken()
{ {
static const Token dummy; static const Token dummy;
//lyxerr << "looking at token " << tokens_[pos_] << '\n';
return good() ? tokens_[pos_++] : dummy; return good() ? tokens_[pos_++] : dummy;
} }
void Parser::skipSpaces()
{
while (nextToken().cat() == catSpace)
getToken();
}
int Parser::readHLines()
{
int num = 0;
skipSpaces();
while (nextToken().cs() == "hline") {
getToken();
++num;
skipSpaces();
}
return num;
}
void Parser::putback() void Parser::putback()
{ {
--pos_; --pos_;
@ -481,6 +506,9 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
bool const saved_num = curr_num_; bool const saved_num = curr_num_;
string const saved_label = curr_label_; string const saved_label = curr_label_;
// read initial hlines
p->rowinfo(0).lines_ = readHLines();
for (int row = 0; true; ++row) { for (int row = 0; true; ++row) {
// reset global variables // reset global variables
curr_num_ = numbered; curr_num_ = numbered;
@ -491,12 +519,15 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
//lyxerr << "reading cell " << row << " " << col << "\n"; //lyxerr << "reading cell " << row << " " << col << "\n";
parse_into(p->cell(col + row * cols), FLAG_BLOCK); parse_into(p->cell(col + row * cols), FLAG_BLOCK);
// no ampersand // break if cell is not followed by an ampersand
if (prevToken().cat() != catAlign) { if (nextToken().cat() != catAlign) {
//lyxerr << "less cells read than normal in row/col: " //lyxerr << "less cells read than normal in row/col: "
// << row << " " << col << "\n"; // << row << " " << col << "\n";
break; break;
} }
// skip the ampersand
getToken();
} }
if (outmost) { if (outmost) {
@ -508,17 +539,34 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
m->numbered(row, curr_num_); m->numbered(row, curr_num_);
m->label(row, curr_label_); m->label(row, curr_label_);
if (curr_skip_.size()) { if (curr_skip_.size()) {
m->vskip(LyXLength(curr_skip_), row); m->vcrskip(LyXLength(curr_skip_), row);
curr_skip_.erase(); curr_skip_.erase();
} }
} }
// no newline? // is a \\ coming?
if (!prevToken().isCR()) { if (nextToken().isCR()) {
//lyxerr << "no newline here\n"; // skip the cr-token
getToken();
// try to read a length
//get
// read hlines for next row
p->rowinfo(row + 1).lines_ = readHLines();
}
// we are finished if the next token is an 'end'
if (nextToken().cs() == "end") {
// skip the end-token
getToken();
getArg('{','}');
// leave the 'read a line'-loop
break; break;
} }
// otherwise, we have to start a new row
p->appendRow(); p->appendRow();
} }
@ -533,9 +581,7 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
string Parser::parse_macro() string Parser::parse_macro()
{ {
string name = "{error}"; string name = "{error}";
skipSpaces();
while (nextToken().cat() == catSpace)
getToken();
if (getToken().cs() != "newcommand") { if (getToken().cs() != "newcommand") {
lyxerr << "\\newcommand expected\n"; lyxerr << "\\newcommand expected\n";
@ -571,9 +617,7 @@ string Parser::parse_macro()
bool Parser::parse_normal(MathAtom & matrix) bool Parser::parse_normal(MathAtom & matrix)
{ {
while (nextToken().cat() == catSpace) skipSpaces();
getToken();
Token const & t = getToken(); Token const & t = getToken();
if (t.cs() == "(") { if (t.cs() == "(") {
@ -706,10 +750,8 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
} }
if (flags & FLAG_BLOCK) { if (flags & FLAG_BLOCK) {
if (t.cat() == catAlign || t.isCR()) if (t.cat() == catAlign || t.isCR() || t.cs() == "end") {
return; putback();
if (t.cs() == "end") {
getArg('{', '}');
return; return;
} }
} }
@ -865,8 +907,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
if (name == "array") { if (name == "array") {
string const valign = getArg('[', ']') + 'c'; string const valign = getArg('[', ']') + 'c';
string const halign = getArg('{', '}'); string const halign = getArg('{', '}');
array.push_back( array.push_back(MathAtom(new MathArrayInset(valign[0], halign)));
MathAtom(new MathArrayInset(halign.size(), 1, valign[0], halign)));
parse_lines(array.back(), false, false); parse_lines(array.back(), false, false);
} else if (name == "split") { } else if (name == "split") {
array.push_back(MathAtom(new MathSplitInset(1))); array.push_back(MathAtom(new MathSplitInset(1)));