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"
32 #include "formulabase.h"
33 #include "math_cursor.h"
34 #include "math_factory.h"
35 #include "math_arrayinset.h"
36 #include "math_charinset.h"
37 #include "math_deliminset.h"
38 #include "math_matrixinset.h"
39 #include "math_scriptinset.h"
40 #include "math_spaceinset.h"
41 #include "math_specialcharinset.h"
42 #include "math_parser.h"
56 void grab(MathCursor const & cursor)
61 cursor.getSelection(i1, i2);
62 if (i1.idx_ == i2.idx_)
63 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
65 std::vector<MathInset::idx_type> indices =
66 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
67 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
68 data_.push_back(i1.cell(indices[i]));
72 void erase(MathCursor & cursor)
76 cursor.getSelection(i1, i2);
77 if (i1.idx_ == i2.idx_) {
78 i1.cell().erase(i1.pos_, i2.pos_);
80 std::vector<MathInset::idx_type> indices =
81 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
82 for (unsigned i = 0; i < indices.size(); ++i)
83 i1.cell(indices[i]).erase();
88 void paste(MathCursor & cursor) const
90 MathArray ar = glue();
94 // glues selection to one cell
95 MathArray glue() const
98 for (unsigned i = 0; i < data_.size(); ++i)
99 ar.push_back(data_[i]);
108 std::vector<MathArray> data_;
112 Selection theSelection;
116 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
118 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
126 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
127 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
129 left ? first() : last();
133 void MathCursor::push(MathAtom & t)
139 Cursor_.push_back(p);
143 void MathCursor::pushLeft(MathAtom & t)
145 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
147 t->idxFirst(idx(), pos());
151 void MathCursor::pushRight(MathAtom & t)
153 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
156 t->idxLast(idx(), pos());
160 bool MathCursor::popLeft()
162 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
163 if (Cursor_.size() <= 1)
166 // nextInset()->removeEmptyScripts();
169 // nextAtom()->removeEmptyScripts();
174 bool MathCursor::popRight()
176 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
177 if (Cursor_.size() <= 1)
180 // nextInset()->removeEmptyScripts();
183 // nextInset()->removeEmptyScripts();
191 void MathCursor::dump(char const * what) const
193 lyxerr << "MC: " << what << "\n";
194 for (unsigned i = 0; i < Cursor_.size(); ++i)
195 lyxerr << " i: " << i
196 << " Cursor: pos: " << Cursor_[i].pos_
197 << " idx: " << Cursor_[i].idx_
198 << " par: " << Cursor_[i].par_ << "\n";
200 for (unsigned i = 0; i < Anchor_.size(); ++i)
201 lyxerr << " i: " << i
202 << " Anchor: pos: " << Anchor_[i].pos_
203 << " idx: " << Anchor_[i].idx_
204 << " par: " << Anchor_[i].par_ << "\n";
206 lyxerr << " sel: " << selection_ << "\n";
210 void MathCursor::seldump(char const * str) const
212 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
215 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
216 << str << "\ntheSelection: " << selection_
217 << " '" << theSelection.glue() << "'\n";
218 for (unsigned int i = 0; i < Cursor_.size(); ++i)
219 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
221 for (unsigned int i = 0; i < Anchor_.size(); ++i)
222 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
223 //lyxerr << "\ncursor.pos_: " << pos();
224 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
225 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
230 void MathCursor::seldump(char const *) const {}
231 void MathCursor::dump(char const *) const {}
236 bool MathCursor::isInside(MathInset const * p) const
238 for (unsigned i = 0; i < Cursor_.size(); ++i)
239 if (Cursor_[i].par_->nucleus() == p)
245 bool MathCursor::openable(MathAtom const & t, bool sel) const
250 if (t->asScriptInset())
254 // we can't move into anything new during selection
255 if (Cursor_.size() == Anchor_.size())
257 if (&t != Anchor_[Cursor_.size()].par_)
264 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
267 // we can't move into anything new during selection
268 if (Cursor_.size() == Anchor_.size())
270 //if (t != Anchor_[Cursor_.size()].par_)
274 return t->nargs() && t->covers(x, y);
278 bool MathCursor::posLeft()
287 bool MathCursor::posRight()
296 bool MathCursor::left(bool sel)
301 lastcode_ = LM_TC_VAR;
305 lastcode_ = LM_TC_VAR;
307 if (hasPrevAtom() && openable(prevAtom(), sel)) {
308 pushRight(prevAtom());
312 return posLeft() || idxLeft() || popLeft() || selection_;
316 bool MathCursor::right(bool sel)
321 lastcode_ = LM_TC_VAR;
325 lastcode_ = LM_TC_VAR;
327 if (hasNextAtom() && openable(nextAtom(), sel)) {
328 pushLeft(nextAtom());
332 return posRight() || idxRight() || popRight() || selection_;
336 void MathCursor::first()
339 pushLeft(formula_->par());
343 void MathCursor::last()
350 void MathCursor::setPos(int x, int y)
353 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
356 lastcode_ = LM_TC_VAR;
359 cursor().par_ = &formula_->par();
364 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
365 int distmin = 1 << 30; // large enough
366 for (unsigned int i = 0; i < par()->nargs(); ++i) {
367 MathXArray const & ar = par()->xcell(i);
368 int x1 = x - ar.xo();
369 int y1 = y - ar.yo();
370 MathXArray::size_type c = ar.x2pos(x1);
371 int xx = abs(x1 - ar.pos2x(c));
373 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
374 // << " c: " << c << " xo: " << ar.xo() << "\n";
375 if (yy + xx <= distmin) {
381 //lyxerr << "found idx: " << idx() << " cursor: "
383 if (hasNextAtom() && positionable(nextAtom(), x, y))
384 pushLeft(nextAtom());
385 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
386 pushRight(prevAtom());
394 void MathCursor::home(bool sel)
399 lastcode_ = LM_TC_VAR;
400 if (!par()->idxHome(idx(), pos()))
406 void MathCursor::end(bool sel)
411 lastcode_ = LM_TC_VAR;
412 if (!par()->idxEnd(idx(), pos()))
418 void MathCursor::plainErase()
420 array().erase(pos());
424 void MathCursor::plainInsert(MathAtom const & t)
426 array().insert(pos(), t);
431 void MathCursor::insert(char c, MathTextCodes t)
433 //lyxerr << "inserting '" << c << "'\n";
434 plainInsert(MathAtom(new MathCharInset(c, t)));
438 void MathCursor::insert(MathAtom const & t)
453 void MathCursor::niceInsert(MathAtom const & t)
456 insert(t); // inserting invalidates the pointer!
457 MathAtom const & p = prevAtom();
460 right(); // do not push for e.g. MathSymbolInset
463 p->metrics(p->size());
467 void MathCursor::insert(MathArray const & ar)
473 array().insert(pos(), ar);
478 void MathCursor::paste(MathArray const & ar)
482 array().insert(pos(), ar);
487 void MathCursor::backspace()
499 MathScriptInset * p = prevAtom()->asScriptInset();
501 p->removeScript(p->hasUp());
502 // Don't delete if there is anything left
503 if (p->hasUp() || p->hasDown())
512 void MathCursor::erase()
522 // delete empty cells if necessary
523 if (array().empty()) {
526 par()->idxDelete(idx(), popit, removeit);
527 if (popit && popLeft() && removeit)
535 MathScriptInset * p = nextAtom()->asScriptInset();
537 p->removeScript(p->hasUp());
538 // Don't delete if there is anything left
539 if (p->hasUp() || p->hasDown())
547 void MathCursor::delLine()
556 if (par()->nrows() > 1)
557 par()->delRow(row());
561 bool MathCursor::up(bool sel)
568 // check whether we could move into a superscript
570 MathAtom & p = prevAtom();
571 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
580 MathAtom & n = nextAtom();
581 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
590 return goUp() || selection_;
594 bool MathCursor::down(bool sel)
601 // check whether we could move into a subscript
603 MathAtom & p = prevAtom();
604 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
613 MathAtom & n = nextAtom();
614 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
623 return goDown() || selection_;
627 bool MathCursor::toggleLimits()
631 MathScriptInset * t = prevAtom()->asScriptInset();
634 int old = t->limits();
635 t->limits(old < 0 ? 1 : -1);
636 return old != t->limits();
640 void MathCursor::setSize(MathStyles size)
642 par()->userSetSize(size);
646 void MathCursor::macroModeClose()
648 string s = macroName();
650 size_type old = pos();
652 array().erase(pos(), old);
658 int MathCursor::macroNamePos() const
660 for (int i = pos() - 1; i >= 0; --i) {
661 MathAtom & p = array().at(i);
662 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
669 string MathCursor::macroName() const
672 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
673 s += array().at(i)->getChar();
678 void MathCursor::selCopy()
682 theSelection.grab(*this);
688 void MathCursor::selCut()
692 theSelection.grab(*this);
693 theSelection.erase(*this);
696 theSelection.clear();
701 void MathCursor::selDel()
705 theSelection.erase(*this);
711 void MathCursor::selPaste()
714 theSelection.paste(*this);
715 theSelection.grab(*this);
720 void MathCursor::selHandle(bool sel)
722 if (sel == selection_)
725 theSelection.clear();
731 void MathCursor::selStart()
737 theSelection.clear();
743 void MathCursor::selClear()
750 void MathCursor::drawSelection(Painter & pain) const
757 getSelection(i1, i2);
759 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
761 if (i1.idx_ == i2.idx_) {
762 MathXArray & c = i1.xcell();
763 int x1 = c.xo() + c.pos2x(i1.pos_);
764 int y1 = c.yo() - c.ascent();
765 int x2 = c.xo() + c.pos2x(i2.pos_);
766 int y2 = c.yo() + c.descent();
767 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
769 std::vector<MathInset::idx_type> indices
770 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
771 for (unsigned i = 0; i < indices.size(); ++i) {
772 MathXArray & c = i1.xcell(indices[i]);
774 int y1 = c.yo() - c.ascent();
775 int x2 = c.xo() + c.width();
776 int y2 = c.yo() + c.descent();
777 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
783 void MathCursor::handleFont(MathTextCodes t)
789 getSelection(i1, i2);
790 if (i1.idx_ == i2.idx_) {
791 MathArray & ar = i1.cell();
792 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
793 ar.at(pos)->handleFont(t);
796 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
800 void MathCursor::handleDelim(string const & l, string const & r)
802 handleNest(new MathDelimInset(l, r));
806 void MathCursor::handleNest(MathInset * p)
810 p->cell(0) = theSelection.glue();
812 insert(MathAtom(p)); // this invalidates p!
813 pushRight(prevAtom());
817 void MathCursor::getPos(int & x, int & y)
820 #warning This should probably take cellXOffset and cellYOffset into account
822 x = xarray().xo() + xarray().pos2x(pos());
827 MathAtom & MathCursor::par() const
829 return *cursor().par_;
833 InsetFormulaBase const * MathCursor::formula()
839 MathCursor::idx_type MathCursor::idx() const
841 return cursor().idx_;
845 MathCursor::idx_type & MathCursor::idx()
847 return cursor().idx_;
851 MathCursor::pos_type MathCursor::pos() const
853 return cursor().pos_;
857 MathCursor::pos_type & MathCursor::pos()
859 return cursor().pos_;
863 bool MathCursor::inMacroMode() const
865 return macroNamePos() != -1;
869 bool MathCursor::selection() const
875 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
877 for (int i = Cursor_.size() - 1; i >= 0; --i) {
878 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
880 idx = Cursor_[i].idx_;
888 void MathCursor::pullArg(bool goright)
891 MathArray a = array();
893 MathScriptInset const * p = par()->asScriptInset();
895 // special handling for scripts
896 const bool up = p->hasUp();
898 MathScriptInset * q = nextAtom()->asScriptInset();
902 array().insert(pos(), a);
908 array().insert(pos(), a);
915 MathStyles MathCursor::style() const
917 return xarray().style();
921 void MathCursor::normalize() const
924 #warning This is evil!
926 MathCursor * it = const_cast<MathCursor *>(this);
928 if (idx() >= par()->nargs()) {
929 lyxerr << "this should not really happen - 1: "
930 << idx() << " " << par()->nargs() << "\n";
933 it->idx() = min(idx(), par()->nargs() - 1);
935 if (pos() > size()) {
936 lyxerr << "this should not really happen - 2: "
937 << pos() << " " << size() << " in idx: " << it->idx()
939 it->par()->write(lyxerr, false);
943 it->pos() = min(pos(), size());
947 MathCursor::size_type MathCursor::size() const
949 return array().size();
953 MathCursor::col_type MathCursor::col() const
955 return par()->col(idx());
959 MathCursor::row_type MathCursor::row() const
961 return par()->row(idx());
965 bool MathCursor::hasPrevAtom() const
971 bool MathCursor::hasNextAtom() const
973 return pos() < size();
977 MathAtom const & MathCursor::prevAtom() const
979 lyx::Assert(pos() > 0);
980 return array().at(pos() - 1);
984 MathAtom & MathCursor::prevAtom()
986 lyx::Assert(pos() > 0);
987 return array().at(pos() - 1);
991 MathAtom const & MathCursor::nextAtom() const
993 lyx::Assert(pos() < size());
994 return array().at(pos());
998 MathAtom & MathCursor::nextAtom()
1000 lyx::Assert(pos() < size());
1001 return array().at(pos());
1005 MathArray & MathCursor::array() const
1007 static MathArray dummy;
1009 if (idx() >= par()->nargs()) {
1010 lyxerr << "############ idx_ " << idx() << " not valid\n";
1014 return cursor().cell();
1018 MathXArray & MathCursor::xarray() const
1020 return cursor().xcell();
1024 void MathCursor::idxNext()
1026 par()->idxNext(idx(), pos());
1030 void MathCursor::idxPrev()
1032 par()->idxPrev(idx(), pos());
1036 void MathCursor::splitCell()
1038 if (idx() == par()->nargs() - 1)
1040 MathArray ar = array();
1042 array().erase(pos(), size());
1045 array().insert(0, ar);
1049 void MathCursor::breakLine()
1051 // leave inner cells
1055 MathMatrixInset * p = formula()->par()->asMatrixInset();
1059 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1060 p->mutate(LM_OT_EQNARRAY);
1067 const row_type r = row();
1068 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1069 const MathMatrixInset::idx_type i1 = p->index(r, c);
1070 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1071 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1072 p->cell(i1).swap(p->cell(i2));
1077 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1082 char MathCursor::valign() const
1085 MathArrayInset * p = enclosingArray(idx);
1086 return p ? p->valign() : '\0';
1090 char MathCursor::halign() const
1093 MathArrayInset * p = enclosingArray(idx);
1094 return p ? p->halign(idx % p->ncols()) : '\0';
1098 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1100 MathCursorPos anc = normalAnchor();
1101 if (anc < cursor()) {
1111 MathCursorPos & MathCursor::cursor()
1113 return Cursor_.back();
1117 MathCursorPos const & MathCursor::cursor() const
1119 return Cursor_.back();
1123 int MathCursor::cellXOffset() const
1125 return par()->cellXOffset(idx());
1129 int MathCursor::cellYOffset() const
1131 return par()->cellYOffset(idx());
1135 int MathCursor::xpos() const
1137 return cellXOffset() + xarray().pos2x(pos());
1141 int MathCursor::ypos() const
1143 return cellYOffset();
1148 void MathCursor::gotoX(int x)
1150 pos() = xarray().x2pos(x - cellXOffset());
1154 bool MathCursor::goUp()
1156 // first ask the inset if it knows better then we
1157 if (par()->idxUp(idx(), pos()))
1160 // leave subscript to the nearest side
1161 MathScriptInset * p = par()->asScriptInset();
1162 if (p && p->hasDown()) {
1163 if (pos() <= size() / 2)
1170 // if not, apply brute force.
1174 std::vector<MathCursorPos> save = Cursor_;
1175 MathAtom const & out = formula()->par();
1176 y0 -= xarray().ascent();
1177 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1179 if (save != Cursor_ && xarray().yo() < y0)
1187 bool MathCursor::goDown()
1189 // first ask the inset if it knows better then we
1190 if (par()->idxDown(idx(), pos()))
1193 // leave superscript to the nearest side
1194 MathScriptInset * p = par()->asScriptInset();
1195 if (p && p->hasUp()) {
1196 if (pos() <= size() / 2)
1203 // if not, apply brute force.
1207 std::vector<MathCursorPos> save = Cursor_;
1208 MathAtom const & out = formula()->par();
1209 y0 += xarray().descent();
1210 for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
1212 if (save != Cursor_ && xarray().yo() > y0)
1220 bool MathCursor::idxLeft()
1222 return par()->idxLeft(idx(), pos());
1226 bool MathCursor::idxRight()
1228 return par()->idxRight(idx(), pos());
1232 void MathCursor::interpret(string const & s)
1234 //lyxerr << "interpret 1: '" << s << "'\n";
1235 //lyxerr << "in: " << in_word_set(s) << " \n";
1240 if (s.size() == 1) {
1245 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1246 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1247 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1249 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1254 istringstream is(s.substr(7).c_str());
1255 is >> m >> n >> v_align >> h_align;
1256 m = std::max(1u, m);
1257 n = std::max(1u, n);
1259 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1263 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1264 MathArray ar = array();
1265 MathAtom t = createMathInset(s.substr(1));
1266 t->asNestInset()->cell(0).swap(array());
1274 niceInsert(createMathInset(s.substr(1)));
1278 void MathCursor::interpret(char c)
1280 //lyxerr << "interpret 2: '" << c << "'\n";
1282 if (inMacroMode()) {
1283 string name = macroName();
1285 if (name == "\\" && c == '#') {
1286 insert(c, LM_TC_TEX);
1290 if (name == "\\" && c == '\\') {
1292 interpret("\\backslash");
1296 if (name == "\\#" && '1' <= c && c <= '9') {
1297 insert(c, LM_TC_TEX);
1303 insert(c, LM_TC_TEX);
1308 insert(c, LM_TC_TEX);
1318 if (c == '^' || c == '_') {
1319 const bool up = (c == '^');
1321 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1322 prevAtom()->asScriptInset()->ensure(up);
1323 pushRight(prevAtom());
1326 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1327 nextAtom()->asScriptInset()->ensure(up);
1328 pushLeft(nextAtom());
1332 plainInsert(MathAtom(new MathScriptInset(up)));
1333 prevAtom()->asScriptInset()->ensure(up);
1334 pushRight(prevAtom());
1346 if (lastcode_ == LM_TC_TEXTRM) {
1347 insert(c, LM_TC_TEXTRM);
1352 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1353 prevAtom()->asSpaceInset()->incSpace();
1357 if (mathcursor->popRight())
1361 // this would not work if the inset is in an table!
1362 //bv->text->cursorRight(bv, true);
1363 //result = FINISHED;
1367 if (strchr("{}", c)) {
1368 insert(c, LM_TC_TEX);
1372 if (strchr("#$%", c)) {
1373 insert(MathAtom(new MathSpecialCharInset(c)));
1374 lastcode_ = LM_TC_VAR;
1378 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1379 static char const greekl[][26] =
1380 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1381 "gamma", "eta", "iota", "epsilon", "kappa", "lambda", "mu",
1382 "nu", "omega", "pi", "vartheta", "rho", "sigma",
1383 "tau", "upsilon", "theta", "omega", "xi", "varphi", "zeta"};
1384 static char const greeku[][26] =
1385 {"alpha", "beta", "chi", "Delta", "varepsilon", "Phi",
1386 "Gamma", "varepsilon", "varepsilon", "epsilon", "kappa", "Lambda", "mu",
1387 "Nu", "Omega", "Pi", "vartheta", "varrho", "Sigma", "varsigma",
1388 "Upsilon", "Theta", "Omega", "Xi", "Varphi", "zeta"};
1390 latexkeys const * l = 0;
1391 if ('a' <= c && c <= 'z')
1392 l = in_word_set(greekl[c - 'a']);
1393 if ('A' <= c && c <= 'Z')
1394 l = in_word_set(greeku[c - 'A']);
1397 insert(createMathInset(l));
1399 insert(c, LM_TC_VAR);
1401 if (lastcode_ == LM_TC_GREEK1)
1402 lastcode_ = LM_TC_VAR;
1407 insert(c, LM_TC_TEX);
1408 //bv->owner()->message(_("TeX mode"));
1412 // no special circumstances, so insert the character without any fuss
1413 insert(c, LM_TC_MIN);
1418 ////////////////////////////////////////////////////////////////////////
1421 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1423 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1427 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1429 if (ti.par_ != it.par_) {
1430 lyxerr << "can't compare cursor and anchor in different insets\n";
1433 if (ti.idx_ != it.idx_)
1434 return ti.idx_ < it.idx_;
1435 return ti.pos_ < it.pos_;
1439 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1441 return (*par_)->cell(idx);
1445 MathArray & MathCursorPos::cell() const
1447 return (*par_)->cell(idx_);
1451 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1453 return (*par_)->xcell(idx);
1457 MathXArray & MathCursorPos::xcell() const
1459 return (*par_)->xcell(idx_);
1463 MathCursorPos MathCursor::normalAnchor() const
1465 // use Anchor on the same level as Cursor
1466 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1467 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1468 // anchor is behind cursor -> move anchor behind the inset