2 * \file math_nestinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_nestinset.h"
15 #include "math_arrayinset.h"
16 #include "math_boxinset.h"
17 #include "math_braceinset.h"
18 #include "math_commentinset.h"
19 #include "math_data.h"
20 #include "math_deliminset.h"
21 #include "math_factory.h"
22 #include "math_hullinset.h"
23 #include "math_mathmlstream.h"
24 #include "math_macroarg.h"
25 //#include "math_mboxinset.h"
26 #include "math_parser.h"
27 #include "math_scriptinset.h"
28 #include "math_spaceinset.h"
29 #include "math_symbolinset.h"
30 #include "math_support.h"
31 #include "math_unknowninset.h"
33 #include "BufferView.h"
34 #include "CutAndPaste.h"
35 #include "FuncStatus.h"
37 #include "bufferview_funcs.h"
38 #include "coordcache.h"
41 #include "dispatchresult.h"
42 #include "funcrequest.h"
44 #include "outputparams.h"
47 #include "support/lstrings.h"
49 #include "frontends/Dialogs.h"
50 #include "frontends/LyXView.h"
51 #include "frontends/Painter.h"
55 using lyx::cap::copySelection;
56 using lyx::cap::grabAndEraseSelection;
57 using lyx::cap::cutSelection;
58 using lyx::cap::pasteSelection;
59 using lyx::cap::replaceSelection;
60 using lyx::cap::selClearOrDel;
64 using std::istringstream;
67 MathNestInset::MathNestInset(idx_type nargs)
68 : cells_(nargs), lock_(false)
72 MathInset::idx_type MathNestInset::nargs() const
78 MathArray & MathNestInset::cell(idx_type i)
84 MathArray const & MathNestInset::cell(idx_type i) const
90 void MathNestInset::getCursorPos(CursorSlice const & sl,
91 int & x, int & y) const
93 // FIXME: This is a hack. Ideally, the coord cache should not store
94 // absolute positions, but relative ones. This would mean to call
95 // setXY() not in MathArray::draw(), but in the parent insets' draw()
96 // with the correctly adjusted x,y values. But this means that we'd have
97 // to touch all (math)inset's draw() methods. Right now, we'll store
98 // absolute value, and make them here relative, only to make them
99 // absolute again when actually drawing the cursor. What a mess.
100 BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
101 MathArray const & ar = sl.cell();
102 if (!theCoords.getArrays().has(&ar)) {
103 // this can (semi-)legally happen if we just created this cell
104 // and it never has been drawn before. So don't ASSERT.
105 //lyxerr << "no cached data for array " << &ar << endl;
110 Point const pt = theCoords.getArrays().xy(&ar);
111 if (!theCoords.getInsets().has(this)) {
113 //lyxerr << "no cached data for inset " << this << endl;
118 Point const pt2 = theCoords.getInsets().xy(this);
119 //lyxerr << "retrieving position cache for MathArray "
120 // << pt.x_ << ' ' << pt.y_ << std::endl;
121 x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
123 // lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
124 // << " asc: " << ascent() << " des: " << descent()
125 // << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl;
126 // move cursor visually into empty cells ("blue rectangles");
132 void MathNestInset::metrics(MetricsInfo const & mi) const
135 for (idx_type i = 0, n = nargs(); i != n; ++i)
140 bool MathNestInset::idxNext(LCursor & cur) const
142 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
143 if (cur.idx() == cur.lastidx())
151 bool MathNestInset::idxRight(LCursor & cur) const
157 bool MathNestInset::idxPrev(LCursor & cur) const
159 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
163 cur.pos() = cur.lastpos();
168 bool MathNestInset::idxLeft(LCursor & cur) const
174 bool MathNestInset::idxFirst(LCursor & cur) const
176 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
185 bool MathNestInset::idxLast(LCursor & cur) const
187 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
190 cur.idx() = cur.lastidx();
191 cur.pos() = cur.lastpos();
196 void MathNestInset::dump() const
198 WriteStream os(lyxerr);
199 os << "---------------------------------------------\n";
202 for (idx_type i = 0, n = nargs(); i != n; ++i)
203 os << cell(i) << "\n";
204 os << "---------------------------------------------\n";
208 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
212 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
215 setPosCache(pi, x, y);
219 void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
221 // FIXME: hack to get position cache warm
224 // this should use the x/y values given, not the cached values
225 LCursor & cur = pi.base.bv->cursor();
226 if (!cur.selection())
228 if (!ptr_cmp(&cur.inset(), this))
231 CursorSlice s1 = cur.selBegin();
232 CursorSlice s2 = cur.selEnd();
233 //lyxerr << "MathNestInset::drawing selection: "
234 // << " s1: " << s1 << " s2: " << s2 << endl;
235 if (s1.idx() == s2.idx()) {
236 MathArray const & c = cell(s1.idx());
237 int x1 = c.xo() + c.pos2x(s1.pos());
238 int y1 = c.yo() - c.ascent();
239 int x2 = c.xo() + c.pos2x(s2.pos());
240 int y2 = c.yo() + c.descent();
241 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
242 //lyxerr << "MathNestInset::drawing selection 3: "
243 // << " x1: " << x1 << " x2: " << x2
244 // << " y1: " << y1 << " y2: " << y2 << endl;
246 for (idx_type i = 0; i < nargs(); ++i) {
247 if (idxBetween(i, s1.idx(), s2.idx())) {
248 MathArray const & c = cell(i);
250 int y1 = c.yo() - c.ascent();
251 int x2 = c.xo() + c.width();
252 int y2 = c.yo() + c.descent();
253 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
260 void MathNestInset::validate(LaTeXFeatures & features) const
262 for (idx_type i = 0; i < nargs(); ++i)
263 cell(i).validate(features);
267 void MathNestInset::replace(ReplaceData & rep)
269 for (idx_type i = 0; i < nargs(); ++i)
270 cell(i).replace(rep);
274 bool MathNestInset::contains(MathArray const & ar) const
276 for (idx_type i = 0; i < nargs(); ++i)
277 if (cell(i).contains(ar))
283 bool MathNestInset::lock() const
289 void MathNestInset::lock(bool l)
295 bool MathNestInset::isActive() const
301 MathArray MathNestInset::glue() const
304 for (size_t i = 0; i < nargs(); ++i)
310 void MathNestInset::write(WriteStream & os) const
312 os << '\\' << name().c_str();
313 for (size_t i = 0; i < nargs(); ++i)
314 os << '{' << cell(i) << '}';
316 os.pendingSpace(true);
317 if (lock_ && !os.latex()) {
319 os.pendingSpace(true);
324 void MathNestInset::normalize(NormalStream & os) const
326 os << '[' << name().c_str();
327 for (size_t i = 0; i < nargs(); ++i)
328 os << ' ' << cell(i);
333 int MathNestInset::latex(Buffer const &, std::ostream & os,
334 OutputParams const & runparams) const
336 WriteStream wi(os, runparams.moving_arg, true);
342 void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/)
348 MathArray & ar = cur.cell();
349 // remove base-only "scripts"
350 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
351 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
352 if (p && p->nargs() == 1) {
353 MathArray ar = p->nuc();
356 cur.adjust(i, ar.size() - 1);
360 // glue adjacent font insets of the same kind
361 for (pos_type i = 0; i + 1 < size(); ++i) {
362 MathFontInset * p = operator[](i).nucleus()->asFontInset();
363 MathFontInset const * q = operator[](i + 1)->asFontInset();
364 if (p && q && p->name() == q->name()) {
365 p->cell(0).append(q->cell(0));
374 void MathNestInset::handleFont
375 (LCursor & cur, string const & arg, string const & font)
377 // this whole function is a hack and won't work for incremental font
379 recordUndo(cur, Undo::ATOMIC);
381 if (cur.inset().asMathInset()->name() == font)
382 cur.handleFont(font);
384 cur.handleNest(createMathInset(font));
390 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
392 recordUndo(cur, Undo::ATOMIC);
395 bv_funcs::string2font(arg, font, b);
396 if (font.color() != LColor::inherit) {
397 MathAtom at = createMathInset("color");
398 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
399 cur.handleNest(at, 1);
404 void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
406 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
407 //CursorSlice sl = cur.current();
409 switch (cmd.action) {
413 cur.message(_("Paste"));
414 replaceSelection(cur);
416 istringstream is(cmd.argument);
418 pasteSelection(cur, n);
419 cur.clearSelection(); // bug 393
420 cur.bv().switchKeyMap();
426 cutSelection(cur, true, true);
427 cur.message(_("Cut"));
432 cur.message(_("Copy"));
435 case LFUN_MOUSE_PRESS:
436 lfunMousePress(cur, cmd);
439 case LFUN_MOUSE_MOTION:
440 lfunMouseMotion(cur, cmd);
443 case LFUN_MOUSE_RELEASE:
444 lfunMouseRelease(cur, cmd);
447 case LFUN_FINISHED_LEFT:
448 cur.bv().cursor() = cur;
451 case LFUN_FINISHED_RIGHT:
453 cur.bv().cursor() = cur;
456 case LFUN_FINISHED_UP:
457 cur.bv().cursor() = cur;
460 case LFUN_FINISHED_DOWN:
461 cur.bv().cursor() = cur;
466 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
467 cur.autocorrect() = false;
469 cur.macroModeClose();
470 if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
471 cur.pushLeft(*cur.nextAtom().nucleus());
472 cur.inset().idxFirst(cur);
473 } else if (cur.posRight() || idxRight(cur)
474 || cur.popRight() || cur.selection())
477 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
482 cur.selHandle(cmd.action == LFUN_LEFTSEL);
483 cur.autocorrect() = false;
485 cur.macroModeClose();
486 if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
488 cur.push(*cur.nextAtom().nucleus());
489 cur.inset().idxLast(cur);
490 } else if (cur.posLeft() || idxLeft(cur)
491 || cur.popLeft() || cur.selection())
494 cmd = FuncRequest(LFUN_FINISHED_LEFT);
499 cur.selHandle(cmd.action == LFUN_UPSEL);
501 cmd = FuncRequest(LFUN_FINISHED_UP);
502 // fixes bug 1598. Please check!
508 cur.selHandle(cmd.action == LFUN_DOWNSEL);
510 cmd = FuncRequest(LFUN_FINISHED_DOWN);
511 // fixes bug 1598. Please check!
515 case LFUN_MOUSE_DOUBLE:
516 case LFUN_MOUSE_TRIPLE:
521 cur.selection() = true;
522 cur.pos() = cur.lastpos();
523 cur.idx() = cur.lastidx();
526 case LFUN_UP_PARAGRAPHSEL:
527 case LFUN_UP_PARAGRAPH:
528 case LFUN_DOWN_PARAGRAPHSEL:
529 case LFUN_DOWN_PARAGRAPH:
534 case LFUN_WORDLEFTSEL:
536 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
537 cur.macroModeClose();
538 if (cur.pos() != 0) {
540 } else if (cur.col() != 0) {
541 cur.idx() -= cur.col();
543 } else if (cur.idx() != 0) {
547 cmd = FuncRequest(LFUN_FINISHED_LEFT);
551 case LFUN_WORDRIGHTSEL:
555 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
556 cur.macroModeClose();
558 if (cur.pos() != cur.lastpos()) {
559 cur.pos() = cur.lastpos();
560 } else if (ncols() && (cur.col() != cur.lastcol())) {
561 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
562 cur.pos() = cur.lastpos();
563 } else if (cur.idx() != cur.lastidx()) {
564 cur.idx() = cur.lastidx();
565 cur.pos() = cur.lastpos();
567 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
573 cmd = FuncRequest(LFUN_FINISHED_LEFT);
578 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
581 case LFUN_CELL_FORWARD:
582 cur.inset().idxNext(cur);
585 case LFUN_CELL_BACKWARD:
586 cur.inset().idxPrev(cur);
589 case LFUN_DELETE_WORD_BACKWARD:
591 recordUndo(cur, Undo::ATOMIC);
595 case LFUN_DELETE_WORD_FORWARD:
599 cmd = FuncRequest(LFUN_FINISHED_LEFT);
604 cur.clearSelection();
606 cmd = FuncRequest(LFUN_FINISHED_LEFT);
609 case LFUN_INSET_TOGGLE:
612 if (cur.pos() != cur.lastpos()) {
613 // toggle previous inset ...
614 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
615 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
616 // ... or enclosing inset if we are in the last inset position
617 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
622 case LFUN_SELFINSERT:
624 if (cmd.argument.size() != 1) {
625 cur.insert(cmd.argument);
628 if (!interpret(cur, cmd.argument[0]))
629 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
633 // sprintf(dispatch_buffer, "%d %d",);
637 lyxerr << "LFUN_SETXY broken!" << endl;
640 istringstream is(cmd.argument);
642 cur.setScreenPos(x, y);
646 // Special casing for superscript in case of LyX handling
648 case LFUN_CIRCUMFLEX:
649 if (cmd.argument.empty()) {
650 // do superscript if LyX handles
652 recordUndo(cur, Undo::ATOMIC);
670 case LFUN_HUNG_UMLAUT:
674 case LFUN_FREEFONT_APPLY:
675 case LFUN_FREEFONT_UPDATE:
676 handleFont2(cur, cmd.argument);
680 handleFont(cur, cmd.argument, "mathbf");
683 handleFont(cur, cmd.argument, "mathsf");
686 handleFont(cur, cmd.argument, "mathcal");
689 handleFont(cur, cmd.argument, "mathrm");
692 handleFont(cur, cmd.argument, "texttt");
695 handleFont(cur, cmd.argument, "mathfrak");
698 handleFont(cur, cmd.argument, "mathit");
701 handleFont(cur, cmd.argument, "mathbb");
703 //case LFUN_FREEFONT_APPLY:
704 handleFont(cur, cmd.argument, "textrm");
707 handleFont(cur, cmd.argument, "textnormal");
712 // ignore math-mode on when already in math mode
713 if (currentMode() == InsetBase::MATH_MODE && cmd.argument == "on")
715 cur.macroModeClose();
717 //cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
718 cur.plainInsert(MathAtom(new MathBoxInset("mbox")));
720 cur.pushLeft(*cur.nextInset());
722 if (currentMode() == InsetBase::TEXT_MODE) {
723 cur.niceInsert(MathAtom(new MathHullInset("simple")));
724 cur.message(_("create new math text environment ($...$)"));
726 handleFont(cur, cmd.argument, "textrm");
727 cur.message(_("entered math text mode (textrm)"));
739 case LFUN_INSERT_MATRIX: {
740 recordUndo(cur, Undo::ATOMIC);
745 istringstream is(cmd.argument);
746 is >> m >> n >> v_align >> h_align;
753 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
757 case LFUN_MATH_DELIM: {
758 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
760 string rs = lyx::support::split(cmd.argument, ls, ' ');
761 // Reasonable default values
766 recordUndo(cur, Undo::ATOMIC);
767 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
771 case LFUN_SPACE_INSERT:
772 case LFUN_MATH_SPACE:
773 recordUndo(cur, Undo::ATOMIC);
774 cur.insert(MathAtom(new MathSpaceInset(",")));
778 // interpret this as if a backslash was typed
779 recordUndo(cur, Undo::ATOMIC);
780 interpret(cur, '\\');
784 // interpret this as if a _ was typed
785 recordUndo(cur, Undo::ATOMIC);
789 case LFUN_SUPERSCRIPT:
790 // interpret this as if a ^ was typed
791 recordUndo(cur, Undo::ATOMIC);
795 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
796 // handling such that "self-insert" works on "arbitrary stuff" too, and
797 // math-insert only handles special math things like "matrix".
798 case LFUN_INSERT_MATH: {
799 recordUndo(cur, Undo::ATOMIC);
801 asArray(cmd.argument, ar);
802 if (ar.size() == 1 && (ar[0].nucleus()->asNestInset())) {
803 cur.handleNest(ar[0]);
805 cur.niceInsert(cmd.argument);
809 case LFUN_DIALOG_SHOW_NEW_INSET: {
810 string const & name = cmd.argument;
815 data = tmp.createDialogStr(name);
818 cur.bv().owner()->getDialogs().show(name, data, 0);
822 case LFUN_INSET_APPLY: {
823 string const name = cmd.getArg(0);
824 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
827 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
828 base->dispatch(cur, fr);
832 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
841 MathDimInset::doDispatch(cur, cmd);
847 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
848 FuncStatus & flag) const
850 // the font related toggles
851 //string tc = "mathnormal";
853 switch (cmd.action) {
855 case LFUN_TABULAR_FEATURE:
856 // FIXME: check temporarily disabled
858 char align = mathcursor::valign();
863 if (cmd.argument.empty()) {
867 if (!contains("tcb", cmd.argument[0])) {
871 flag.setOnOff(cmd.argument[0] == align);
874 flag.setOnOff(tc == "mathbf");
877 flag.setOnOff(tc == "mathsf");
880 flag.setOnOff(tc == "mathcal");
883 flag.setOnOff(tc == "mathrm");
886 flag.setOnOff(tc == "mathtt");
889 flag.setOnOff(tc == "mathbb");
892 flag.setOnOff(tc == "mathnormal");
895 case LFUN_MATH_MUTATE:
896 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
897 flag.setOnOff(false);
900 // we just need to be in math mode to enable that
902 case LFUN_MATH_SPACE:
903 case LFUN_MATH_LIMITS:
904 case LFUN_MATH_NONUMBER:
905 case LFUN_MATH_NUMBER:
906 case LFUN_MATH_EXTERN:
918 void MathNestInset::edit(LCursor & cur, bool left)
921 cur.idx() = left ? 0 : cur.lastidx();
922 cur.pos() = left ? 0 : cur.lastpos();
924 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
928 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) const
931 int dist_min = 1000000;
932 for (idx_type i = 0; i < nargs(); ++i) {
933 int d = cell(i).dist(x, y);
939 MathArray const & ar = cell(idx_min);
940 cur.push(const_cast<MathNestInset&>(*this));
942 cur.pos() = ar.x2pos(x - ar.xo());
943 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
946 for (pos_type i = 0, n = ar.size(); i < n; ++i)
947 if (ar[i]->covers(x, y))
948 return ar[i].nucleus()->editXY(cur, x, y);
950 return const_cast<MathNestInset*>(this);
954 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
956 //lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
957 if (cmd.button() == mouse_button::button1) {
958 //lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
960 cur.bv().cursor() = cur;
963 if (cmd.button() == mouse_button::button2) {
964 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
969 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
971 // only select with button 1
972 if (cmd.button() == mouse_button::button1) {
973 LCursor & bvcur = cur.bv().cursor();
974 if (bvcur.anchor_.hasPart(cur)) {
975 //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
976 bvcur.setCursor(cur);
977 bvcur.selection() = true;
978 //lyxerr << "MOTION " << bvcur << endl;
987 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
989 //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
991 if (cmd.button() == mouse_button::button1) {
992 //cur.bv().stuffClipboard(cur.grabSelection());
996 if (cmd.button() == mouse_button::button2) {
998 asArray(cur.bv().getClipboard(), ar);
999 cur.clearSelection();
1000 cur.setScreenPos(cmd.x, cmd.y);
1006 if (cmd.button() == mouse_button::button3) {
1007 // try to dispatch to enclosed insets first
1008 cur.bv().owner()->getDialogs().show("mathpanel");
1016 bool MathNestInset::interpret(LCursor & cur, char c)
1018 lyxerr << "interpret 2: '" << c << "'" << endl;
1022 if (cur.inMacroMode()) {
1023 string name = cur.macroName();
1025 /// are we currently typing '#1' or '#2' or...?
1026 if (name == "\\#") {
1029 if (n >= 1 && n <= 9)
1030 cur.insert(new MathMacroArgument(n));
1035 cur.activeMacro()->setName(name + c);
1039 // handle 'special char' macros
1044 if (currentMode() == MathInset::TEXT_MODE)
1045 cur.niceInsert(createMathInset("textbackslash"));
1047 cur.niceInsert(createMathInset("backslash"));
1048 } else if (c == '{') {
1050 cur.niceInsert(MathAtom(new MathBraceInset));
1051 } else if (c == '%') {
1053 cur.niceInsert(MathAtom(new MathCommentInset));
1054 } else if (c == '#') {
1055 BOOST_ASSERT(cur.activeMacro());
1056 cur.activeMacro()->setName(name + c);
1059 cur.niceInsert(createMathInset(string(1, c)));
1064 // leave macro mode and try again if necessary
1065 cur.macroModeClose();
1067 cur.niceInsert(MathAtom(new MathBraceInset));
1073 // This is annoying as one has to press <space> far too often.
1077 // leave autocorrect mode if necessary
1078 if (autocorrect() && c == ' ') {
1079 autocorrect() = false;
1084 // just clear selection on pressing the space bar
1085 if (cur.selection() && c == ' ') {
1086 cur.selection() = false;
1093 //lyxerr << "starting with macro" << endl;
1094 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1099 if (currentMode() == MathInset::TEXT_MODE)
1105 if (currentMode() == MathInset::TEXT_MODE) {
1106 // insert spaces in text mode,
1107 // but suppress direct insertion of two spaces in a row
1108 // the still allows typing '<space>a<space>' and deleting the 'a', but
1109 // it is better than nothing...
1110 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1114 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1115 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1120 // if are at the very end, leave the formula
1121 return cur.pos() != cur.lastpos();
1134 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
1135 cur.niceInsert(createMathInset(string(1, c)));
1140 cur.niceInsert(createMathInset("sim"));
1144 // try auto-correction
1145 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1148 // no special circumstances, so insert the character without any fuss
1150 cur.autocorrect() = true;
1155 bool MathNestInset::script(LCursor & cur, bool up)
1157 // Hack to get \^ and \_ working
1158 lyxerr << "handling script: up: " << up << endl;
1159 if (cur.inMacroMode() && cur.macroName() == "\\") {
1161 cur.niceInsert(createMathInset("mathcircumflex"));
1163 interpret(cur, '_');
1167 cur.macroModeClose();
1168 string safe = grabAndEraseSelection(cur);
1169 if (asScriptInset() && cur.idx() == 0) {
1170 // we are in a nucleus of a script inset, move to _our_ script
1171 MathScriptInset * inset = asScriptInset();
1172 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1174 cur.idx() = inset->idxOfScript(up);
1176 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1178 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1180 cur.idx() = inset->idxOfScript(up);
1181 cur.pos() = cur.lastpos();
1183 // convert the thing to our left to a scriptinset or create a new
1184 // one if in the very first position of the array
1185 if (cur.pos() == 0) {
1186 lyxerr << "new scriptinset" << endl;
1187 cur.insert(new MathScriptInset(up));
1189 lyxerr << "converting prev atom " << endl;
1190 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1193 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1198 lyxerr << "pasting 1: safe:\n" << safe << endl;
1201 lyxerr << "pasting 2: safe:\n" << safe << endl;