From 761fab540ecf0dd1328080c5c7b3582bc0fe56e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 15 Oct 2001 14:19:16 +0000 Subject: [PATCH] support reading TeX's $$...$$ syntax git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2887 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_cursor.C | 8 ++++++-- src/mathed/math_gridinset.C | 18 ++++++++++++------ src/mathed/math_macro.C | 2 -- src/mathed/math_parser.C | 22 ++++++++++++++++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 99c7ec2d0a..5c4840ba13 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -308,7 +308,7 @@ bool MathCursor::left(bool sel) pushRight(prevAtom()); return true; } - + return posLeft() || idxLeft() || popLeft() || selection_; } @@ -1068,13 +1068,17 @@ void MathCursor::breakLine() for (col_type c = col() + 1; c < p->ncols(); ++c) { const MathMatrixInset::idx_type i1 = p->index(r, c); const MathMatrixInset::idx_type i2 = p->index(r + 1, c); - lyxerr << "swapping cells " << i1 << " and " << i2 << "\n"; + //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n"; p->cell(i1).swap(p->cell(i2)); } // split cell splitCell(); p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1)); + + // correct cursor position + --idx(); + pos() = size(); } } diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 074b76fbfe..9957c17b82 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -464,20 +464,26 @@ void MathGridInset::idxDelete(idx_type & idx, bool & popit, bool & deleteit) popit = false; deleteit = false; - // delete entire row if in first cell of empty row - if (col(idx) == 0 && nrows() > 1) { + // delete entire sequence of ncols() empty cells if possible + if (idx <= index(nrows() - 1, 0)) { bool deleterow = true; for (idx_type i = idx; i < idx + ncols(); ++i) if (cell(i).size()) { deleterow = false; break; } - if (deleterow) + + if (deleterow) { + // move cells if necessary + for (idx_type i = index(row(idx), 0); i < idx; ++i) + cell(i).swap(cell(i + ncols())); + delRow(row(idx)); - if (idx >= nargs()) - idx = nargs() - 1; - return; + if (idx >= nargs()) + idx = nargs() - 1; + return; + } } // undo effect of Ctrl-Tab (i.e. pull next cell) diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 5db4fe185a..afd872b9a7 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -30,7 +30,6 @@ #include "Painter.h" #include "LaTeXFeatures.h" -using std::endl; MathMacro::MathMacro(string const & name) : MathNestInset(MathMacroTable::provide(name)->asMacroTemplate()->numargs()), @@ -160,7 +159,6 @@ void MathMacro::dump() const lyxerr << "\n macro: '" << this << "'\n"; lyxerr << " name: '" << name() << "'\n"; lyxerr << " template: '"; tmplate_->write(lyxerr, false); lyxerr << "'\n"; - lyxerr << endl; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 074ee0509b..ba96a36feb 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -535,12 +535,30 @@ bool Parser::parse_normal(MathAtom & matrix) Token const & t = getToken(); - if (t.cat() == catMath || t.cs() == "(") { + if (t.cs() == "(") { matrix = MathAtom(new MathMatrixInset(LM_OT_SIMPLE)); parse_into(matrix->cell(0), 0); return true; } + if (t.cat() == catMath) { + Token const & n = getToken(); + if (n.cat() == catMath) { + // TeX's $$...$$ syntax for displayed math + matrix = MathAtom(new MathMatrixInset(LM_OT_EQUATION)); + MathMatrixInset * p = matrix->asMatrixInset(); + parse_into(p->cell(0), 0); + p->numbered(0, curr_num_); + p->label(0, curr_label_); + } else { + // simple $...$ stuff + putback(); + matrix = MathAtom(new MathMatrixInset(LM_OT_SIMPLE)); + parse_into(matrix->cell(0), 0); + } + return true; + } + if (!t.cs().size()) { lyxerr << "start of math expected, got '" << t << "'\n"; return false; @@ -556,7 +574,7 @@ bool Parser::parse_normal(MathAtom & matrix) parse_into(p->cell(0), 0); p->numbered(0, curr_num_); p->label(0, curr_label_); - return p; + return true; } if (cs != "begin") {