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"
31 #include "formulabase.h"
32 #include "math_cursor.h"
33 #include "math_factory.h"
34 #include "math_arrayinset.h"
35 #include "math_charinset.h"
36 #include "math_deliminset.h"
37 #include "math_matrixinset.h"
38 #include "math_scriptinset.h"
39 #include "math_spaceinset.h"
40 #include "math_specialcharinset.h"
41 #include "math_parser.h"
55 void grab(MathCursor const & cursor)
60 cursor.getSelection(i1, i2);
61 if (i1.idx_ == i2.idx_) {
64 ar.push_back(*i1.at());
65 ar.back().removeNucleus();
68 ar.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
70 ar.push_back(*i2.at());
72 ar.back().removeDown();
77 std::vector<MathInset::idx_type> indices =
78 i1.par_->idxBetween(i1.idx_, i2.idx_);
79 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
80 data_.push_back(i1.cell(indices[i]));
84 void erase(MathCursor & cursor)
88 cursor.getSelection(i1, i2);
89 if (i1.idx_ == i2.idx_) {
93 i1.at()->removeDown();
98 i2.at()->removeNucleus();
100 i1.cell().erase(i1.pos_, i2.pos_);
102 std::vector<MathInset::idx_type> indices =
103 i1.par_->idxBetween(i1.idx_, i2.idx_);
104 for (unsigned i = 0; i < indices.size(); ++i)
105 i1.cell(indices[i]).erase();
107 cursor.cursor() = i1;
110 void paste(MathCursor & cursor) const
112 cursor.insert(glue());
115 // glues selection to one cell
116 MathArray glue() const
119 for (unsigned i = 0; i < data_.size(); ++i)
120 ar.push_back(data_[i]);
129 std::vector<MathArray> data_;
133 Selection theSelection;
137 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
139 os << "(par: " << p.par_ << " idx: " << p.idx_
140 << " pos: " << p.pos_ << " inner: " << p.inner_ << ")";
148 MathCursor::MathCursor(InsetFormulaBase * formula)
149 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
155 void MathCursor::pushLeft(MathInset * par)
160 par->idxFirst(p.idx_, p.pos_);
161 Cursor_.push_back(p);
165 void MathCursor::pushRight(MathInset * par)
171 par->idxLast(p.idx_, p.pos_);
172 Cursor_.push_back(p);
176 bool MathCursor::popLeft()
178 if (Cursor_.size() <= 1)
181 nextAtom()->removeEmptyScripts();
184 nextAtom()->removeEmptyScripts();
189 bool MathCursor::popRight()
191 if (Cursor_.size() <= 1)
194 nextAtom()->removeEmptyScripts();
197 nextAtom()->removeEmptyScripts();
205 void MathCursor::dump(char const *) const
207 lyxerr << "MC: " << what << "\n";
208 for (unsigned i = 0; i < Cursor_.size(); ++i)
209 lyxerr << " i: " << i
210 << " pos: " << Cursor_[i].pos_
211 << " idx: " << Cursor_[i].idx_
212 << " par: " << Cursor_[i].par_ << "\n";
213 //lyxerr << " sel: " << selection_ << " data: " << array() << "\n";
216 void MathCursor::seldump(char const * str) const
218 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
221 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
222 << str << "\ntheSelection: " << selection_
223 << " '" << theSelection.glue() << "'\n";
224 for (unsigned int i = 0; i < Cursor_.size(); ++i)
225 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
227 for (unsigned int i = 0; i < Anchor_.size(); ++i)
228 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
229 //lyxerr << "\ncursor.pos_: " << pos();
230 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
231 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
236 void MathCursor::seldump(char const *) const {}
237 void MathCursor::dump(char const *) const {}
242 bool MathCursor::isInside(MathInset const * p) const
244 for (unsigned i = 0; i < Cursor_.size(); ++i)
245 if (Cursor_[i].par_ == p)
251 bool MathCursor::openable(MathInset * p, bool sel) const
260 // we can't move into anything new during selection
261 if (Cursor_.size() == Anchor_.size())
263 if (p != Anchor_[Cursor_.size()].par_)
270 MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
276 // we can't move into anything new during selection
277 if (Cursor_.size() == Anchor_.size())
279 //if (t != Anchor_[Cursor_.size()].par_)
286 if (p && p->nargs() && p->covers(x, y))
290 if (p && p->nargs() && p->covers(x, y))
294 if (p && p->nargs() && p->covers(x, y))
301 bool MathCursor::posLeft()
313 if (nextAtom()->hasInner())
320 bool MathCursor::posRight()
331 if (nextAtom()->hasInner())
340 bool MathCursor::left(bool sel)
345 lastcode_ = LM_TC_VAR;
349 lastcode_ = LM_TC_VAR;
351 MathInset * p = prevInset();
352 if (openable(p, sel)) {
357 return posLeft() || idxLeft() || popLeft();
361 bool MathCursor::right(bool sel)
366 lastcode_ = LM_TC_VAR;
370 lastcode_ = LM_TC_VAR;
372 MathInset * p = nextInset();
373 if (openable(p, sel)) {
378 return posRight() || idxRight() || popRight();
382 void MathCursor::first()
385 pushLeft(outerPar());
389 void MathCursor::last()
396 void MathCursor::setPos(int x, int y)
399 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
402 lastcode_ = LM_TC_VAR;
405 cursor().par_ = outerPar();
410 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
411 int distmin = 1 << 30; // large enough
412 for (unsigned int i = 0; i < par()->nargs(); ++i) {
413 MathXArray const & ar = par()->xcell(i);
414 int x1 = x - ar.xo();
415 int y1 = y - ar.yo();
416 MathXArray::size_type c = ar.x2pos(x1);
417 int xx = abs(x1 - ar.pos2x(c, false));
419 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
420 // << " c: " << c << " xo: " << ar.xo() << "\n";
421 if (yy + xx <= distmin) {
427 //lyxerr << "found idx: " << idx() << " cursor: "
429 if (MathInset * p = positionable(nextAtom(), x, y))
431 else if (MathInset * p = positionable(prevAtom(), x, y))
440 void MathCursor::home(bool sel)
445 lastcode_ = LM_TC_VAR;
446 if (!par()->idxHome(idx(), pos()))
452 void MathCursor::end(bool sel)
457 lastcode_ = LM_TC_VAR;
458 if (!par()->idxEnd(idx(), pos()))
464 void MathCursor::plainErase()
466 array().erase(pos());
470 void MathCursor::plainInsert(MathInset * p)
473 array().insert(pos(), p);
475 if (prevAtom() && nextAtom()) // should be unnecessary
476 swap(prevAtom()->nucleus(), nextAtom()->nucleus());
480 MathAtom * n = nextAtom();
482 if (n && !n->nucleus()) {
488 array().insert(pos(), p); // this invalidates the pointer!
493 void MathCursor::insert(char c, MathTextCodes t)
495 //lyxerr << "inserting '" << c << "'\n";
496 plainInsert(new MathCharInset(c, t));
500 void MathCursor::insert(MathInset * p)
504 if (p && selection_) {
515 void MathCursor::niceInsert(MathInset * p)
518 lyxerr << "MathCursor::niceInsert: should not happen\n";
522 //cerr << "\n2: "; p->write(cerr, true); cerr << "\n";
523 insert(p); // inserting invalidates the pointer!
524 p = prevAtom()->nucleus();
525 //cerr << "\n3: "; p->write(cerr, true); cerr << "\n";
528 right(); // do not push for e.g. MathSymbolInset
531 p->metrics(p->size());
535 void MathCursor::insert(MathArray const & ar)
541 array().insert(pos(), ar);
546 void MathCursor::glueAdjacentAtoms()
548 MathAtom * p = prevAtom();
552 MathAtom * n = nextAtom();
556 if (p->up() && n->up())
559 if (p->down() && n->down())
562 // move everything to the previous atom
564 swap(p->up(), n->up());
567 swap(p->down(), n->down());
571 inner() = nextAtom()->hasInner();
575 void MathCursor::backspace()
578 nextAtom()->removeNucleus();
589 if (prevAtom()->hasInner()) {
600 void MathCursor::erase()
610 // delete empty cells if necessary
611 if (array().empty()) {
614 par()->idxDelete(idx(), popit, removeit);
615 if (popit && popLeft() && removeit)
620 MathAtom * n = nextAtom();
630 if (!n->up() && !n->down()) {
648 void MathCursor::delLine()
657 if (par()->nrows() > 1)
658 par()->delRow(row());
662 bool MathCursor::up(bool sel)
671 // check whether we could move into a superscript on the right or on the left
672 if (prevAtom() && prevAtom()->up()) {
673 pushRight(prevAtom()->up());
677 if (nextAtom() && nextAtom()->up()) {
678 pushLeft(nextAtom()->up());
686 bool MathCursor::down(bool sel)
695 // check whether we could move into an subscript on the right or on the left
696 if (prevAtom() && prevAtom()->down()) {
697 pushRight(prevAtom()->down());
701 if (nextAtom() && nextAtom()->down()) {
702 pushLeft(nextAtom()->down());
710 bool MathCursor::toggleLimits()
712 MathAtom * t = prevAtom();
715 int old = t->limits();
716 t->limits(old < 0 ? 1 : -1);
717 return old != t->limits();
721 void MathCursor::setSize(MathStyles size)
723 par()->userSetSize(size);
727 void MathCursor::macroModeClose()
729 string s = macroName();
731 size_type old = pos();
733 array().erase(pos(), old);
739 int MathCursor::macroNamePos() const
741 for (int i = pos() - 1; i >= 0; --i) {
742 MathInset * p = array().at(i)->nucleus();
743 if (p && p->code() == LM_TC_TEX && p->getChar() == '\\')
750 string MathCursor::macroName() const
753 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
754 s += array().at(i)->nucleus()->getChar();
759 void MathCursor::selCopy()
763 theSelection.grab(*this);
769 void MathCursor::selCut()
773 theSelection.grab(*this);
774 theSelection.erase(*this);
777 theSelection.clear();
782 void MathCursor::selDel()
786 theSelection.erase(*this);
792 void MathCursor::selPaste()
795 theSelection.paste(*this);
800 void MathCursor::selHandle(bool sel)
802 if (sel == selection_)
805 theSelection.clear();
811 void MathCursor::selStart()
817 theSelection.clear();
823 void MathCursor::selClear()
830 void MathCursor::drawSelection(Painter & pain) const
837 getSelection(i1, i2);
839 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
841 if (i1.idx_ == i2.idx_) {
842 MathXArray & c = i1.xcell();
843 int x1 = c.xo() + c.pos2x(i1.pos_, i1.inner_);
844 int y1 = c.yo() - c.ascent();
845 int x2 = c.xo() + c.pos2x(i2.pos_, i2.inner_);
846 int y2 = c.yo() + c.descent();
847 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
849 std::vector<MathInset::idx_type> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
850 for (unsigned i = 0; i < indices.size(); ++i) {
851 MathXArray & c = i1.xcell(indices[i]);
853 int y1 = c.yo() - c.ascent();
854 int x2 = c.xo() + c.width();
855 int y2 = c.yo() + c.descent();
856 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
862 MathTextCodes MathCursor::nextCode() const
864 //return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
869 void MathCursor::handleFont(MathTextCodes t)
875 getSelection(i1, i2);
876 if (i1.idx_ == i2.idx_) {
877 MathArray & ar = i1.cell();
878 for (MathInset::pos_type pos = i1.pos_;
879 pos != i2.pos_; ++pos) {
880 MathInset * p = ar.at(pos)->nucleus();
886 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
890 void MathCursor::handleDelim(string const & l, string const & r)
892 handleNest(new MathDelimInset(l, r));
896 void MathCursor::handleNest(MathInset * p)
900 p->cell(0) = theSelection.glue();
902 insert(p); // this invalidates p!
903 p = prevAtom()->nucleus();
908 void MathCursor::getPos(int & x, int & y)
911 #warning This should probably take cellXOffset and cellYOffset into account
913 x = xarray().xo() + xarray().pos2x(pos(), inner());
918 MathInset * MathCursor::par() const
920 return cursor().par_;
924 InsetFormulaBase const * MathCursor::formula()
930 MathCursor::idx_type MathCursor::idx() const
932 return cursor().idx_;
936 MathCursor::idx_type & MathCursor::idx()
938 return cursor().idx_;
942 MathCursor::pos_type MathCursor::pos() const
944 return cursor().pos_;
948 MathCursor::pos_type & MathCursor::pos()
950 return cursor().pos_;
954 bool MathCursor::inner() const
956 return cursor().inner_;
960 bool & MathCursor::inner()
962 return cursor().inner_;
966 bool MathCursor::inMacroMode() const
968 return macroNamePos() != -1;
972 bool MathCursor::selection() const
978 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
980 for (int i = Cursor_.size() - 1; i >= 0; --i) {
981 if (Cursor_[i].par_->isArray()) {
982 idx = Cursor_[i].idx_;
983 return static_cast<MathArrayInset *>(Cursor_[i].par_);
990 void MathCursor::pullArg(bool goright)
993 MathArray a = array();
995 MathScriptInset const * p = par()->asScriptInset();
997 // special handling for scripts
998 const bool up = p->up();
1002 nextAtom()->removeUp();
1004 nextAtom()->removeDown();
1007 array().insert(pos(), a);
1013 array().insert(pos(), a);
1020 MathStyles MathCursor::style() const
1022 return xarray().style();
1026 void MathCursor::normalize() const
1028 #ifdef WITH_WARNINGS
1029 #warning This is evil!
1031 MathCursor * it = const_cast<MathCursor *>(this);
1033 if (idx() >= par()->nargs()) {
1034 lyxerr << "this should not really happen - 1: "
1035 << idx() << " " << par()->nargs() << "\n";
1038 it->idx() = min(idx(), par()->nargs() - 1);
1040 if (pos() > size()) {
1041 lyxerr << "this should not really happen - 2: "
1042 << pos() << " " << size() << "\n";
1045 it->pos() = min(pos(), size());
1049 MathCursor::size_type MathCursor::size() const
1051 return array().size();
1055 MathCursor::col_type MathCursor::col() const
1057 return par()->col(idx());
1061 MathCursor::row_type MathCursor::row() const
1063 return par()->row(idx());
1068 char MathCursorPos::getChar() const
1070 return array().getChar(pos());
1074 string MathCursorPos::readString()
1077 int code = nextCode();
1078 for ( ; OK() && nextCode() == code; Next())
1086 MathInset * MathCursor::prevInset() const
1088 return prevAtom() ? prevAtom()->nucleus() : 0;
1092 MathInset * MathCursor::nextInset() const
1094 return nextAtom() ? nextAtom()->nucleus() : 0;
1098 MathSpaceInset * MathCursor::prevSpaceInset() const
1100 MathInset * p = prevInset();
1101 return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
1105 MathAtom const * MathCursor::prevAtom() const
1107 return array().at(pos() - 1);
1111 MathAtom * MathCursor::prevAtom()
1113 return array().at(pos() - 1);
1117 MathAtom const * MathCursor::nextAtom() const
1119 return array().at(pos());
1123 MathAtom * MathCursor::nextAtom()
1125 return array().at(pos());
1129 MathArray & MathCursor::array() const
1131 static MathArray dummy;
1133 lyxerr << "############ par_ not valid\n";
1137 if (idx() >= par()->nargs()) {
1138 lyxerr << "############ idx_ " << idx() << " not valid\n";
1142 return cursor().cell();
1146 MathXArray & MathCursor::xarray() const
1148 return cursor().xcell();
1152 void MathCursor::idxNext()
1154 par()->idxNext(idx(), pos());
1158 void MathCursor::idxPrev()
1160 par()->idxPrev(idx(), pos());
1164 void MathCursor::splitCell()
1166 if (idx() == par()->nargs() - 1)
1168 MathArray ar = array();
1170 array().erase(pos(), size());
1173 array().insert(0, ar);
1177 void MathCursor::breakLine()
1179 // leave inner cells
1183 MathMatrixInset * p = outerPar();
1184 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1185 p->mutate(LM_OT_EQNARRAY);
1192 const row_type r = row();
1193 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1194 const MathMatrixInset::idx_type i1 = p->index(r, c);
1195 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1196 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1197 p->cell(i1).swap(p->cell(i2));
1202 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1207 char MathCursor::valign() const
1210 MathArrayInset * p = enclosingArray(idx);
1211 return p ? p->valign() : '\0';
1215 char MathCursor::halign() const
1218 MathArrayInset * p = enclosingArray(idx);
1219 return p ? p->halign(idx % p->ncols()) : '\0';
1223 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1225 MathCursorPos anc = normalAnchor();
1226 if (anc < cursor()) {
1236 MathCursorPos & MathCursor::cursor()
1238 return Cursor_.back();
1242 MathCursorPos const & MathCursor::cursor() const
1244 return Cursor_.back();
1248 int MathCursor::cellXOffset() const
1250 return par()->cellXOffset(idx());
1254 int MathCursor::cellYOffset() const
1256 return par()->cellYOffset(idx());
1260 int MathCursor::xpos() const
1262 return cellXOffset() + xarray().pos2x(pos(), inner());
1266 int MathCursor::ypos() const
1268 return cellYOffset();
1273 void MathCursor::gotoX(int x)
1275 pos() = xarray().x2pos(x - cellXOffset());
1279 bool MathCursor::goUp()
1281 // first ask the inset if it knows better then we
1282 if (par()->idxUp(idx(), pos()))
1285 // leave subscript to the nearest side
1286 if (par()->asScriptInset() && par()->asScriptInset()->down()) {
1287 if (pos() <= size() / 2)
1294 // if not, apply brute force.
1298 std::vector<MathCursorPos> save = Cursor_;
1299 y0 -= xarray().ascent();
1300 for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
1302 if (save != Cursor_ && xarray().yo() < y0)
1310 bool MathCursor::goDown()
1312 // first ask the inset if it knows better then we
1313 if (par()->idxDown(idx(), pos()))
1316 // leave superscript to the nearest side
1317 if (par()->asScriptInset() && par()->asScriptInset()->up()) {
1318 if (pos() <= size() / 2)
1325 // if not, apply brute force.
1329 std::vector<MathCursorPos> save = Cursor_;
1330 y0 += xarray().descent();
1331 for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
1333 if (save != Cursor_ && xarray().yo() > y0)
1341 bool MathCursor::idxLeft()
1343 return par()->idxLeft(idx(), pos());
1347 bool MathCursor::idxRight()
1349 return par()->idxRight(idx(), pos());
1353 MathMatrixInset * MathCursor::outerPar() const
1356 static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
1360 void MathCursor::interpret(string const & s)
1362 //lyxerr << "interpret 1: '" << s << "'\n";
1363 //lyxerr << "in: " << in_word_set(s) << " \n";
1368 if (s.size() == 1) {
1373 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1374 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1375 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1377 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1382 istringstream is(s.substr(7).c_str());
1383 is >> m >> n >> v_align >> h_align;
1384 m = std::max(1u, m);
1385 n = std::max(1u, n);
1387 MathArrayInset * p = new MathArrayInset(m, n);
1388 p->valign(v_align[0]);
1394 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1395 MathArray ar = array();
1396 MathInset * p = createMathInset(s.substr(1));
1397 p->cell(0).swap(array());
1405 niceInsert(createMathInset(s.substr(1)));
1409 void MathCursor::interpret(char c)
1411 //lyxerr << "interpret 2: '" << c << "'\n";
1413 if (inMacroMode()) {
1414 string name = macroName();
1416 if (name == "\\" && c == '#') {
1417 insert(c, LM_TC_TEX);
1421 if (name == "\\" && c == '\\') {
1423 interpret("\\backslash");
1427 if (name == "\\#" && '1' <= c && c <= '9') {
1428 insert(c, LM_TC_TEX);
1434 insert(c, LM_TC_TEX);
1439 insert(c, LM_TC_TEX);
1449 if (c == '^' || c == '_') {
1450 const bool up = (c == '^');
1451 const bool in = inner();
1457 MathInset * par = prevAtom()->ensure(up);
1469 if (lastcode_ == LM_TC_TEXTRM) {
1470 insert(c, LM_TC_TEXTRM);
1475 MathSpaceInset * p = prevSpaceInset();
1481 if (mathcursor->popRight())
1485 // this would not work if the inset is in an table!
1486 //bv->text->cursorRight(bv, true);
1487 //result = FINISHED;
1491 if (strchr("{}", c)) {
1492 insert(c, LM_TC_TEX);
1496 if (strchr("#$%", c)) {
1497 insert(new MathSpecialCharInset(c));
1498 lastcode_ = LM_TC_VAR;
1502 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1503 static char const greekl[][26] =
1504 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1505 "gamma", "eta", "iota", "iota", "kappa", "lambda", "mu",
1506 "nu", "omikron", "pi", "omega", "rho", "sigma",
1507 "tau", "upsilon", "theta", "omega", "xi", "upsilon", "zeta"};
1508 static char const greeku[][26] =
1509 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1510 "Gamma", "Eta", "Iota", "Iota", "Kappa", "Lambda", "Mu",
1511 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1512 "Upsilon", "Theta", "Omega", "xi", "Upsilon", "Zeta"};
1514 latexkeys const * l = 0;
1515 if ('a' <= c && c <= 'z')
1516 l = in_word_set(greekl[c - 'a']);
1517 if ('A' <= c && c <= 'Z')
1518 l = in_word_set(greeku[c - 'A']);
1521 insert(createMathInset(l));
1523 insert(c, LM_TC_VAR);
1525 #warning greek insert problem? look here!
1526 if (lastcode_ == LM_TC_GREEK1)
1527 lastcode_ = LM_TC_VAR;
1532 insert(c, LM_TC_TEX);
1533 //bv->owner()->message(_("TeX mode"));
1537 // no special circumstances, so insert the character without any fuss
1538 insert(c, LM_TC_MIN);
1543 ////////////////////////////////////////////////////////////////////////
1546 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1548 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1552 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1554 if (ti.par_ != it.par_) {
1555 lyxerr << "can't compare cursor and anchor in different insets\n";
1558 if (ti.idx_ != it.idx_)
1559 return ti.idx_ < it.idx_;
1560 return ti.pos_ < it.pos_;
1564 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1566 return par_->cell(idx);
1570 MathArray & MathCursorPos::cell() const
1572 return par_->cell(idx_);
1576 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1578 return par_->xcell(idx);
1582 MathXArray & MathCursorPos::xcell() const
1584 return par_->xcell(idx_);
1588 MathAtom * MathCursorPos::at() const
1590 return cell().at(pos_);
1594 MathCursorPos MathCursor::normalAnchor() const
1596 // use Anchor on the same level as Cursor
1597 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1598 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1599 // anchor is behind cursor -> move anchor behind the inset