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_->nucleus()->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_->nucleus()->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)
137 Cursor_.push_back(p);
141 void MathCursor::pushLeft(MathAtom & t)
143 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
145 t->idxFirst(idx(), pos());
149 void MathCursor::pushRight(MathAtom & t)
151 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
154 t->idxLast(idx(), pos());
158 bool MathCursor::popLeft()
160 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
161 if (Cursor_.size() <= 1)
164 // nextInset()->removeEmptyScripts();
167 // nextAtom()->removeEmptyScripts();
172 bool MathCursor::popRight()
174 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
175 if (Cursor_.size() <= 1)
178 // nextInset()->removeEmptyScripts();
181 // nextInset()->removeEmptyScripts();
189 void MathCursor::dump(char const * what) const
191 lyxerr << "MC: " << what << "\n";
192 lyxerr << " Cursor: " << Cursor_.size() << "\n";
193 for (unsigned i = 0; i < Cursor_.size(); ++i)
194 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
195 lyxerr << " Anchor: " << Anchor_.size() << "\n";
196 for (unsigned i = 0; i < Anchor_.size(); ++i)
197 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
198 lyxerr << " sel: " << selection_ << "\n";
201 void MathCursor::dump(char const *) const {}
205 UpdatableInset * MathCursor::asHyperActiveInset() const
207 return par()->asHyperActiveInset();
211 bool MathCursor::isInside(MathInset const * p) const
213 for (unsigned i = 0; i < Cursor_.size(); ++i)
214 if (Cursor_[i].par_->nucleus() == p)
220 bool MathCursor::openable(MathAtom const & t, bool sel) const
222 if (t->isHyperActive())
228 if (t->asScriptInset())
232 // we can't move into anything new during selection
233 if (Cursor_.size() == Anchor_.size())
235 if (&t != Anchor_[Cursor_.size()].par_)
242 bool MathCursor::posLeft()
251 bool MathCursor::posRight()
260 bool MathCursor::left(bool sel)
265 lastcode_ = LM_TC_VAR;
269 lastcode_ = LM_TC_VAR;
271 if (hasPrevAtom() && openable(prevAtom(), sel)) {
272 if (prevAtom()->isHyperActive()) {
273 lyxerr << "entering hyperactive inset\n";
275 pushRight(prevAtom());
279 return posLeft() || idxLeft() || popLeft() || selection_;
283 bool MathCursor::right(bool sel)
288 lastcode_ = LM_TC_VAR;
292 lastcode_ = LM_TC_VAR;
294 if (hasNextAtom() && openable(nextAtom(), sel)) {
295 if (nextAtom()->isHyperActive()) {
296 lyxerr << "entering hyperactive inset\n";
299 nextAtom()->edit(formula()->view(), x, y, 0);
301 pushLeft(nextAtom());
305 return posRight() || idxRight() || popRight() || selection_;
309 void MathCursor::first()
312 pushLeft(formula_->par());
316 void MathCursor::last()
324 void MathCursor::setPos(int x, int y)
327 cursor_type best_cursor;
328 double best_dist = 1e10;
330 MathIterator it = ibegin(formula()->par());
331 MathIterator et = iend(formula()->par());
332 for ( ; it != et; ++it) {
333 //lyxerr << "*it: " << *it << " *et: " << *et << "\n";
335 // avoid deeper nested insets when selecting
336 if (it.cursor().size() > Anchor_.size())
338 // anchor might be deeper!
339 if (it.cursor().size() == Anchor_.size())
340 if (it.par().nucleus() != Anchor_.back().par_->nucleus())
342 //if (it.par() != Anchor_[it.cursor().size()].par_)
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 par()->delRow(row());
527 if (idx() > par()->nargs())
528 idx() = par()->nargs();
535 bool MathCursor::up(bool sel)
542 MathInset::idx_type i = 0;
543 MathInset::pos_type p = 0;
545 // check whether we could move into the inset
546 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
547 pushRight(prevAtom());
553 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
554 pushLeft(nextAtom());
561 return goUp() || selection_;
565 bool MathCursor::down(bool sel)
572 MathInset::idx_type i = 0;
573 MathInset::pos_type p = 0;
575 // check whether we could move into the inset
576 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
577 pushRight(prevAtom());
583 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
584 pushLeft(nextAtom());
591 return goDown() || selection_;
595 bool MathCursor::toggleLimits()
599 MathScriptInset * t = nextAtom()->asScriptInset();
602 int old = t->limits();
603 t->limits(old < 0 ? 1 : -1);
604 return old != t->limits();
608 void MathCursor::macroModeClose()
610 string s = macroName();
612 size_type old = pos();
614 array().erase(pos(), old);
620 int MathCursor::macroNamePos() const
622 for (int i = pos() - 1; i >= 0; --i) {
623 MathAtom & p = array().at(i);
624 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
631 string MathCursor::macroName() const
634 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
635 s += array().at(i)->getChar();
640 void MathCursor::selCopy()
644 theSelection.grab(*this);
650 void MathCursor::selCut()
654 theSelection.grab(*this);
655 theSelection.erase(*this);
658 theSelection.clear();
663 void MathCursor::selDel()
667 theSelection.erase(*this);
675 void MathCursor::selPaste()
678 theSelection.paste(*this);
679 //theSelection.grab(*this);
684 void MathCursor::selHandle(bool sel)
686 if (sel == selection_)
688 //theSelection.clear();
694 void MathCursor::selStart()
697 //theSelection.clear();
704 void MathCursor::selClear()
712 void MathCursor::selGet(MathArray & ar)
718 theSelection.grab(*this);
719 ar = theSelection.glue();
724 void MathCursor::drawSelection(Painter & pain) const
731 getSelection(i1, i2);
733 if (i1.idx_ == i2.idx_) {
734 MathXArray & c = i1.xcell();
735 int x1 = c.xo() + c.pos2x(i1.pos_);
736 int y1 = c.yo() - c.ascent();
737 int x2 = c.xo() + c.pos2x(i2.pos_);
738 int y2 = c.yo() + c.descent();
739 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
741 std::vector<MathInset::idx_type> indices
742 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
743 for (unsigned i = 0; i < indices.size(); ++i) {
744 MathXArray & c = i1.xcell(indices[i]);
746 int y1 = c.yo() - c.ascent();
747 int x2 = c.xo() + c.width();
748 int y2 = c.yo() + c.descent();
749 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
754 // draw anchor if different from selection boundary
755 MathCursorPos anc = Anchor_.back();
756 if (anc != i1 && anc != i2) {
757 MathXArray & c = anc.xcell();
758 int x = c.xo() + c.pos2x(anc.pos_);
759 int y1 = c.yo() - c.ascent();
760 int y2 = c.yo() + c.descent();
761 pain.line(x, y1, x, y2, LColor::math);
767 void MathCursor::handleFont(MathTextCodes t)
773 getSelection(i1, i2);
774 if (i1.idx_ == i2.idx_) {
775 MathArray & ar = i1.cell();
776 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
777 ar.at(pos)->handleFont(t);
780 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
784 void MathCursor::handleDelim(string const & l, string const & r)
786 handleNest(new MathDelimInset(l, r));
790 void MathCursor::handleNest(MathInset * p)
794 p->cell(0) = theSelection.glue();
796 insert(MathAtom(p)); // this invalidates p!
797 pushRight(prevAtom());
801 void MathCursor::getPos(int & x, int & y)
804 #warning This should probably take cellXOffset and cellYOffset into account
806 x = xarray().xo() + xarray().pos2x(pos());
811 MathAtom & MathCursor::par() const
813 return *cursor().par_;
817 InsetFormulaBase * MathCursor::formula()
823 MathCursor::idx_type MathCursor::idx() const
825 return cursor().idx_;
829 MathCursor::idx_type & MathCursor::idx()
831 return cursor().idx_;
835 MathCursor::pos_type MathCursor::pos() const
837 return cursor().pos_;
841 MathCursor::pos_type & MathCursor::pos()
843 return cursor().pos_;
847 bool MathCursor::inMacroMode() const
849 return macroNamePos() != -1;
853 bool MathCursor::selection() const
859 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
861 for (int i = Cursor_.size() - 1; i >= 0; --i) {
862 MathGridInset * p = (*Cursor_[i].par_)->asGridInset();
864 idx = Cursor_[i].idx_;
872 void MathCursor::pullArg(bool goright)
875 MathArray a = array();
877 MathScriptInset const * p = par()->asScriptInset();
879 // special handling for scripts
880 const bool up = p->hasUp();
882 MathScriptInset * q = nextAtom()->asScriptInset();
886 array().insert(pos(), a);
892 array().insert(pos(), a);
899 void MathCursor::normalize() const
902 #warning This is evil!
904 MathCursor * it = const_cast<MathCursor *>(this);
906 if (idx() >= par()->nargs()) {
907 lyxerr << "this should not really happen - 1: "
908 << idx() << " " << par()->nargs() << "\n";
911 it->idx() = min(idx(), par()->nargs() - 1);
913 if (pos() > size()) {
914 lyxerr << "this should not really happen - 2: "
915 << pos() << " " << size() << " in idx: " << it->idx()
917 WriteStream wi(lyxerr, false);
918 it->par()->write(wi);
922 it->pos() = min(pos(), size());
926 MathCursor::size_type MathCursor::size() const
928 return array().size();
932 MathCursor::col_type MathCursor::col() const
934 return par()->col(idx());
938 MathCursor::row_type MathCursor::row() const
940 return par()->row(idx());
944 bool MathCursor::hasPrevAtom() const
950 bool MathCursor::hasNextAtom() const
952 return pos() < size();
956 MathAtom const & MathCursor::prevAtom() const
958 lyx::Assert(pos() > 0);
959 return array().at(pos() - 1);
963 MathAtom & MathCursor::prevAtom()
965 lyx::Assert(pos() > 0);
966 return array().at(pos() - 1);
970 MathAtom const & MathCursor::nextAtom() const
972 lyx::Assert(pos() < size());
973 return array().at(pos());
977 MathAtom & MathCursor::nextAtom()
979 lyx::Assert(pos() < size());
980 return array().at(pos());
984 MathArray & MathCursor::array() const
986 static MathArray dummy;
988 if (idx() >= par()->nargs()) {
989 lyxerr << "############ idx_ " << idx() << " not valid\n";
993 if (Cursor_.size() == 0) {
994 lyxerr << "############ Cursor_.size() == 0 not valid\n";
998 return cursor().cell();
1002 MathXArray & MathCursor::xarray() const
1004 static MathXArray dummy;
1006 if (Cursor_.size() == 0) {
1007 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1011 return cursor().xcell();
1015 void MathCursor::idxNext()
1017 par()->idxNext(idx(), pos());
1021 void MathCursor::idxPrev()
1023 par()->idxPrev(idx(), pos());
1027 void MathCursor::splitCell()
1029 if (idx() + 1 == par()->nargs())
1031 MathArray ar = array();
1033 array().erase(pos(), size());
1036 array().insert(0, ar);
1040 void MathCursor::breakLine()
1042 // leave inner cells
1046 MathHullInset * p = formula()->par()->asHullInset();
1050 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1051 p->mutate(LM_OT_EQNARRAY);
1058 const row_type r = row();
1059 for (col_type c = col() + 1; c < p->ncols(); ++c)
1060 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1064 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1069 void MathCursor::readLine(MathArray & ar) const
1071 idx_type base = row() * par()->ncols();
1072 for (idx_type off = 0; off < par()->ncols(); ++off)
1073 ar.push_back(par()->cell(base + off));
1077 char MathCursor::valign() const
1080 MathGridInset * p = enclosingGrid(idx);
1081 return p ? p->valign() : '\0';
1085 char MathCursor::halign() const
1088 MathGridInset * p = enclosingGrid(idx);
1089 return p ? p->halign(idx % p->ncols()) : '\0';
1093 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1095 MathCursorPos anc = normalAnchor();
1096 if (anc < cursor()) {
1106 MathCursorPos & MathCursor::cursor()
1108 lyx::Assert(Cursor_.size());
1109 return Cursor_.back();
1113 MathCursorPos const & MathCursor::cursor() const
1115 lyx::Assert(Cursor_.size());
1116 return Cursor_.back();
1120 bool MathCursor::goUp()
1122 // first ask the inset if it knows better then we
1123 if (par()->idxUp(idx(), pos())) {
1124 //lyxerr << "ask cell\n";
1125 int xlow, xhigh, ylow, yhigh;
1126 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1127 bruteFind(xlow, xhigh, ylow, yhigh);
1131 // if not, apply brute force.
1132 //lyxerr << "brute force\n";
1138 xarray().yo() - 4 - xarray().ascent()
1143 bool MathCursor::goDown()
1145 // first ask the inset if it knows better then we
1146 if (par()->idxDown(idx(), pos())) {
1147 //lyxerr << "ask cell\n";
1148 int xlow, xhigh, ylow, yhigh;
1149 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1150 bruteFind(xlow, xhigh, ylow, yhigh);
1154 // if not, apply brute force.
1155 //lyxerr << "brute force\n";
1160 xarray().yo() + 4 + xarray().descent(),
1166 bool MathCursor::bruteFind(int xlow, int xhigh, int ylow, int yhigh)
1171 //lyxerr << "looking at range: "
1172 // << "[" << xlow << "..." << xhigh << "]"
1173 // << " x [" << ylow << "..." << yhigh << "]"
1174 // << " xo: " << x << " yo: " << y << "\n";
1176 cursor_type best_cursor;
1177 double best_dist = 1e10;
1179 MathIterator it = ibegin(formula()->par());
1180 MathIterator et = iend(formula()->par());
1181 for ( ; it != et; ++it) {
1182 int xo = it.position().xpos();
1183 int yo = it.position().ypos();
1184 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1185 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1186 if (d < best_dist) {
1188 best_cursor = it.cursor();
1192 if (best_dist < 1e10)
1193 Cursor_ = best_cursor;
1194 return best_dist < 1e10;
1198 bool MathCursor::idxLeft()
1200 return par()->idxLeft(idx(), pos());
1204 bool MathCursor::idxRight()
1206 return par()->idxRight(idx(), pos());
1210 bool MathCursor::interpret(string const & s)
1212 //lyxerr << "interpret 1: '" << s << "'\n";
1217 return interpret(s[0]);
1219 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1220 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1221 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1223 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1225 istringstream is(s.substr(5).c_str());
1227 n = std::max(1u, n);
1228 niceInsert(MathAtom(new MathCasesInset(n)));
1232 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1237 istringstream is(s.substr(6).c_str());
1238 is >> m >> n >> v_align >> h_align;
1239 m = std::max(1u, m);
1240 n = std::max(1u, n);
1242 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1246 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1248 istringstream is(s.substr(7).c_str());
1251 mathed_parse_cell(rep.from, from);
1252 mathed_parse_cell(rep.to, to);
1253 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1254 par()->replace(rep);
1258 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1259 MathArray ar = array();
1260 MathAtom t = createMathInset(s.substr(1));
1261 t->asNestInset()->cell(0).swap(array());
1269 latexkeys const * l = in_word_set(s.substr(1));
1270 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1271 lastcode_ = static_cast<MathTextCodes>(l->id);
1275 niceInsert(createMathInset(s.substr(1)));
1280 bool MathCursor::interpret(char c)
1282 //lyxerr << "interpret 2: '" << c << "'\n";
1283 if (c == '^' || c == '_') {
1285 const bool up = (c == '^');
1287 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1288 prevAtom()->asScriptInset()->ensure(up);
1289 pushRight(prevAtom());
1292 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1293 nextAtom()->asScriptInset()->ensure(up);
1294 pushLeft(nextAtom());
1298 plainInsert(MathAtom(new MathScriptInset(up)));
1299 prevAtom()->asScriptInset()->ensure(up);
1300 pushRight(prevAtom());
1311 if (inMacroMode()) {
1312 string name = macroName();
1314 if (name == "\\" && c == '#') {
1315 insert(c, LM_TC_TEX);
1319 if (name == "\\" && c == '\\') {
1321 interpret("\\backslash");
1325 if (name == "\\#" && '1' <= c && c <= '9') {
1326 insert(c, LM_TC_TEX);
1332 insert(c, LM_TC_TEX);
1337 insert(c, LM_TC_TEX);
1349 if (lastcode_ == LM_TC_TEXTRM) {
1350 // suppress direct insertion of to spaces in a row
1351 // the still allows typing '<space>a<space>' and deleting the 'a', but
1352 // it is better than nothing
1353 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1355 insert(c, LM_TC_TEXTRM);
1360 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1361 prevAtom()->asSpaceInset()->incSpace();
1365 if (mathcursor->popRight())
1368 // if are at the very end, leave the formula
1369 return pos() != size();
1373 if (strchr("{}", c)) {
1374 insert(c, LM_TC_TEX);
1380 niceInsert(MathAtom(new MathBraceInset));
1388 if (strchr("#$%", c)) {
1389 insert(MathAtom(new MathSpecialCharInset(c)));
1390 lastcode_ = LM_TC_VAR;
1394 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1395 insert(c, LM_TC_VAR);
1399 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1400 insert(c, LM_TC_VAR);
1401 lastcode_ = LM_TC_VAR;
1406 insert(c, LM_TC_TEX);
1407 //bv->owner()->message(_("TeX mode"));
1411 // no special circumstances, so insert the character without any fuss
1412 insert(c, lastcode_);
1413 lastcode_ = LM_TC_MIN;
1419 MathCursorPos MathCursor::normalAnchor() const
1421 lyx::Assert(Anchor_.size() >= Cursor_.size());
1422 // use Anchor on the same level as Cursor
1423 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1424 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1425 // anchor is behind cursor -> move anchor behind the inset
1432 void MathCursor::stripFromLastEqualSign()
1434 // find position of last '=' in the array
1435 MathArray & ar = cursor().cell();
1436 MathArray::const_iterator et = ar.end();
1437 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1438 if ((*it)->getChar() == '=')
1441 // delete everything behind this position
1442 ar.erase(et - ar.begin(), ar.size());