3 * Purpose: Implementation of formula inset
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Allows the edition of math paragraphs inside Lyx.
8 * Copyright: 1996-1998 Alejandro Aguilar Sierra
10 * Version: 0.4, Lyx project.
12 * You are free to use and modify this code under the terms of
13 * the GNU General Public Licence version 2 or later.
22 #pragma implementation
26 #include "formulamacro.h"
27 #include "commandtags.h"
28 #include "math_cursor.h"
29 #include "math_parser.h"
30 #include "BufferView.h"
34 #include "LaTeXFeatures.h"
36 #include "support/LOstream.h"
40 #include "math_arrayinset.h"
41 #include "math_spaceinset.h"
42 #include "math_deliminset.h"
43 #include "support/lyxlib.h"
44 #include "mathed/support.h"
45 #include "undo_funcs.h"
51 extern char const * latex_special_chars;
53 int greek_kb_flag = 0;
54 extern char const * latex_mathenv[];
55 LyXFont * Math_Fonts = 0;
56 MathCursor * mathcursor = 0;
67 void mathed_init_fonts();
69 string nicelabel(string const & label)
71 return "(" + (label.empty() ? "#" : label) + ")";
74 void handleFont(BufferView * bv, MathTextCodes t)
76 if (mathcursor->Selection())
77 bv->lockedInsetStoreUndo(Undo::EDIT);
78 mathcursor->handleFont(t);
81 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
83 LyXText * lt = bv->getLyXText();
87 if (!bv->insertInset(new_inset)) {
91 new_inset->edit(bv, 0, 0, 0);
99 LyXFont WhichFont(short type, int size)
136 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
149 if (type == LM_TC_BSYM) {
162 case LM_ST_SCRIPTSCRIPT:
168 lyxerr << "Math Error: wrong font size: " << size << endl;
172 if (type != LM_TC_TEXTRM)
173 f.setColor(LColor::math);
181 void mathed_init_fonts()
183 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
186 for (int i = 0 ; i < 8 ; ++i) {
187 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
190 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
192 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
194 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
195 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
197 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
199 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
200 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
202 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
204 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
206 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
210 // returns the nearest enclosing matrix
211 MathArrayInset * matrixpar(int & idx)
215 static_cast<MathArrayInset *>
216 (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
223 InsetFormulaBase::InsetFormulaBase(MathInset * par)
228 InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
229 : UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
233 InsetFormulaBase::~InsetFormulaBase()
236 #warning leak this for a while...
242 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
247 void InsetFormulaBase::write(Buffer const *, ostream & os) const
252 int InsetFormulaBase::latex(Buffer const *, ostream & os,
253 bool fragile, bool spacing) const
255 return latex(os, fragile, spacing);
258 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
260 return ascii(os, spacing);
263 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
268 int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
275 // Check if uses AMS macros
276 void InsetFormulaBase::validate(LaTeXFeatures &) const
280 string const InsetFormulaBase::editMessage() const
282 return _("Math editor mode");
286 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
288 mathcursor = new MathCursor(this);
290 if (!bv->lockInset(this))
291 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
293 par_->Metrics(LM_ST_TEXT);
294 bv->updateInset(this, false);
306 void InsetFormulaBase::insetUnlock(BufferView * bv)
309 if (mathcursor->InMacroMode()) {
310 mathcursor->MacroModeClose();
316 bv->updateInset(this, false);
320 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
322 mathcursor->GetPos(x, y);
328 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
333 if (isCursorVisible())
334 bv->hideLockedInsetCursor();
338 mathcursor->GetPos(x, y);
342 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
343 int const asc = lyxfont::maxAscent(font);
344 int const desc = lyxfont::maxDescent(font);
346 bv->showLockedInsetCursor(x, y, asc, desc);
349 toggleCursorVisible();
353 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
355 if (!isCursorVisible()) {
359 mathcursor->GetPos(x, y);
362 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
363 int const asc = lyxfont::maxAscent(font);
364 int const desc = lyxfont::maxDescent(font);
365 bv->fitLockedInsetCursor(x, y, asc, desc);
367 toggleInsetCursor(bv);
372 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
374 if (isCursorVisible())
375 toggleInsetCursor(bv);
379 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
384 bv->updateInset(this, false);
388 vector<string> const InsetFormulaBase::getLabelList() const
390 return std::vector<string>();
394 void InsetFormulaBase::updateLocal(BufferView * bv)
396 par_->Metrics(LM_ST_TEXT);
397 bv->updateInset(this, true);
401 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
402 int x, int y, int /*button*/)
408 mathcursor->SetPos(x, y);
415 bv->updateInset(this, false);
420 void InsetFormulaBase::insetButtonPress(BufferView * bv,
421 int x, int y, int /*button*/)
426 if (mathcursor && mathcursor->Selection()) {
427 mathcursor->SelClear();
428 bv->updateInset(this, false);
433 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
434 int x, int y, int /*button*/)
436 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
439 mathcursor->SetPos(sel_x + par_->xo(), sel_y + par_->yo());
440 mathcursor->SelStart();
442 mathcursor->GetPos(sel_x, sel_y);
443 } else if (sel_flag) {
447 mathcursor->SetPos(x, y);
449 mathcursor->GetPos(x, y);
450 if (sel_x != x || sel_y != y)
451 bv->updateInset(this, false);
458 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
460 lyxerr[Debug::MATHED]
461 << "Used InsetFormulaBase::InsetKeyPress." << endl;
466 UpdatableInset::RESULT
467 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
470 //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
471 // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
472 // extern char *dispatch_result;
477 MathTextCodes varcode = LM_TC_MIN;
478 bool was_macro = mathcursor->InMacroMode();
480 bool was_selection = mathcursor->Selection();
481 RESULT result = DISPATCHED;
485 if (mathcursor->getLastCode() == LM_TC_TEX)
488 mathcursor->normalize();
492 // --- Cursor Movements ---------------------------------------------
495 sel = true; // fall through...
498 result = DISPATCH_RESULT(mathcursor->Right(sel));
504 sel = true; // fall through
507 result = DISPATCH_RESULT(mathcursor->Left(sel));
516 result = DISPATCH_RESULT(mathcursor->Up(sel));
525 result = DISPATCH_RESULT(mathcursor->Down(sel));
539 case LFUN_DELETE_LINE_FORWARD:
540 bv->lockedInsetStoreUndo(Undo::DELETE);
541 mathcursor->DelLine();
546 mathcursor->idxNext();
551 mathcursor->idxPrev();
556 bv->lockedInsetStoreUndo(Undo::EDIT);
557 mathcursor->splitCell();
562 if (!mathcursor->InMacroMode() && mathcursor->pos() == 0) {
563 bv->lockedInsetStoreUndo(Undo::DELETE);
564 mathcursor->pullArg();
565 bv->updateInset(this, true);
568 if (!mathcursor->Left())
573 bv->lockedInsetStoreUndo(Undo::DELETE);
574 mathcursor->Delete();
575 bv->updateInset(this, true);
579 // sprintf(dispatch_buffer, "%d %d",);
580 // dispatch_result = dispatch_buffer;
584 lyxerr << "LFUN_SETXY broken!\n";
589 istringstream is(arg.c_str());
592 mathcursor->SetPos(x1 + x, y1 + y);
597 // cursor selection ----------------------------
601 mathcursor->MacroModeClose();
602 bv->lockedInsetStoreUndo(Undo::INSERT);
603 mathcursor->SelPaste();
608 bv->lockedInsetStoreUndo(Undo::DELETE);
609 mathcursor->SelCut();
614 mathcursor->SelCopy();
619 case LFUN_WORDRIGHTSEL:
620 case LFUN_WORDLEFTSEL:
623 // --- accented characters ------------------------------
625 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
626 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
627 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
628 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
629 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
630 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
631 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
632 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
633 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
634 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
638 if (!greek_kb_flag) {
640 bv->owner()->message(_("Math greek mode on"));
646 case LFUN_GREEK_TOGGLE:
647 greek_kb_flag = greek_kb_flag ? 0 : 2;
649 bv->owner()->message(_("Math greek keyboard on"));
651 bv->owner()->message(_("Math greek keyboard off"));
655 case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
656 case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
657 case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
658 case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
659 case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
660 case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
663 handleFont(bv, LM_TC_TEXTRM);
664 //bv->owner()->message(_("math text mode toggled"));
669 if (!mathcursor->Selection()) {
670 mathcursor->handleFont(LM_TC_TEX);
671 //bv->owner()->message(_("TeX mode toggled"));
676 case LFUN_MATH_LIMITS:
677 bv->lockedInsetStoreUndo(Undo::INSERT);
678 if (mathcursor->toggleLimits())
684 bv->lockedInsetStoreUndo(Undo::INSERT);
685 latexkeys const * l = in_word_set(arg);
686 mathcursor->SetSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
691 case LFUN_INSERT_MATRIX:
693 bv->lockedInsetStoreUndo(Undo::INSERT);
694 mathcursor->Interpret("matrix " + arg);
699 case LFUN_INSERT_MATH:
701 bv->lockedInsetStoreUndo(Undo::INSERT);
702 mathcursor->Interpret(arg);
707 case LFUN_MATH_DELIM:
709 bv->lockedInsetStoreUndo(Undo::INSERT);
712 static const string vdelim("(){}[]./|");
713 lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
718 istringstream is(arg.c_str());
722 lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
723 lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
726 latexkeys const * l = in_word_set(lt);
729 } else if (vdelim.find(lt[0]) != string::npos)
733 latexkeys const * l = in_word_set(rt);
736 } else if (vdelim.find(rt[0]) != string::npos)
739 if (mathcursor->selection) {
740 MathDelimInset * p = new MathDelimInset(ilt, irt);
742 mathcursor->selArray(ar);
743 lyxerr << "selarray: " << ar << "\n";
745 mathcursor->insert(p);
747 mathcursor->insert(new MathDelimInset(ilt, irt));
753 case LFUN_PROTECTEDSPACE:
754 bv->lockedInsetStoreUndo(Undo::INSERT);
755 mathcursor->insert(new MathSpaceInset(1));
760 bv->owner()->message(_("Invalid action in math mode!"));
764 case LFUN_MATH_HALIGN:
766 bv->lockedInsetStoreUndo(Undo::INSERT);
767 lyxerr << "handling halign '" << arg << "'\n";
769 MathArrayInset * p = matrixpar(idx);
772 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
777 case LFUN_MATH_VALIGN:
779 bv->lockedInsetStoreUndo(Undo::INSERT);
780 lyxerr << "handling valign '" << arg << "'\n";
782 MathArrayInset * p = matrixpar(idx);
785 p->valign(arg.size() ? arg[0] : 'c');
790 case LFUN_MATH_ROW_INSERT:
792 bv->lockedInsetStoreUndo(Undo::INSERT);
794 MathArrayInset * p = matrixpar(idx);
795 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
798 p->addRow(p->row(idx));
803 case LFUN_MATH_ROW_DELETE:
805 bv->lockedInsetStoreUndo(Undo::INSERT);
807 MathArrayInset * p = matrixpar(idx);
808 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
811 p->delRow(p->row(idx));
816 case LFUN_MATH_COLUMN_INSERT:
818 bv->lockedInsetStoreUndo(Undo::INSERT);
820 MathArrayInset * p = matrixpar(idx);
823 p->addCol(p->col(idx));
828 case LFUN_MATH_COLUMN_DELETE:
830 bv->lockedInsetStoreUndo(Undo::INSERT);
832 MathArrayInset * p = matrixpar(idx);
835 p->delCol(p->col(idx));
840 case LFUN_EXEC_COMMAND:
841 result = UNDISPATCHED;
845 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
846 unsigned char c = arg[0];
847 lyxerr << "char: '" << c << "' int: " << int(c) << endl;
848 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
849 lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
850 bv->lockedInsetStoreUndo(Undo::INSERT);
852 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
854 mathcursor->setAccent(0);
857 if (c == 0) { // Dead key, do nothing
858 //lyxerr << "deadkey" << endl;
863 if (mathcursor->getLastCode() == LM_TC_TEX) {
864 mathcursor->MacroModeOpen();
865 mathcursor->clearLastCode();
867 } else if (!varcode) {
868 short f = mathcursor->getLastCode() ?
869 mathcursor->getLastCode() :
870 mathcursor->nextCode();
871 varcode = MathIsAlphaFont(f) ?
872 static_cast<MathTextCodes>(f) :
876 // lyxerr << "Varcode << vardoce;
877 MathTextCodes char_code = varcode;
880 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
881 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
882 'Y', 0, 0, 0, 0 , 'Z' };
884 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
885 char_code = LM_TC_RM;
888 char_code = LM_TC_SYMB;
891 mathcursor->insert(c, char_code);
893 if (greek_kb_flag && char_code == LM_TC_RM )
894 mathcursor->setLastCode(LM_TC_VAR);
898 if (greek_kb_flag < 2)
901 } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
902 mathcursor->insert(c, LM_TC_TEX);
904 mathcursor->insert('}', LM_TC_TEX);
907 mathcursor->clearLastCode();
908 // varcode = LM_TC_MIN;
909 } else if (c == '_' && varcode == LM_TC_TEX) {
910 mathcursor->insert(c, LM_TC_SPECIAL);
911 mathcursor->clearLastCode();
912 // varcode = LM_TC_MIN;
913 } else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
914 mathcursor->MacroModeOpen();
915 mathcursor->clearLastCode();
916 mathcursor->insert(c, LM_TC_MIN);
917 } else if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) {
918 MathTextCodes code = mathcursor->getLastCode();
919 if (code != LM_TC_TEXTRM)
921 mathcursor->insert(c, code);
922 } else if (strchr("+/-*<>=", c)) {
923 MathTextCodes code = mathcursor->getLastCode();
924 if (code != LM_TC_TEXTRM)
926 mathcursor->insert(c, code);
927 } else if (strchr(latex_special_chars, c) && c != '_') {
928 MathTextCodes code = mathcursor->getLastCode();
929 if (code != LM_TC_TEXTRM)
930 code = LM_TC_SPECIAL;
931 mathcursor->insert(c, code);
932 } else if (c == '_' || c == '^') {
936 mathcursor->Interpret(s);
937 } else if (c == ' ') {
939 short f = (mathcursor->getLastCode()) ?
940 mathcursor->getLastCode() :
941 mathcursor->nextCode();
942 varcode = MathIsAlphaFont(f) ?
943 static_cast<MathTextCodes>(f) :
947 if (varcode == LM_TC_TEXTRM) {
948 mathcursor->insert(c, LM_TC_TEXTRM);
949 } else if (was_macro) {
950 mathcursor->MacroModeClose();
952 if (!mathcursor->pop())
954 mathcursor->plainRight();
956 } else if (c == '\'' || c == '@') {
957 mathcursor->insert (c, LM_TC_VAR);
958 } else if (c == '\\') {
960 mathcursor->MacroModeClose();
961 bv->owner()->message(_("TeX mode"));
962 mathcursor->setLastCode(LM_TC_TEX);
965 } else if (action == LFUN_MATH_PANEL) {
966 result = UNDISPATCHED;
968 lyxerr << "Closed by action " << action << endl;
974 mathcursor->normalize();
976 if (mathcursor && was_macro != mathcursor->InMacroMode()
978 && action != LFUN_BACKSPACE)
984 if (mathcursor && (mathcursor->Selection() || was_selection))
985 toggleInsetSelection(bv);
987 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
988 result == UNDISPATCHED)
991 bv->unlockInset(this);
993 return result; // original version
998 /* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
1000 bool math_insert_greek(BufferView * bv, char c)
1002 if (!bv->available())
1010 if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
1011 int greek_kb_flag_save = greek_kb_flag;
1012 InsetFormula * new_inset = new InsetFormula();
1013 bv->beforeChange(bv->text);
1014 if (!bv->insertInset(new_inset)) {
1019 new_inset->edit(bv, 0, 0, 0);
1020 new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
1021 if (greek_kb_flag_save < 2) {
1022 bv->unlockInset(new_inset); // bv->theLockingInset());
1023 bv->text->cursorRight(bv, true);
1026 if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
1027 bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
1028 static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
1030 lyxerr << "Math error: attempt to write on a wrong "
1031 "class of inset." << endl;
1037 Inset::Code InsetFormulaBase::lyxCode() const
1039 return Inset::MATH_CODE;
1043 LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
1045 // We have already discussed what was here
1048 font.setLatex(LyXFont::OFF);
1053 MathInset * InsetFormulaBase::par() const
1059 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
1061 if (bv->available()) {
1062 // Feature "Read math inset from selection" disabled.
1063 // // use selection if available..
1065 // if (action == LFUN_MATH_IMPORT_SELECTION)
1068 // sel = bv->getLyXText()->selectionAsString(bv->buffer());
1071 // if (sel.empty()) {
1072 f = new InsetFormula;
1073 if (openNewInset(bv, f)) {
1074 // don't do that also for LFUN_MATH_MODE unless you want end up with
1075 // always changing to mathrm when opening an inlined inset
1076 // -- I really hate "LyXfunc overloading"...
1078 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
1079 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
1082 // f = new InsetFormula(sel);
1083 // bv->getLyXText()->cutSelection(bv);
1084 // openNewInset(bv, f);
1087 bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
1090 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
1092 mathDispatchCreation(bv, arg, true);
1095 void mathDispatchMathMode(BufferView * bv, string const & arg)
1097 mathDispatchCreation(bv, arg, false);
1100 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
1102 mathDispatchCreation(bv, arg, true);
1105 void mathDispatchMathMacro(BufferView * bv, string const & arg)
1107 if (bv->available()) {
1110 bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
1112 string const s1 = token(s, ' ', 1);
1113 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1114 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1119 void mathDispatchMathDelim(BufferView * bv, string const & arg)
1121 if (bv->available()) {
1122 if (openNewInset(bv, new InsetFormula))
1123 bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
1128 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
1130 if (bv->available()) {
1131 if (openNewInset(bv, new InsetFormula))
1132 bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
1136 void mathDispatchInsertMath(BufferView * bv, string const & arg)
1138 if (bv->available()) {
1139 if (arg.size() && arg[0] == '\\') {
1140 InsetFormula * f = new InsetFormula(arg);
1141 openNewInset(bv, f);
1143 mathDispatchMathMode(bv, arg);