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)
160 // nextInset()->removeEmptyScripts();
163 // nextAtom()->removeEmptyScripts();
168 bool MathCursor::popRight()
170 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
171 if (Cursor_.size() <= 1)
174 // nextInset()->removeEmptyScripts();
177 // nextInset()->removeEmptyScripts();
185 void MathCursor::dump(char const * what) const
187 lyxerr << "MC: " << what << "\n";
188 lyxerr << " Cursor: " << Cursor_.size() << "\n";
189 for (unsigned i = 0; i < Cursor_.size(); ++i)
190 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
191 lyxerr << " Anchor: " << Anchor_.size() << "\n";
192 for (unsigned i = 0; i < Anchor_.size(); ++i)
193 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
194 lyxerr << " sel: " << selection_ << "\n";
197 void MathCursor::dump(char const *) const {}
201 UpdatableInset * MathCursor::asHyperActiveInset() const
203 return par()->asHyperActiveInset();
207 bool MathCursor::isInside(MathInset const * p) const
209 for (unsigned i = 0; i < Cursor_.size(); ++i)
210 if (Cursor_[i].par_ == p)
216 bool MathCursor::openable(MathAtom const & t, bool sel) const
218 if (t->isHyperActive())
224 if (t->asScriptInset())
228 // we can't move into anything new during selection
229 if (Cursor_.size() == Anchor_.size())
231 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
238 bool MathCursor::posLeft()
247 bool MathCursor::posRight()
256 bool MathCursor::left(bool sel)
261 lastcode_ = LM_TC_VAR;
265 lastcode_ = LM_TC_VAR;
267 if (hasPrevAtom() && openable(prevAtom(), sel)) {
268 if (prevAtom()->isHyperActive()) {
269 lyxerr << "entering hyperactive inset\n";
271 pushRight(prevAtom());
275 return posLeft() || idxLeft() || popLeft() || selection_;
279 bool MathCursor::right(bool sel)
284 lastcode_ = LM_TC_VAR;
288 lastcode_ = LM_TC_VAR;
290 if (hasNextAtom() && openable(nextAtom(), sel)) {
291 if (nextAtom()->isHyperActive()) {
292 lyxerr << "entering hyperactive inset\n";
295 nextAtom()->edit(formula()->view(), x, y, 0);
297 pushLeft(nextAtom());
301 return posRight() || idxRight() || popRight() || selection_;
305 void MathCursor::first()
308 pushLeft(formula_->par());
312 void MathCursor::last()
320 void MathCursor::setPos(int x, int y)
323 cursor_type best_cursor;
324 double best_dist = 1e10;
326 MathIterator it = ibegin(formula()->par().nucleus());
327 MathIterator et = iend(formula()->par().nucleus());
328 for ( ; it != et; ++it) {
329 //lyxerr << "*it: " << *it << " *et: " << *et << "\n";
331 // avoid deeper nested insets when selecting
332 if (it.cursor().size() > Anchor_.size())
334 // anchor might be deeper!
335 if (it.cursor().size() == Anchor_.size())
336 if (it.par() != Anchor_.back().par_)
338 //if (it.par() != Anchor_[it.cursor().size()].par_)
341 //lyxerr << it.position() << endl;
342 int xo = it.position().xpos();
343 int yo = it.position().ypos();
344 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
347 best_cursor = it.cursor();
350 if (best_dist < 1e10)
351 Cursor_ = best_cursor;
352 //lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n";
353 lyx::Assert(Cursor_.size());
359 void MathCursor::home(bool sel)
364 lastcode_ = LM_TC_VAR;
365 if (!par()->idxHome(idx(), pos()))
371 void MathCursor::end(bool sel)
376 lastcode_ = LM_TC_VAR;
377 if (!par()->idxEnd(idx(), pos()))
383 void MathCursor::plainErase()
385 array().erase(pos());
389 void MathCursor::plainInsert(MathAtom const & t)
391 array().insert(pos(), t);
396 void MathCursor::insert(char c, MathTextCodes t)
398 //lyxerr << "inserting '" << c << "'\n";
399 plainInsert(MathAtom(new MathCharInset(c, t)));
403 void MathCursor::insert(MathAtom const & t)
418 void MathCursor::niceInsert(MathAtom const & t)
421 insert(t); // inserting invalidates the pointer!
422 MathAtom const & p = prevAtom();
425 right(); // do not push for e.g. MathSymbolInset
431 void MathCursor::insert(MathArray const & ar)
437 array().insert(pos(), ar);
442 void MathCursor::paste(MathArray const & ar)
446 array().insert(pos(), ar);
451 void MathCursor::backspace()
463 MathScriptInset * p = prevAtom()->asScriptInset();
465 p->removeScript(p->hasUp());
466 // Don't delete if there is anything left
467 if (p->hasUp() || p->hasDown())
476 void MathCursor::erase()
486 // delete empty cells if necessary
487 if (array().empty()) {
490 par()->idxDelete(idx(), popit, removeit);
491 if (popit && popLeft() && removeit)
499 MathScriptInset * p = nextAtom()->asScriptInset();
501 p->removeScript(p->hasUp());
502 // Don't delete if there is anything left
503 if (p->hasUp() || p->hasDown())
511 void MathCursor::delLine()
520 if (par()->nrows() > 1) {
521 // grid are the only things with more than one row...
522 lyx::Assert(par()->asGridInset());
523 par()->asGridInset()->delRow(hullRow());
526 if (idx() > par()->nargs())
527 idx() = par()->nargs();
534 bool MathCursor::up(bool sel)
541 MathInset::idx_type i = 0;
542 MathInset::pos_type p = 0;
544 // check whether we could move into the inset
545 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
546 pushRight(prevAtom());
552 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
553 pushLeft(nextAtom());
560 return goUp() || selection_;
564 bool MathCursor::down(bool sel)
571 MathInset::idx_type i = 0;
572 MathInset::pos_type p = 0;
574 // check whether we could move into the inset
575 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
576 pushRight(prevAtom());
582 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
583 pushLeft(nextAtom());
590 return goDown() || selection_;
594 bool MathCursor::toggleLimits()
598 MathScriptInset * t = nextAtom()->asScriptInset();
601 int old = t->limits();
602 t->limits(old < 0 ? 1 : -1);
603 return old != t->limits();
607 void MathCursor::macroModeClose()
609 string s = macroName();
611 size_type old = pos();
613 array().erase(pos(), old);
619 int MathCursor::macroNamePos() const
621 for (int i = pos() - 1; i >= 0; --i) {
622 MathAtom & p = array().at(i);
623 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
630 string MathCursor::macroName() const
633 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
634 s += array().at(i)->getChar();
639 void MathCursor::selCopy()
643 theSelection.grab(*this);
649 void MathCursor::selCut()
653 theSelection.grab(*this);
654 theSelection.erase(*this);
657 theSelection.clear();
662 void MathCursor::selDel()
666 theSelection.erase(*this);
674 void MathCursor::selPaste()
677 theSelection.paste(*this);
678 //theSelection.grab(*this);
683 void MathCursor::selHandle(bool sel)
685 if (sel == selection_)
687 //theSelection.clear();
693 void MathCursor::selStart()
696 //theSelection.clear();
703 void MathCursor::selClear()
711 void MathCursor::selGet(MathArray & ar)
717 theSelection.grab(*this);
718 ar = theSelection.glue();
723 void MathCursor::drawSelection(Painter & pain) const
730 getSelection(i1, i2);
732 if (i1.idx_ == i2.idx_) {
733 MathXArray & c = i1.xcell();
734 int x1 = c.xo() + c.pos2x(i1.pos_);
735 int y1 = c.yo() - c.ascent();
736 int x2 = c.xo() + c.pos2x(i2.pos_);
737 int y2 = c.yo() + c.descent();
738 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
740 std::vector<MathInset::idx_type> indices
741 = i1.par_->idxBetween(i1.idx_, i2.idx_);
742 for (unsigned i = 0; i < indices.size(); ++i) {
743 MathXArray & c = i1.xcell(indices[i]);
745 int y1 = c.yo() - c.ascent();
746 int x2 = c.xo() + c.width();
747 int y2 = c.yo() + c.descent();
748 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
753 // draw anchor if different from selection boundary
754 MathCursorPos anc = Anchor_.back();
755 if (anc != i1 && anc != i2) {
756 MathXArray & c = anc.xcell();
757 int x = c.xo() + c.pos2x(anc.pos_);
758 int y1 = c.yo() - c.ascent();
759 int y2 = c.yo() + c.descent();
760 pain.line(x, y1, x, y2, LColor::math);
766 void MathCursor::handleFont(MathTextCodes t)
772 getSelection(i1, i2);
773 if (i1.idx_ == i2.idx_) {
774 MathArray & ar = i1.cell();
775 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
776 ar.at(pos)->handleFont(t);
779 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
783 void MathCursor::handleDelim(string const & l, string const & r)
785 handleNest(new MathDelimInset(l, r));
789 void MathCursor::handleNest(MathInset * p)
793 p->cell(0) = theSelection.glue();
795 insert(MathAtom(p)); // this invalidates p!
796 pushRight(prevAtom());
800 void MathCursor::getPos(int & x, int & y)
803 #warning This should probably take cellXOffset and cellYOffset into account
805 x = xarray().xo() + xarray().pos2x(pos());
810 MathInset * MathCursor::par() const
812 return cursor().par_;
816 InsetFormulaBase * MathCursor::formula()
822 MathCursor::idx_type MathCursor::idx() const
824 return cursor().idx_;
828 MathCursor::idx_type & MathCursor::idx()
830 return cursor().idx_;
834 MathCursor::pos_type MathCursor::pos() const
836 return cursor().pos_;
840 MathCursor::pos_type & MathCursor::pos()
842 return cursor().pos_;
846 bool MathCursor::inMacroMode() const
848 return macroNamePos() != -1;
852 bool MathCursor::selection() const
858 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
860 for (int i = Cursor_.size() - 1; i >= 0; --i) {
861 MathGridInset * p = Cursor_[i].par_->asGridInset();
863 idx = Cursor_[i].idx_;
871 void MathCursor::pullArg(bool goright)
874 MathArray a = array();
876 MathScriptInset const * p = par()->asScriptInset();
878 // special handling for scripts
879 const bool up = p->hasUp();
881 MathScriptInset * q = nextAtom()->asScriptInset();
885 array().insert(pos(), a);
891 array().insert(pos(), a);
898 void MathCursor::normalize() const
901 #warning This is evil!
903 MathCursor * it = const_cast<MathCursor *>(this);
905 if (idx() >= par()->nargs()) {
906 lyxerr << "this should not really happen - 1: "
907 << idx() << " " << par()->nargs() << "\n";
910 it->idx() = min(idx(), par()->nargs() - 1);
912 if (pos() > size()) {
913 lyxerr << "this should not really happen - 2: "
914 << pos() << " " << size() << " in idx: " << it->idx()
916 WriteStream wi(lyxerr, false);
917 it->par()->write(wi);
921 it->pos() = min(pos(), size());
925 MathCursor::size_type MathCursor::size() const
927 return array().size();
931 MathCursor::col_type MathCursor::hullCol() const
933 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
937 MathCursor::row_type MathCursor::hullRow() const
939 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
943 bool MathCursor::hasPrevAtom() const
949 bool MathCursor::hasNextAtom() const
951 return pos() < size();
955 MathAtom const & MathCursor::prevAtom() const
957 lyx::Assert(pos() > 0);
958 return array().at(pos() - 1);
962 MathAtom & MathCursor::prevAtom()
964 lyx::Assert(pos() > 0);
965 return array().at(pos() - 1);
969 MathAtom const & MathCursor::nextAtom() const
971 lyx::Assert(pos() < size());
972 return array().at(pos());
976 MathAtom & MathCursor::nextAtom()
978 lyx::Assert(pos() < size());
979 return array().at(pos());
983 MathArray & MathCursor::array() const
985 static MathArray dummy;
987 if (idx() >= par()->nargs()) {
988 lyxerr << "############ idx_ " << idx() << " not valid\n";
992 if (Cursor_.size() == 0) {
993 lyxerr << "############ Cursor_.size() == 0 not valid\n";
997 return cursor().cell();
1001 MathXArray & MathCursor::xarray() const
1003 static MathXArray dummy;
1005 if (Cursor_.size() == 0) {
1006 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1010 return cursor().xcell();
1014 void MathCursor::idxNext()
1016 par()->idxNext(idx(), pos());
1020 void MathCursor::idxPrev()
1022 par()->idxPrev(idx(), pos());
1026 void MathCursor::splitCell()
1028 if (idx() + 1 == par()->nargs())
1030 MathArray ar = array();
1032 array().erase(pos(), size());
1035 array().insert(0, ar);
1039 void MathCursor::breakLine()
1041 // leave inner cells
1045 MathHullInset * p = formula()->par()->asHullInset();
1049 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1050 p->mutate(LM_OT_EQNARRAY);
1054 p->addRow(hullRow());
1057 const row_type r = hullRow();
1058 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1059 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1063 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1068 //void MathCursor::readLine(MathArray & ar) const
1070 // idx_type base = row() * par()->ncols();
1071 // for (idx_type off = 0; off < par()->ncols(); ++off)
1072 // ar.push_back(par()->cell(base + off));
1076 char MathCursor::valign() const
1079 MathGridInset * p = enclosingGrid(idx);
1080 return p ? p->valign() : '\0';
1084 char MathCursor::halign() const
1087 MathGridInset * p = enclosingGrid(idx);
1088 return p ? p->halign(idx % p->ncols()) : '\0';
1092 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1094 MathCursorPos anc = normalAnchor();
1095 if (anc < cursor()) {
1105 MathCursorPos & MathCursor::cursor()
1107 lyx::Assert(Cursor_.size());
1108 return Cursor_.back();
1112 MathCursorPos const & MathCursor::cursor() const
1114 lyx::Assert(Cursor_.size());
1115 return Cursor_.back();
1119 bool MathCursor::goUp()
1121 // first ask the inset if it knows better then we
1122 if (par()->idxUp(idx(), pos())) {
1123 //lyxerr << "ask cell\n";
1124 int xlow, xhigh, ylow, yhigh;
1125 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1126 bruteFind(xlow, xhigh, ylow, yhigh);
1130 // if not, apply brute force.
1131 //lyxerr << "brute force\n";
1137 xarray().yo() - 4 - xarray().ascent()
1142 bool MathCursor::goDown()
1144 // first ask the inset if it knows better then we
1145 if (par()->idxDown(idx(), pos())) {
1146 //lyxerr << "ask cell\n";
1147 int xlow, xhigh, ylow, yhigh;
1148 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1149 bruteFind(xlow, xhigh, ylow, yhigh);
1153 // if not, apply brute force.
1154 //lyxerr << "brute force\n";
1159 xarray().yo() + 4 + xarray().descent(),
1165 bool MathCursor::bruteFind(int xlow, int xhigh, int ylow, int yhigh)
1170 //lyxerr << "looking at range: "
1171 // << "[" << xlow << "..." << xhigh << "]"
1172 // << " x [" << ylow << "..." << yhigh << "]"
1173 // << " xo: " << x << " yo: " << y << "\n";
1175 cursor_type best_cursor;
1176 double best_dist = 1e10;
1178 MathIterator it = ibegin(formula()->par().nucleus());
1179 MathIterator et = iend(formula()->par().nucleus());
1180 for ( ; it != et; ++it) {
1181 int xo = it.position().xpos();
1182 int yo = it.position().ypos();
1183 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1184 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1185 if (d < best_dist) {
1187 best_cursor = it.cursor();
1191 if (best_dist < 1e10)
1192 Cursor_ = best_cursor;
1193 return best_dist < 1e10;
1197 bool MathCursor::idxLeft()
1199 return par()->idxLeft(idx(), pos());
1203 bool MathCursor::idxRight()
1205 return par()->idxRight(idx(), pos());
1209 bool MathCursor::interpret(string const & s)
1211 //lyxerr << "interpret 1: '" << s << "'\n";
1216 return interpret(s[0]);
1218 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1219 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1220 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1222 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1224 istringstream is(s.substr(5).c_str());
1226 n = std::max(1u, n);
1227 niceInsert(MathAtom(new MathCasesInset(n)));
1231 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1236 istringstream is(s.substr(6).c_str());
1237 is >> m >> n >> v_align >> h_align;
1238 m = std::max(1u, m);
1239 n = std::max(1u, n);
1241 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1245 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1247 istringstream is(s.substr(7).c_str());
1250 mathed_parse_cell(rep.from, from);
1251 mathed_parse_cell(rep.to, to);
1252 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1253 par()->replace(rep);
1257 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1258 MathArray ar = array();
1259 MathAtom t = createMathInset(s.substr(1));
1260 t->asNestInset()->cell(0).swap(array());
1268 latexkeys const * l = in_word_set(s.substr(1));
1269 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1270 lastcode_ = static_cast<MathTextCodes>(l->id);
1274 niceInsert(createMathInset(s.substr(1)));
1279 bool MathCursor::interpret(char c)
1281 //lyxerr << "interpret 2: '" << c << "'\n";
1282 if (c == '^' || c == '_') {
1284 const bool up = (c == '^');
1286 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1287 prevAtom()->asScriptInset()->ensure(up);
1288 pushRight(prevAtom());
1291 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1292 nextAtom()->asScriptInset()->ensure(up);
1293 pushLeft(nextAtom());
1297 plainInsert(MathAtom(new MathScriptInset(up)));
1298 prevAtom()->asScriptInset()->ensure(up);
1299 pushRight(prevAtom());
1310 if (inMacroMode()) {
1311 string name = macroName();
1313 if (name == "\\" && c == '#') {
1314 insert(c, LM_TC_TEX);
1318 if (name == "\\" && c == '\\') {
1320 interpret("\\backslash");
1324 if (name == "\\#" && '1' <= c && c <= '9') {
1325 insert(c, LM_TC_TEX);
1331 insert(c, LM_TC_TEX);
1336 insert(c, LM_TC_TEX);
1348 if (lastcode_ == LM_TC_TEXTRM) {
1349 // suppress direct insertion of to spaces in a row
1350 // the still allows typing '<space>a<space>' and deleting the 'a', but
1351 // it is better than nothing
1352 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1354 insert(c, LM_TC_TEXTRM);
1359 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1360 prevAtom()->asSpaceInset()->incSpace();
1364 if (mathcursor->popRight())
1367 // if are at the very end, leave the formula
1368 return pos() != size();
1372 if (strchr("{}", c)) {
1373 insert(c, LM_TC_TEX);
1379 niceInsert(MathAtom(new MathBraceInset));
1387 if (strchr("#$%", c)) {
1388 insert(MathAtom(new MathSpecialCharInset(c)));
1389 lastcode_ = LM_TC_VAR;
1393 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1394 insert(c, LM_TC_VAR);
1398 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1399 insert(c, LM_TC_VAR);
1400 lastcode_ = LM_TC_VAR;
1405 insert(c, LM_TC_TEX);
1406 //bv->owner()->message(_("TeX mode"));
1410 // no special circumstances, so insert the character without any fuss
1411 insert(c, lastcode_);
1412 lastcode_ = LM_TC_MIN;
1418 MathCursorPos MathCursor::normalAnchor() const
1420 lyx::Assert(Anchor_.size() >= Cursor_.size());
1421 // use Anchor on the same level as Cursor
1422 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1423 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1424 // anchor is behind cursor -> move anchor behind the inset
1431 void MathCursor::stripFromLastEqualSign()
1433 // find position of last '=' in the array
1434 MathArray & ar = cursor().cell();
1435 MathArray::const_iterator et = ar.end();
1436 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1437 if ((*it)->getChar() == '=')
1440 // delete everything behind this position
1441 ar.erase(et - ar.begin(), ar.size());