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
464 #warning "redraw disabled"
466 //p->metrics(p->size());
470 void MathCursor::insert(MathArray const & ar)
476 array().insert(pos(), ar);
481 void MathCursor::paste(MathArray const & ar)
485 array().insert(pos(), ar);
490 void MathCursor::backspace()
502 MathScriptInset * p = prevAtom()->asScriptInset();
504 p->removeScript(p->hasUp());
505 // Don't delete if there is anything left
506 if (p->hasUp() || p->hasDown())
515 void MathCursor::erase()
525 // delete empty cells if necessary
526 if (array().empty()) {
529 par()->idxDelete(idx(), popit, removeit);
530 if (popit && popLeft() && removeit)
538 MathScriptInset * p = nextAtom()->asScriptInset();
540 p->removeScript(p->hasUp());
541 // Don't delete if there is anything left
542 if (p->hasUp() || p->hasDown())
550 void MathCursor::delLine()
559 if (par()->nrows() > 1)
560 par()->delRow(row());
564 bool MathCursor::up(bool sel)
571 // check whether we could move into a superscript
573 MathAtom & p = prevAtom();
574 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
583 MathAtom & n = nextAtom();
584 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
593 return goUp() || selection_;
597 bool MathCursor::down(bool sel)
604 // check whether we could move into a subscript
606 MathAtom & p = prevAtom();
607 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
616 MathAtom & n = nextAtom();
617 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
626 return goDown() || selection_;
630 bool MathCursor::toggleLimits()
634 MathScriptInset * t = prevAtom()->asScriptInset();
637 int old = t->limits();
638 t->limits(old < 0 ? 1 : -1);
639 return old != t->limits();
643 void MathCursor::setSize(MathStyles size)
645 par()->userSetSize(size);
649 void MathCursor::macroModeClose()
651 string s = macroName();
653 size_type old = pos();
655 array().erase(pos(), old);
661 int MathCursor::macroNamePos() const
663 for (int i = pos() - 1; i >= 0; --i) {
664 MathAtom & p = array().at(i);
665 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
672 string MathCursor::macroName() const
675 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
676 s += array().at(i)->getChar();
681 void MathCursor::selCopy()
685 theSelection.grab(*this);
691 void MathCursor::selCut()
695 theSelection.grab(*this);
696 theSelection.erase(*this);
699 theSelection.clear();
704 void MathCursor::selDel()
708 theSelection.erase(*this);
714 void MathCursor::selPaste()
717 theSelection.paste(*this);
718 theSelection.grab(*this);
723 void MathCursor::selHandle(bool sel)
725 if (sel == selection_)
728 theSelection.clear();
734 void MathCursor::selStart()
740 theSelection.clear();
746 void MathCursor::selClear()
753 void MathCursor::drawSelection(Painter & pain) const
760 getSelection(i1, i2);
762 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
764 if (i1.idx_ == i2.idx_) {
765 MathXArray & c = i1.xcell();
766 int x1 = c.xo() + c.pos2x(i1.pos_);
767 int y1 = c.yo() - c.ascent();
768 int x2 = c.xo() + c.pos2x(i2.pos_);
769 int y2 = c.yo() + c.descent();
770 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
772 std::vector<MathInset::idx_type> indices
773 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
774 for (unsigned i = 0; i < indices.size(); ++i) {
775 MathXArray & c = i1.xcell(indices[i]);
777 int y1 = c.yo() - c.ascent();
778 int x2 = c.xo() + c.width();
779 int y2 = c.yo() + c.descent();
780 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
786 void MathCursor::handleFont(MathTextCodes t)
792 getSelection(i1, i2);
793 if (i1.idx_ == i2.idx_) {
794 MathArray & ar = i1.cell();
795 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
796 ar.at(pos)->handleFont(t);
799 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
803 void MathCursor::handleDelim(string const & l, string const & r)
805 handleNest(new MathDelimInset(l, r));
809 void MathCursor::handleNest(MathInset * p)
813 p->cell(0) = theSelection.glue();
815 insert(MathAtom(p)); // this invalidates p!
816 pushRight(prevAtom());
820 void MathCursor::getPos(int & x, int & y)
823 #warning This should probably take cellXOffset and cellYOffset into account
825 x = xarray().xo() + xarray().pos2x(pos());
830 MathAtom & MathCursor::par() const
832 return *cursor().par_;
836 InsetFormulaBase const * MathCursor::formula()
842 MathCursor::idx_type MathCursor::idx() const
844 return cursor().idx_;
848 MathCursor::idx_type & MathCursor::idx()
850 return cursor().idx_;
854 MathCursor::pos_type MathCursor::pos() const
856 return cursor().pos_;
860 MathCursor::pos_type & MathCursor::pos()
862 return cursor().pos_;
866 bool MathCursor::inMacroMode() const
868 return macroNamePos() != -1;
872 bool MathCursor::selection() const
878 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
880 for (int i = Cursor_.size() - 1; i >= 0; --i) {
881 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
883 idx = Cursor_[i].idx_;
891 void MathCursor::pullArg(bool goright)
894 MathArray a = array();
896 MathScriptInset const * p = par()->asScriptInset();
898 // special handling for scripts
899 const bool up = p->hasUp();
901 MathScriptInset * q = nextAtom()->asScriptInset();
905 array().insert(pos(), a);
911 array().insert(pos(), a);
918 MathStyles MathCursor::style() const
920 return xarray().style();
924 void MathCursor::normalize() const
927 #warning This is evil!
929 MathCursor * it = const_cast<MathCursor *>(this);
931 if (idx() >= par()->nargs()) {
932 lyxerr << "this should not really happen - 1: "
933 << idx() << " " << par()->nargs() << "\n";
936 it->idx() = min(idx(), par()->nargs() - 1);
938 if (pos() > size()) {
939 lyxerr << "this should not really happen - 2: "
940 << pos() << " " << size() << " in idx: " << it->idx()
942 MathWriteInfo wi(0, lyxerr, false);
943 it->par()->write(wi);
947 it->pos() = min(pos(), size());
951 MathCursor::size_type MathCursor::size() const
953 return array().size();
957 MathCursor::col_type MathCursor::col() const
959 return par()->col(idx());
963 MathCursor::row_type MathCursor::row() const
965 return par()->row(idx());
969 bool MathCursor::hasPrevAtom() const
975 bool MathCursor::hasNextAtom() const
977 return pos() < size();
981 MathAtom const & MathCursor::prevAtom() const
983 lyx::Assert(pos() > 0);
984 return array().at(pos() - 1);
988 MathAtom & MathCursor::prevAtom()
990 lyx::Assert(pos() > 0);
991 return array().at(pos() - 1);
995 MathAtom const & MathCursor::nextAtom() const
997 lyx::Assert(pos() < size());
998 return array().at(pos());
1002 MathAtom & MathCursor::nextAtom()
1004 lyx::Assert(pos() < size());
1005 return array().at(pos());
1009 MathArray & MathCursor::array() const
1011 static MathArray dummy;
1013 if (idx() >= par()->nargs()) {
1014 lyxerr << "############ idx_ " << idx() << " not valid\n";
1018 return cursor().cell();
1022 MathXArray & MathCursor::xarray() const
1024 return cursor().xcell();
1028 void MathCursor::idxNext()
1030 par()->idxNext(idx(), pos());
1034 void MathCursor::idxPrev()
1036 par()->idxPrev(idx(), pos());
1040 void MathCursor::splitCell()
1042 if (idx() == par()->nargs() - 1)
1044 MathArray ar = array();
1046 array().erase(pos(), size());
1049 array().insert(0, ar);
1053 void MathCursor::breakLine()
1055 // leave inner cells
1059 MathMatrixInset * p = formula()->par()->asMatrixInset();
1063 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1064 p->mutate(LM_OT_EQNARRAY);
1071 const row_type r = row();
1072 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1073 const MathMatrixInset::idx_type i1 = p->index(r, c);
1074 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1075 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1076 p->cell(i1).swap(p->cell(i2));
1081 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1083 // correct cursor position
1090 char MathCursor::valign() const
1093 MathArrayInset * p = enclosingArray(idx);
1094 return p ? p->valign() : '\0';
1098 char MathCursor::halign() const
1101 MathArrayInset * p = enclosingArray(idx);
1102 return p ? p->halign(idx % p->ncols()) : '\0';
1106 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1108 MathCursorPos anc = normalAnchor();
1109 if (anc < cursor()) {
1119 MathCursorPos & MathCursor::cursor()
1121 return Cursor_.back();
1125 MathCursorPos const & MathCursor::cursor() const
1127 return Cursor_.back();
1131 int MathCursor::cellXOffset() const
1133 return par()->cellXOffset(idx());
1137 int MathCursor::cellYOffset() const
1139 return par()->cellYOffset(idx());
1143 int MathCursor::xpos() const
1145 return cellXOffset() + xarray().pos2x(pos());
1149 int MathCursor::ypos() const
1151 return cellYOffset();
1156 void MathCursor::gotoX(int x)
1158 pos() = xarray().x2pos(x - cellXOffset());
1162 bool MathCursor::goUp()
1164 // first ask the inset if it knows better then we
1165 if (par()->idxUp(idx(), pos()))
1168 // leave subscript to the nearest side
1169 MathScriptInset * p = par()->asScriptInset();
1170 if (p && idx() == 0) {
1171 if (pos() <= size() / 2)
1178 // if not, apply brute force.
1182 std::vector<MathCursorPos> save = Cursor_;
1183 MathAtom const & out = formula()->par();
1184 y0 -= xarray().ascent();
1185 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1187 if (save != Cursor_ && xarray().yo() < y0)
1195 bool MathCursor::goDown()
1197 // first ask the inset if it knows better then we
1198 if (par()->idxDown(idx(), pos()))
1201 // leave superscript to the nearest side
1202 MathScriptInset * p = par()->asScriptInset();
1203 if (p && idx() == 1) {
1204 if (pos() <= size() / 2)
1211 // if not, apply brute force.
1215 std::vector<MathCursorPos> save = Cursor_;
1216 MathAtom const & out = formula()->par();
1217 y0 += xarray().descent();
1218 for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
1220 if (save != Cursor_ && xarray().yo() > y0)
1228 bool MathCursor::idxLeft()
1230 return par()->idxLeft(idx(), pos());
1234 bool MathCursor::idxRight()
1236 return par()->idxRight(idx(), pos());
1240 void MathCursor::interpret(string const & s)
1242 //lyxerr << "interpret 1: '" << s << "'\n";
1243 //lyxerr << "in: " << in_word_set(s) << " \n";
1248 if (s.size() == 1) {
1253 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1254 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1255 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1257 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1262 istringstream is(s.substr(7).c_str());
1263 is >> m >> n >> v_align >> h_align;
1264 m = std::max(1u, m);
1265 n = std::max(1u, n);
1267 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1271 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1272 MathArray ar = array();
1273 MathAtom t = createMathInset(s.substr(1));
1274 t->asNestInset()->cell(0).swap(array());
1282 niceInsert(createMathInset(s.substr(1)));
1286 void MathCursor::interpret(char c)
1288 //lyxerr << "interpret 2: '" << c << "'\n";
1290 if (inMacroMode()) {
1291 string name = macroName();
1293 if (name == "\\" && c == '#') {
1294 insert(c, LM_TC_TEX);
1298 if (name == "\\" && c == '\\') {
1300 interpret("\\backslash");
1304 if (name == "\\#" && '1' <= c && c <= '9') {
1305 insert(c, LM_TC_TEX);
1311 insert(c, LM_TC_TEX);
1316 insert(c, LM_TC_TEX);
1326 if (c == '^' || c == '_') {
1327 const bool up = (c == '^');
1329 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1330 prevAtom()->asScriptInset()->ensure(up);
1331 pushRight(prevAtom());
1334 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1335 nextAtom()->asScriptInset()->ensure(up);
1336 pushLeft(nextAtom());
1340 plainInsert(MathAtom(new MathScriptInset(up)));
1341 prevAtom()->asScriptInset()->ensure(up);
1342 pushRight(prevAtom());
1354 if (lastcode_ == LM_TC_TEXTRM) {
1355 insert(c, LM_TC_TEXTRM);
1360 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1361 prevAtom()->asSpaceInset()->incSpace();
1365 if (mathcursor->popRight())
1369 // this would not work if the inset is in an table!
1370 //bv->text->cursorRight(bv, true);
1371 //result = FINISHED;
1375 if (strchr("{}", c)) {
1376 insert(c, LM_TC_TEX);
1380 if (strchr("#$%", c)) {
1381 insert(MathAtom(new MathSpecialCharInset(c)));
1382 lastcode_ = LM_TC_VAR;
1386 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1387 static char const greekl[][26] =
1388 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1389 "gamma", "eta", "iota", "epsilon", "kappa", "lambda", "mu",
1390 "nu", "omega", "pi", "vartheta", "rho", "sigma",
1391 "tau", "upsilon", "theta", "omega", "xi", "varphi", "zeta"};
1392 static char const greeku[][26] =
1393 {"alpha", "beta", "chi", "Delta", "varepsilon", "Phi",
1394 "Gamma", "varepsilon", "varepsilon", "epsilon", "kappa", "Lambda", "mu",
1395 "Nu", "Omega", "Pi", "vartheta", "varrho", "Sigma", "varsigma",
1396 "Upsilon", "Theta", "Omega", "Xi", "Varphi", "zeta"};
1398 latexkeys const * l = 0;
1399 if ('a' <= c && c <= 'z')
1400 l = in_word_set(greekl[c - 'a']);
1401 if ('A' <= c && c <= 'Z')
1402 l = in_word_set(greeku[c - 'A']);
1405 insert(createMathInset(l));
1407 insert(c, LM_TC_VAR);
1409 if (lastcode_ == LM_TC_GREEK1)
1410 lastcode_ = LM_TC_VAR;
1415 insert(c, LM_TC_TEX);
1416 //bv->owner()->message(_("TeX mode"));
1420 // no special circumstances, so insert the character without any fuss
1421 insert(c, LM_TC_MIN);
1426 ////////////////////////////////////////////////////////////////////////
1429 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1431 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1435 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1437 if (ti.par_ != it.par_) {
1438 lyxerr << "can't compare cursor and anchor in different insets\n";
1441 if (ti.idx_ != it.idx_)
1442 return ti.idx_ < it.idx_;
1443 return ti.pos_ < it.pos_;
1447 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1449 return (*par_)->cell(idx);
1453 MathArray & MathCursorPos::cell() const
1455 return (*par_)->cell(idx_);
1459 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1461 return (*par_)->xcell(idx);
1465 MathXArray & MathCursorPos::xcell() const
1467 return (*par_)->xcell(idx_);
1471 MathCursorPos MathCursor::normalAnchor() const
1473 // use Anchor on the same level as Cursor
1474 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1475 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1476 // anchor is behind cursor -> move anchor behind the inset