3 * Purpose: Interaction for mathed
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Math interaction for a WYSIWYG math editor.
8 * Dependencies: Xlib, XForms
10 * Copyright: 1996, Alejandro Aguilar Sierra
12 * Version: 0.8beta, Math & Lyx project.
14 * You are free to use and modify this code under the terms of
15 * the GNU General Public Licence version 2 or later.
19 #pragma implementation
26 #include "support/lstrings.h"
27 #include "support/LAssert.h"
31 #include "formulabase.h"
32 #include "math_arrayinset.h"
33 #include "math_braceinset.h"
34 #include "math_casesinset.h"
35 #include "math_charinset.h"
36 #include "math_cursor.h"
37 #include "math_deliminset.h"
38 #include "math_factory.h"
39 #include "math_hullinset.h"
40 #include "math_iterator.h"
41 #include "math_mathmlstream.h"
42 #include "math_parser.h"
43 #include "math_replace.h"
44 #include "math_scriptinset.h"
45 #include "math_spaceinset.h"
46 #include "math_specialcharinset.h"
47 #include "math_support.h"
61 void grab(MathCursor const & cursor)
66 cursor.getSelection(i1, i2);
67 if (i1.idx_ == i2.idx_)
68 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
70 std::vector<MathInset::idx_type> indices =
71 i1.par_->idxBetween(i1.idx_, i2.idx_);
72 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
73 data_.push_back(i1.cell(indices[i]));
77 void erase(MathCursor & cursor)
81 cursor.getSelection(i1, i2);
82 if (i1.idx_ == i2.idx_)
83 i1.cell().erase(i1.pos_, i2.pos_);
85 std::vector<MathInset::idx_type> indices =
86 i1.par_->idxBetween(i1.idx_, i2.idx_);
87 for (unsigned i = 0; i < indices.size(); ++i)
88 i1.cell(indices[i]).erase();
93 void paste(MathCursor & cursor) const
95 MathArray ar = glue();
99 // glues selection to one cell
100 MathArray glue() const
103 for (unsigned i = 0; i < data_.size(); ++i)
104 ar.push_back(data_[i]);
113 std::vector<MathArray> data_;
117 Selection theSelection;
124 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
125 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
127 left ? first() : last();
131 void MathCursor::push(MathAtom & t)
133 Cursor_.push_back(MathCursorPos(t.nucleus()));
137 void MathCursor::pushLeft(MathAtom & t)
139 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
141 t->idxFirst(idx(), pos());
145 void MathCursor::pushRight(MathAtom & t)
147 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
150 t->idxLast(idx(), pos());
154 bool MathCursor::popLeft()
156 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
157 if (Cursor_.size() <= 1)
159 if (par()->asScriptInset())
160 par()->asScriptInset()->removeEmptyScripts();
166 bool MathCursor::popRight()
168 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
169 if (Cursor_.size() <= 1)
171 if (par()->asScriptInset())
172 par()->asScriptInset()->removeEmptyScripts();
181 void MathCursor::dump(char const * what) const
183 lyxerr << "MC: " << what << "\n";
184 lyxerr << " Cursor: " << Cursor_.size() << "\n";
185 for (unsigned i = 0; i < Cursor_.size(); ++i)
186 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
187 lyxerr << " Anchor: " << Anchor_.size() << "\n";
188 for (unsigned i = 0; i < Anchor_.size(); ++i)
189 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
190 lyxerr << " sel: " << selection_ << "\n";
193 void MathCursor::dump(char const *) const {}
197 UpdatableInset * MathCursor::asHyperActiveInset() const
199 return par()->asHyperActiveInset();
203 bool MathCursor::isInside(MathInset const * p) const
205 for (unsigned i = 0; i < Cursor_.size(); ++i)
206 if (Cursor_[i].par_ == p)
212 bool MathCursor::openable(MathAtom const & t, bool sel) const
214 if (t->isHyperActive())
220 if (t->asScriptInset())
224 // we can't move into anything new during selection
225 if (Cursor_.size() == Anchor_.size())
227 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
234 bool MathCursor::posLeft()
243 bool MathCursor::posRight()
252 bool MathCursor::left(bool sel)
257 lastcode_ = LM_TC_VAR;
261 lastcode_ = LM_TC_VAR;
263 if (hasPrevAtom() && openable(prevAtom(), sel)) {
264 if (prevAtom()->isHyperActive()) {
265 lyxerr << "entering hyperactive inset\n";
267 pushRight(prevAtom());
271 return posLeft() || idxLeft() || popLeft() || selection_;
275 bool MathCursor::right(bool sel)
280 lastcode_ = LM_TC_VAR;
284 lastcode_ = LM_TC_VAR;
286 if (hasNextAtom() && openable(nextAtom(), sel)) {
287 if (nextAtom()->isHyperActive()) {
288 lyxerr << "entering hyperactive inset\n";
291 nextAtom()->edit(formula()->view(), x, y, 0);
293 pushLeft(nextAtom());
297 return posRight() || idxRight() || popRight() || selection_;
301 void MathCursor::first()
304 pushLeft(formula_->par());
308 void MathCursor::last()
315 bool positionable(MathCursor::cursor_type const & cursor,
316 MathCursor::cursor_type const & anchor)
318 // avoid deeper nested insets when selecting
319 if (cursor.size() > anchor.size())
322 // anchor might be deeper, should have same path then
323 for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
324 if (cursor[i].par_ != anchor[i].par_)
327 // position should be ok.
332 void MathCursor::setPos(int x, int y)
335 cursor_type best_cursor;
336 double best_dist = 1e10;
338 MathIterator it = ibegin(formula()->par().nucleus());
339 MathIterator et = iend(formula()->par().nucleus());
340 for ( ; it != et; ++it) {
341 //lyxerr << "*it: " << *it << " *et: " << *et << "\n";
342 // avoid invalid nesting hen selecting
343 if (selection_ && !positionable(it.cursor(), Anchor_))
345 //lyxerr << it.position() << endl;
346 int xo = it.position().xpos();
347 int yo = it.position().ypos();
348 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
351 best_cursor = it.cursor();
354 if (best_dist < 1e10)
355 Cursor_ = best_cursor;
356 //lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n";
357 lyx::Assert(Cursor_.size());
363 void MathCursor::home(bool sel)
368 lastcode_ = LM_TC_VAR;
369 if (!par()->idxHome(idx(), pos()))
375 void MathCursor::end(bool sel)
380 lastcode_ = LM_TC_VAR;
381 if (!par()->idxEnd(idx(), pos()))
387 void MathCursor::plainErase()
389 array().erase(pos());
393 void MathCursor::plainInsert(MathAtom const & t)
395 array().insert(pos(), t);
400 void MathCursor::insert(char c, MathTextCodes t)
402 //lyxerr << "inserting '" << c << "'\n";
403 plainInsert(MathAtom(new MathCharInset(c, t)));
407 void MathCursor::insert(MathAtom const & t)
422 void MathCursor::niceInsert(MathAtom const & t)
425 insert(t); // inserting invalidates the pointer!
426 MathAtom const & p = prevAtom();
429 right(); // do not push for e.g. MathSymbolInset
435 void MathCursor::insert(MathArray const & ar)
441 array().insert(pos(), ar);
446 void MathCursor::paste(MathArray const & ar)
450 array().insert(pos(), ar);
455 void MathCursor::backspace()
467 MathScriptInset * p = prevAtom()->asScriptInset();
469 p->removeScript(p->hasUp());
470 // Don't delete if there is anything left
471 if (p->hasUp() || p->hasDown())
480 void MathCursor::erase()
490 // delete empty cells if necessary
491 if (array().empty()) {
494 par()->idxDelete(idx(), popit, removeit);
495 if (popit && popLeft() && removeit)
503 MathScriptInset * p = nextAtom()->asScriptInset();
505 p->removeScript(p->hasUp());
506 // Don't delete if there is anything left
507 if (p->hasUp() || p->hasDown())
515 void MathCursor::delLine()
524 if (par()->nrows() > 1) {
525 // grid are the only things with more than one row...
526 lyx::Assert(par()->asGridInset());
527 par()->asGridInset()->delRow(hullRow());
530 if (idx() > par()->nargs())
531 idx() = par()->nargs();
538 bool MathCursor::up(bool sel)
545 MathInset::idx_type i = 0;
546 MathInset::pos_type p = 0;
548 // check whether we could move into the inset
549 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
550 pushRight(prevAtom());
556 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
557 pushLeft(nextAtom());
564 cursor_type save = Cursor_;
572 bool MathCursor::down(bool sel)
579 MathInset::idx_type i = 0;
580 MathInset::pos_type p = 0;
582 // check whether we could move into the inset
583 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
584 pushRight(prevAtom());
590 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
591 pushLeft(nextAtom());
598 cursor_type save = Cursor_;
606 bool MathCursor::toggleLimits()
610 MathScriptInset * t = nextAtom()->asScriptInset();
613 int old = t->limits();
614 t->limits(old < 0 ? 1 : -1);
615 return old != t->limits();
619 void MathCursor::macroModeClose()
621 string s = macroName();
623 size_type old = pos();
625 array().erase(pos(), old);
631 int MathCursor::macroNamePos() const
633 for (int i = pos() - 1; i >= 0; --i) {
634 MathAtom & p = array().at(i);
635 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
642 string MathCursor::macroName() const
645 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
646 s += array().at(i)->getChar();
651 void MathCursor::selCopy()
655 theSelection.grab(*this);
661 void MathCursor::selCut()
665 theSelection.grab(*this);
666 theSelection.erase(*this);
669 theSelection.clear();
674 void MathCursor::selDel()
678 theSelection.erase(*this);
686 void MathCursor::selPaste()
689 theSelection.paste(*this);
690 //theSelection.grab(*this);
695 void MathCursor::selHandle(bool sel)
697 if (sel == selection_)
699 //theSelection.clear();
705 void MathCursor::selStart()
708 //theSelection.clear();
715 void MathCursor::selClear()
723 void MathCursor::selGet(MathArray & ar)
729 theSelection.grab(*this);
730 ar = theSelection.glue();
735 void MathCursor::drawSelection(Painter & pain) const
742 getSelection(i1, i2);
744 if (i1.idx_ == i2.idx_) {
745 MathXArray & c = i1.xcell();
746 int x1 = c.xo() + c.pos2x(i1.pos_);
747 int y1 = c.yo() - c.ascent();
748 int x2 = c.xo() + c.pos2x(i2.pos_);
749 int y2 = c.yo() + c.descent();
750 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
752 std::vector<MathInset::idx_type> indices
753 = i1.par_->idxBetween(i1.idx_, i2.idx_);
754 for (unsigned i = 0; i < indices.size(); ++i) {
755 MathXArray & c = i1.xcell(indices[i]);
757 int y1 = c.yo() - c.ascent();
758 int x2 = c.xo() + c.width();
759 int y2 = c.yo() + c.descent();
760 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
765 // draw anchor if different from selection boundary
766 MathCursorPos anc = Anchor_.back();
767 if (anc != i1 && anc != i2) {
768 MathXArray & c = anc.xcell();
769 int x = c.xo() + c.pos2x(anc.pos_);
770 int y1 = c.yo() - c.ascent();
771 int y2 = c.yo() + c.descent();
772 pain.line(x, y1, x, y2, LColor::math);
778 void MathCursor::handleFont(MathTextCodes t)
784 getSelection(i1, i2);
785 if (i1.idx_ == i2.idx_) {
786 MathArray & ar = i1.cell();
787 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
788 ar.at(pos)->handleFont(t);
791 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
795 void MathCursor::handleDelim(string const & l, string const & r)
797 handleNest(new MathDelimInset(l, r));
801 void MathCursor::handleNest(MathInset * p)
805 p->cell(0) = theSelection.glue();
807 insert(MathAtom(p)); // this invalidates p!
808 pushRight(prevAtom());
812 void MathCursor::getPos(int & x, int & y)
815 #warning This should probably take cellXOffset and cellYOffset into account
817 x = xarray().xo() + xarray().pos2x(pos());
822 MathInset * MathCursor::par() const
824 return cursor().par_;
828 InsetFormulaBase * MathCursor::formula()
834 MathCursor::idx_type MathCursor::idx() const
836 return cursor().idx_;
840 MathCursor::idx_type & MathCursor::idx()
842 return cursor().idx_;
846 MathCursor::pos_type MathCursor::pos() const
848 return cursor().pos_;
852 MathCursor::pos_type & MathCursor::pos()
854 return cursor().pos_;
858 bool MathCursor::inMacroMode() const
860 return macroNamePos() != -1;
864 bool MathCursor::selection() const
870 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
872 for (int i = Cursor_.size() - 1; i >= 0; --i) {
873 MathGridInset * p = Cursor_[i].par_->asGridInset();
875 idx = Cursor_[i].idx_;
883 void MathCursor::pullArg(bool goright)
886 MathArray a = array();
888 MathScriptInset const * p = par()->asScriptInset();
890 // special handling for scripts
891 const bool up = p->hasUp();
893 MathScriptInset * q = nextAtom()->asScriptInset();
897 array().insert(pos(), a);
903 array().insert(pos(), a);
910 void MathCursor::normalize() const
913 #warning This is evil!
915 MathCursor * it = const_cast<MathCursor *>(this);
917 if (idx() >= par()->nargs()) {
918 lyxerr << "this should not really happen - 1: "
919 << idx() << " " << par()->nargs() << "\n";
922 it->idx() = min(idx(), par()->nargs() - 1);
924 if (pos() > size()) {
925 lyxerr << "this should not really happen - 2: "
926 << pos() << " " << size() << " in idx: " << it->idx()
928 WriteStream wi(lyxerr, false);
929 it->par()->write(wi);
933 it->pos() = min(pos(), size());
937 MathCursor::size_type MathCursor::size() const
939 return array().size();
943 MathCursor::col_type MathCursor::hullCol() const
945 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
949 MathCursor::row_type MathCursor::hullRow() const
951 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
955 bool MathCursor::hasPrevAtom() const
961 bool MathCursor::hasNextAtom() const
963 return pos() < size();
967 MathAtom const & MathCursor::prevAtom() const
969 lyx::Assert(pos() > 0);
970 return array().at(pos() - 1);
974 MathAtom & MathCursor::prevAtom()
976 lyx::Assert(pos() > 0);
977 return array().at(pos() - 1);
981 MathAtom const & MathCursor::nextAtom() const
983 lyx::Assert(pos() < size());
984 return array().at(pos());
988 MathAtom & MathCursor::nextAtom()
990 lyx::Assert(pos() < size());
991 return array().at(pos());
995 MathArray & MathCursor::array() const
997 static MathArray dummy;
999 if (idx() >= par()->nargs()) {
1000 lyxerr << "############ idx_ " << idx() << " not valid\n";
1004 if (Cursor_.size() == 0) {
1005 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1009 return cursor().cell();
1013 MathXArray & MathCursor::xarray() const
1015 static MathXArray dummy;
1017 if (Cursor_.size() == 0) {
1018 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1022 return cursor().xcell();
1026 void MathCursor::idxNext()
1028 par()->idxNext(idx(), pos());
1032 void MathCursor::idxPrev()
1034 par()->idxPrev(idx(), pos());
1038 void MathCursor::splitCell()
1040 if (idx() + 1 == par()->nargs())
1042 MathArray ar = array();
1044 array().erase(pos(), size());
1047 array().insert(0, ar);
1051 void MathCursor::breakLine()
1053 // leave inner cells
1057 MathHullInset * p = formula()->par()->asHullInset();
1061 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1062 p->mutate(LM_OT_EQNARRAY);
1066 p->addRow(hullRow());
1069 const row_type r = hullRow();
1070 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1071 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1075 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1080 //void MathCursor::readLine(MathArray & ar) const
1082 // idx_type base = row() * par()->ncols();
1083 // for (idx_type off = 0; off < par()->ncols(); ++off)
1084 // ar.push_back(par()->cell(base + off));
1088 char MathCursor::valign() const
1091 MathGridInset * p = enclosingGrid(idx);
1092 return p ? p->valign() : '\0';
1096 char MathCursor::halign() const
1099 MathGridInset * p = enclosingGrid(idx);
1100 return p ? p->halign(idx % p->ncols()) : '\0';
1104 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1106 MathCursorPos anc = normalAnchor();
1107 if (anc < cursor()) {
1117 MathCursorPos & MathCursor::cursor()
1119 lyx::Assert(Cursor_.size());
1120 return Cursor_.back();
1124 MathCursorPos const & MathCursor::cursor() const
1126 lyx::Assert(Cursor_.size());
1127 return Cursor_.back();
1131 bool MathCursor::goUpDown(bool up)
1136 // try to find an inset that knows better then we
1138 // we found a cell that think something "below" us.
1140 if (par()->idxUp(idx()))
1143 if (par()->idxDown(idx()))
1148 // have reached hull
1153 up ? formula()->ylow() : yo + 4,
1154 up ? yo - 4 : formula()->yhigh()
1158 int xlow, xhigh, ylow, yhigh;
1159 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1160 bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
1165 bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1167 //lyxerr << "looking at range: "
1168 // << "[" << xlow << "..." << xhigh << "]"
1169 // << " x [" << ylow << "..." << yhigh << "]"
1170 // << " xo: " << x << " yo: " << y << "\n";
1172 cursor_type best_cursor;
1173 double best_dist = 1e10;
1175 MathIterator it = ibegin(formula()->par().nucleus());
1176 MathIterator et = iend(formula()->par().nucleus());
1177 for ( ; it != et; ++it) {
1178 int xo = it.position().xpos();
1179 int yo = it.position().ypos();
1180 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1181 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1182 if (d < best_dist) {
1184 best_cursor = it.cursor();
1188 if (best_dist < 1e10)
1189 Cursor_ = best_cursor;
1190 return best_dist < 1e10;
1194 bool MathCursor::idxLeft()
1196 return par()->idxLeft(idx(), pos());
1200 bool MathCursor::idxRight()
1202 return par()->idxRight(idx(), pos());
1206 bool MathCursor::interpret(string const & s)
1208 //lyxerr << "interpret 1: '" << s << "'\n";
1213 return interpret(s[0]);
1215 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1216 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1217 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1219 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1221 istringstream is(s.substr(5).c_str());
1223 n = std::max(1u, n);
1224 niceInsert(MathAtom(new MathCasesInset(n)));
1228 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1233 istringstream is(s.substr(6).c_str());
1234 is >> m >> n >> v_align >> h_align;
1235 m = std::max(1u, m);
1236 n = std::max(1u, n);
1238 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1242 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1244 istringstream is(s.substr(7).c_str());
1247 mathed_parse_cell(rep.from, from);
1248 mathed_parse_cell(rep.to, to);
1249 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1250 par()->replace(rep);
1254 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1255 MathArray ar = array();
1256 MathAtom t = createMathInset(s.substr(1));
1257 t->asNestInset()->cell(0).swap(array());
1265 latexkeys const * l = in_word_set(s.substr(1));
1266 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1267 lastcode_ = static_cast<MathTextCodes>(l->id);
1271 niceInsert(createMathInset(s.substr(1)));
1276 bool MathCursor::interpret(char c)
1278 //lyxerr << "interpret 2: '" << c << "'\n";
1279 if (c == '^' || c == '_') {
1281 const bool up = (c == '^');
1283 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1284 prevAtom()->asScriptInset()->ensure(up);
1285 pushRight(prevAtom());
1288 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1289 nextAtom()->asScriptInset()->ensure(up);
1290 pushLeft(nextAtom());
1294 plainInsert(MathAtom(new MathScriptInset(up)));
1295 prevAtom()->asScriptInset()->ensure(up);
1296 pushRight(prevAtom());
1307 if (inMacroMode()) {
1308 string name = macroName();
1310 if (name == "\\" && c == '#') {
1311 insert(c, LM_TC_TEX);
1315 if (name == "\\" && c == '\\') {
1317 interpret("\\backslash");
1321 if (name == "\\#" && '1' <= c && c <= '9') {
1322 insert(c, LM_TC_TEX);
1328 insert(c, LM_TC_TEX);
1333 insert(c, LM_TC_TEX);
1345 if (lastcode_ == LM_TC_TEXTRM) {
1346 // suppress direct insertion of to spaces in a row
1347 // the still allows typing '<space>a<space>' and deleting the 'a', but
1348 // it is better than nothing
1349 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1351 insert(c, LM_TC_TEXTRM);
1356 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1357 prevAtom()->asSpaceInset()->incSpace();
1361 if (mathcursor->popRight())
1364 // if are at the very end, leave the formula
1365 return pos() != size();
1369 if (strchr("{}", c)) {
1370 insert(c, LM_TC_TEX);
1376 niceInsert(MathAtom(new MathBraceInset));
1384 if (strchr("#$%", c)) {
1385 insert(MathAtom(new MathSpecialCharInset(c)));
1386 lastcode_ = LM_TC_VAR;
1390 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1391 insert(c, LM_TC_VAR);
1395 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1396 insert(c, LM_TC_VAR);
1397 lastcode_ = LM_TC_VAR;
1402 insert(c, LM_TC_TEX);
1403 //bv->owner()->message(_("TeX mode"));
1407 // no special circumstances, so insert the character without any fuss
1408 insert(c, lastcode_);
1409 lastcode_ = LM_TC_MIN;
1415 MathCursorPos MathCursor::normalAnchor() const
1417 lyx::Assert(Anchor_.size() >= Cursor_.size());
1418 // use Anchor on the same level as Cursor
1419 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1420 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1421 // anchor is behind cursor -> move anchor behind the inset
1428 void MathCursor::stripFromLastEqualSign()
1430 // find position of last '=' in the array
1431 MathArray & ar = cursor().cell();
1432 MathArray::const_iterator et = ar.end();
1433 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1434 if ((*it)->getChar() == '=')
1437 // delete everything behind this position
1438 ar.erase(et - ar.begin(), ar.size());