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";
476 MathTextCodes varcode = LM_TC_MIN;
477 bool was_macro = mathcursor->InMacroMode();
479 bool was_selection = mathcursor->Selection();
480 RESULT result = DISPATCHED;
484 if (mathcursor->getLastCode() == LM_TC_TEX)
487 mathcursor->normalize();
491 // --- Cursor Movements ---------------------------------------------
494 sel = true; // fall through...
497 result = DISPATCH_RESULT(mathcursor->Right(sel));
503 sel = true; // fall through
506 result = DISPATCH_RESULT(mathcursor->Left(sel));
515 result = DISPATCH_RESULT(mathcursor->Up(sel));
524 result = DISPATCH_RESULT(mathcursor->Down(sel));
538 case LFUN_DELETE_LINE_FORWARD:
539 bv->lockedInsetStoreUndo(Undo::DELETE);
540 mathcursor->DelLine();
545 mathcursor->idxNext();
550 mathcursor->idxPrev();
555 bv->lockedInsetStoreUndo(Undo::EDIT);
556 mathcursor->splitCell();
561 if (!mathcursor->InMacroMode() && mathcursor->pos() == 0) {
562 bv->lockedInsetStoreUndo(Undo::DELETE);
563 mathcursor->pullArg();
564 bv->updateInset(this, true);
567 if (!mathcursor->Left())
572 bv->lockedInsetStoreUndo(Undo::DELETE);
573 mathcursor->Delete();
574 bv->updateInset(this, true);
578 // sprintf(dispatch_buffer, "%d %d",);
579 // dispatch_result = dispatch_buffer;
583 lyxerr << "LFUN_SETXY broken!\n";
588 istringstream is(arg.c_str());
591 mathcursor->SetPos(x1 + x, y1 + y);
596 // cursor selection ----------------------------
600 mathcursor->MacroModeClose();
601 bv->lockedInsetStoreUndo(Undo::INSERT);
602 mathcursor->SelPaste();
607 bv->lockedInsetStoreUndo(Undo::DELETE);
608 mathcursor->SelCut();
613 mathcursor->SelCopy();
618 case LFUN_WORDRIGHTSEL:
619 case LFUN_WORDLEFTSEL:
622 // --- accented characters ------------------------------
624 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
625 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
626 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
627 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
628 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
629 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
630 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
631 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
632 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
633 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
637 if (!greek_kb_flag) {
639 bv->owner()->message(_("Math greek mode on"));
645 case LFUN_GREEK_TOGGLE:
646 greek_kb_flag = greek_kb_flag ? 0 : 2;
648 bv->owner()->message(_("Math greek keyboard on"));
650 bv->owner()->message(_("Math greek keyboard off"));
654 case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
655 case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
656 case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
657 case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
658 case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
659 case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
662 handleFont(bv, LM_TC_TEXTRM);
663 //bv->owner()->message(_("math text mode toggled"));
668 if (!mathcursor->Selection()) {
669 mathcursor->handleFont(LM_TC_TEX);
670 //bv->owner()->message(_("TeX mode toggled"));
675 case LFUN_MATH_LIMITS:
676 bv->lockedInsetStoreUndo(Undo::INSERT);
677 if (mathcursor->toggleLimits())
683 bv->lockedInsetStoreUndo(Undo::INSERT);
684 latexkeys const * l = in_word_set(arg);
685 mathcursor->SetSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
690 case LFUN_INSERT_MATRIX:
692 bv->lockedInsetStoreUndo(Undo::INSERT);
693 mathcursor->Interpret("matrix " + arg);
698 case LFUN_INSERT_MATH:
700 bv->lockedInsetStoreUndo(Undo::INSERT);
701 mathcursor->Interpret(arg);
706 case LFUN_MATH_DELIM:
708 bv->lockedInsetStoreUndo(Undo::INSERT);
711 static const string vdelim("(){}[]./|");
712 lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
717 istringstream is(arg.c_str());
721 lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
722 lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
725 latexkeys const * l = in_word_set(lt);
728 } else if (vdelim.find(lt[0]) != string::npos)
732 latexkeys const * l = in_word_set(rt);
735 } else if (vdelim.find(rt[0]) != string::npos)
738 if (mathcursor->selection) {
739 MathDelimInset * p = new MathDelimInset(ilt, irt);
741 mathcursor->selArray(ar);
742 lyxerr << "selarray: " << ar << "\n";
744 mathcursor->insert(p);
746 mathcursor->insert(new MathDelimInset(ilt, irt));
752 case LFUN_PROTECTEDSPACE:
753 bv->lockedInsetStoreUndo(Undo::INSERT);
754 mathcursor->insert(new MathSpaceInset(1));
759 bv->owner()->message(_("Invalid action in math mode!"));
763 case LFUN_MATH_HALIGN:
765 bv->lockedInsetStoreUndo(Undo::INSERT);
766 lyxerr << "handling halign '" << arg << "'\n";
768 MathArrayInset * p = matrixpar(idx);
771 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
776 case LFUN_MATH_VALIGN:
778 bv->lockedInsetStoreUndo(Undo::INSERT);
779 lyxerr << "handling valign '" << arg << "'\n";
781 MathArrayInset * p = matrixpar(idx);
784 p->valign(arg.size() ? arg[0] : 'c');
789 case LFUN_MATH_ROW_INSERT:
791 bv->lockedInsetStoreUndo(Undo::INSERT);
793 MathArrayInset * p = matrixpar(idx);
794 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
797 p->addRow(p->row(idx));
802 case LFUN_MATH_ROW_DELETE:
804 bv->lockedInsetStoreUndo(Undo::INSERT);
806 MathArrayInset * p = matrixpar(idx);
807 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
810 p->delRow(p->row(idx));
815 case LFUN_MATH_COLUMN_INSERT:
817 bv->lockedInsetStoreUndo(Undo::INSERT);
819 MathArrayInset * p = matrixpar(idx);
822 p->addCol(p->col(idx));
827 case LFUN_MATH_COLUMN_DELETE:
829 bv->lockedInsetStoreUndo(Undo::INSERT);
831 MathArrayInset * p = matrixpar(idx);
834 p->delCol(p->col(idx));
839 case LFUN_EXEC_COMMAND:
840 result = UNDISPATCHED;
844 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
845 unsigned char c = arg[0];
846 lyxerr << "char: '" << c << "' int: " << int(c) << endl;
847 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
848 lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
849 bv->lockedInsetStoreUndo(Undo::INSERT);
851 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
853 mathcursor->setAccent(0);
856 if (c == 0) { // Dead key, do nothing
857 //lyxerr << "deadkey" << endl;
862 if (mathcursor->getLastCode() == LM_TC_TEX) {
863 mathcursor->MacroModeOpen();
864 mathcursor->clearLastCode();
866 } else if (!varcode) {
867 short f = mathcursor->getLastCode() ?
868 mathcursor->getLastCode() :
869 mathcursor->nextCode();
870 varcode = MathIsAlphaFont(f) ?
871 static_cast<MathTextCodes>(f) :
875 // lyxerr << "Varcode << vardoce;
876 MathTextCodes char_code = varcode;
879 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
880 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
881 'Y', 0, 0, 0, 0 , 'Z' };
883 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
884 char_code = LM_TC_RM;
887 char_code = LM_TC_SYMB;
890 mathcursor->insert(c, char_code);
892 if (greek_kb_flag && char_code == LM_TC_RM )
893 mathcursor->setLastCode(LM_TC_VAR);
897 if (greek_kb_flag < 2)
900 } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
901 mathcursor->insert(c, LM_TC_TEX);
903 mathcursor->insert('}', LM_TC_TEX);
906 mathcursor->clearLastCode();
907 // varcode = LM_TC_MIN;
908 } else if (c == '_' && varcode == LM_TC_TEX) {
909 mathcursor->insert(c, LM_TC_SPECIAL);
910 mathcursor->clearLastCode();
911 // varcode = LM_TC_MIN;
912 } else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
913 mathcursor->MacroModeOpen();
914 mathcursor->clearLastCode();
915 mathcursor->insert(c, LM_TC_MIN);
916 } else if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) {
917 MathTextCodes code = mathcursor->getLastCode();
918 if (code != LM_TC_TEXTRM)
920 mathcursor->insert(c, code);
921 } else if (strchr("+/-*<>=", c)) {
922 MathTextCodes code = mathcursor->getLastCode();
923 if (code != LM_TC_TEXTRM)
925 mathcursor->insert(c, code);
926 } else if (strchr(latex_special_chars, c) && c != '_') {
927 MathTextCodes code = mathcursor->getLastCode();
928 if (code != LM_TC_TEXTRM)
929 code = LM_TC_SPECIAL;
930 mathcursor->insert(c, code);
931 } else if (c == '_' || c == '^') {
935 mathcursor->Interpret(s);
936 } else if (c == ' ') {
938 short f = (mathcursor->getLastCode()) ?
939 mathcursor->getLastCode() :
940 mathcursor->nextCode();
941 varcode = MathIsAlphaFont(f) ?
942 static_cast<MathTextCodes>(f) :
946 if (varcode == LM_TC_TEXTRM) {
947 mathcursor->insert(c, LM_TC_TEXTRM);
948 } else if (was_macro) {
949 mathcursor->MacroModeClose();
951 if (!mathcursor->pop())
953 mathcursor->plainRight();
955 } else if (c == '\'' || c == '@') {
956 mathcursor->insert (c, LM_TC_VAR);
957 } else if (c == '\\') {
959 mathcursor->MacroModeClose();
960 bv->owner()->message(_("TeX mode"));
961 mathcursor->setLastCode(LM_TC_TEX);
964 } else if (action == LFUN_MATH_PANEL) {
965 result = UNDISPATCHED;
967 lyxerr << "Closed by action " << action << endl;
972 mathcursor->normalize();
974 if (mathcursor && was_macro != mathcursor->InMacroMode()
976 && action != LFUN_BACKSPACE)
982 if (mathcursor && (mathcursor->Selection() || was_selection))
983 toggleInsetSelection(bv);
985 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
986 result == UNDISPATCHED)
989 bv->unlockInset(this);
991 return result; // original version
996 /* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
998 bool math_insert_greek(BufferView * bv, char c)
1000 if (!bv->available())
1008 if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
1009 int greek_kb_flag_save = greek_kb_flag;
1010 InsetFormula * new_inset = new InsetFormula();
1011 bv->beforeChange(bv->text);
1012 if (!bv->insertInset(new_inset)) {
1017 new_inset->edit(bv, 0, 0, 0);
1018 new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
1019 if (greek_kb_flag_save < 2) {
1020 bv->unlockInset(new_inset); // bv->theLockingInset());
1021 bv->text->cursorRight(bv, true);
1024 if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
1025 bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
1026 static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
1028 lyxerr << "Math error: attempt to write on a wrong "
1029 "class of inset." << endl;
1035 Inset::Code InsetFormulaBase::lyxCode() const
1037 return Inset::MATH_CODE;
1041 LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
1043 // We have already discussed what was here
1046 font.setLatex(LyXFont::OFF);
1051 MathInset * InsetFormulaBase::par() const
1057 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
1059 if (bv->available()) {
1060 // Feature "Read math inset from selection" disabled.
1061 // // use selection if available..
1063 // if (action == LFUN_MATH_IMPORT_SELECTION)
1066 // sel = bv->getLyXText()->selectionAsString(bv->buffer());
1069 // if (sel.empty()) {
1070 f = new InsetFormula;
1071 if (openNewInset(bv, f)) {
1072 // don't do that also for LFUN_MATH_MODE unless you want end up with
1073 // always changing to mathrm when opening an inlined inset
1074 // -- I really hate "LyXfunc overloading"...
1076 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
1077 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
1080 // f = new InsetFormula(sel);
1081 // bv->getLyXText()->cutSelection(bv);
1082 // openNewInset(bv, f);
1085 bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
1088 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
1090 mathDispatchCreation(bv, arg, true);
1093 void mathDispatchMathMode(BufferView * bv, string const & arg)
1095 mathDispatchCreation(bv, arg, false);
1098 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
1100 mathDispatchCreation(bv, arg, true);
1103 void mathDispatchMathMacro(BufferView * bv, string const & arg)
1105 if (bv->available()) {
1108 bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
1110 string const s1 = token(s, ' ', 1);
1111 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1112 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1117 void mathDispatchMathDelim(BufferView * bv, string const & arg)
1119 if (bv->available()) {
1120 if (openNewInset(bv, new InsetFormula))
1121 bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
1126 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
1128 if (bv->available()) {
1129 if (openNewInset(bv, new InsetFormula))
1130 bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
1134 void mathDispatchInsertMath(BufferView * bv, string const & arg)
1136 if (bv->available()) {
1137 if (arg.size() && arg[0] == '\\') {
1138 InsetFormula * f = new InsetFormula(arg);
1139 openNewInset(bv, f);
1141 mathDispatchMathMode(bv, arg);