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 "support/lyxlib.h"
43 #include "mathed/support.h"
44 #include "undo_funcs.h"
50 extern char const * latex_special_chars;
52 int greek_kb_flag = 0;
53 extern char const * latex_mathenv[];
54 LyXFont * Math_Fonts = 0;
55 MathCursor * mathcursor = 0;
66 void mathed_init_fonts();
68 string nicelabel(string const & label)
70 return "(" + (label.empty() ? "#" : label) + ")";
73 void handleFont(BufferView * bv, MathTextCodes t)
75 if (mathcursor->Selection())
76 bv->lockedInsetStoreUndo(Undo::EDIT);
77 mathcursor->handleFont(t);
80 void handleAccent(BufferView * bv, int code)
82 bv->lockedInsetStoreUndo(Undo::EDIT);
83 mathcursor->handleAccent(code);
86 void handleDelim(BufferView * bv, int l, int r)
88 bv->lockedInsetStoreUndo(Undo::EDIT);
89 mathcursor->handleDelim(l, r);
92 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
94 LyXText * lt = bv->getLyXText();
98 if (!bv->insertInset(new_inset)) {
102 new_inset->edit(bv, 0, 0, 0);
111 LyXFont WhichFont(short type, int size)
148 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
162 if (type == LM_TC_BSYM) {
175 case LM_ST_SCRIPTSCRIPT:
181 lyxerr << "Math Error: wrong font size: " << size << endl;
185 if (type != LM_TC_TEXTRM)
186 f.setColor(LColor::math);
188 if (type == LM_TC_TEX)
189 f.setColor(LColor::latex);
197 void mathed_init_fonts()
199 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
202 for (int i = 0 ; i < 8 ; ++i) {
203 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
206 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
208 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
210 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
211 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
213 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
215 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
216 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
218 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
220 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
222 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
226 // returns the nearest enclosing matrix
227 MathArrayInset * matrixpar(int & idx)
231 static_cast<MathArrayInset *>
232 (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
239 InsetFormulaBase::InsetFormulaBase(MathInset * par)
244 InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
245 : UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
249 InsetFormulaBase::~InsetFormulaBase()
252 #warning leak this for a while...
258 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
263 void InsetFormulaBase::write(Buffer const *, ostream & os) const
268 int InsetFormulaBase::latex(Buffer const *, ostream & os,
269 bool fragile, bool spacing) const
271 return latex(os, fragile, spacing);
274 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
276 return ascii(os, spacing);
279 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
284 int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
291 // Check if uses AMS macros
292 void InsetFormulaBase::validate(LaTeXFeatures &) const
296 string const InsetFormulaBase::editMessage() const
298 return _("Math editor mode");
302 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
304 mathcursor = new MathCursor(this);
306 if (!bv->lockInset(this))
307 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
309 par_->Metrics(LM_ST_TEXT);
310 //bv->updateInset(this, false);
321 void InsetFormulaBase::insetUnlock(BufferView * bv)
324 if (mathcursor->InMacroMode()) {
325 mathcursor->MacroModeClose();
331 bv->updateInset(this, false);
335 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
337 mathcursor->GetPos(x, y);
343 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
348 if (isCursorVisible())
349 bv->hideLockedInsetCursor();
353 mathcursor->GetPos(x, y);
357 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
358 int const asc = lyxfont::maxAscent(font);
359 int const desc = lyxfont::maxDescent(font);
361 bv->showLockedInsetCursor(x, y, asc, desc);
364 toggleCursorVisible();
368 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
370 if (!isCursorVisible()) {
374 mathcursor->GetPos(x, y);
377 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
378 int const asc = lyxfont::maxAscent(font);
379 int const desc = lyxfont::maxDescent(font);
380 bv->fitLockedInsetCursor(x, y, asc, desc);
382 toggleInsetCursor(bv);
387 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
389 if (isCursorVisible())
390 toggleInsetCursor(bv);
394 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
399 bv->updateInset(this, false);
403 vector<string> const InsetFormulaBase::getLabelList() const
405 return std::vector<string>();
409 void InsetFormulaBase::updateLocal(BufferView * bv)
411 par_->Metrics(LM_ST_TEXT);
412 bv->updateInset(this, true);
416 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
417 int x, int y, int /*button*/)
423 mathcursor->SetPos(x, y);
430 bv->updateInset(this, false);
435 void InsetFormulaBase::insetButtonPress(BufferView * bv,
436 int x, int y, int /*button*/)
441 if (mathcursor && mathcursor->Selection()) {
442 mathcursor->SelClear();
443 bv->updateInset(this, false);
448 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
449 int x, int y, int /*button*/)
451 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
454 mathcursor->SetPos(sel_x + par_->xo(), sel_y + par_->yo());
455 mathcursor->SelStart();
457 mathcursor->GetPos(sel_x, sel_y);
458 } else if (sel_flag) {
462 mathcursor->SetPos(x, y);
464 mathcursor->GetPos(x, y);
465 if (sel_x != x || sel_y != y)
466 bv->updateInset(this, false);
473 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
475 lyxerr[Debug::MATHED]
476 << "Used InsetFormulaBase::InsetKeyPress." << endl;
481 UpdatableInset::RESULT
482 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
485 //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
486 // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
491 MathTextCodes varcode = LM_TC_MIN;
492 bool was_macro = mathcursor->InMacroMode();
494 bool was_selection = mathcursor->Selection();
495 RESULT result = DISPATCHED;
499 if (mathcursor->getLastCode() == LM_TC_TEX)
502 mathcursor->normalize();
506 // --- Cursor Movements ---------------------------------------------
509 sel = true; // fall through...
512 result = DISPATCH_RESULT(mathcursor->Right(sel));
518 sel = true; // fall through
521 result = DISPATCH_RESULT(mathcursor->Left(sel));
530 result = DISPATCH_RESULT(mathcursor->Up(sel));
539 result = DISPATCH_RESULT(mathcursor->Down(sel));
553 case LFUN_DELETE_LINE_FORWARD:
554 bv->lockedInsetStoreUndo(Undo::DELETE);
555 mathcursor->DelLine();
560 mathcursor->idxNext();
565 mathcursor->idxPrev();
570 bv->lockedInsetStoreUndo(Undo::EDIT);
571 mathcursor->splitCell();
576 if (!mathcursor->InMacroMode() && mathcursor->pos() == 0) {
577 bv->lockedInsetStoreUndo(Undo::DELETE);
578 mathcursor->pullArg();
579 bv->updateInset(this, true);
582 if (!mathcursor->Left())
587 bv->lockedInsetStoreUndo(Undo::DELETE);
588 mathcursor->Delete();
589 bv->updateInset(this, true);
593 // sprintf(dispatch_buffer, "%d %d",);
594 // dispatch_result = dispatch_buffer;
598 lyxerr << "LFUN_SETXY broken!\n";
603 istringstream is(arg.c_str());
606 mathcursor->SetPos(x1 + x, y1 + y);
611 // cursor selection ----------------------------
615 mathcursor->MacroModeClose();
616 bv->lockedInsetStoreUndo(Undo::INSERT);
617 mathcursor->SelPaste();
622 bv->lockedInsetStoreUndo(Undo::DELETE);
623 mathcursor->SelCut();
628 mathcursor->SelCopy();
633 case LFUN_WORDRIGHTSEL:
634 case LFUN_WORDLEFTSEL:
637 // --- accented characters ------------------------------
639 case LFUN_UMLAUT: handleAccent(bv, LM_ddot); break;
640 case LFUN_CIRCUMFLEX: handleAccent(bv, LM_hat); break;
641 case LFUN_GRAVE: handleAccent(bv, LM_grave); break;
642 case LFUN_ACUTE: handleAccent(bv, LM_acute); break;
643 case LFUN_TILDE: handleAccent(bv, LM_tilde); break;
644 case LFUN_MACRON: handleAccent(bv, LM_bar); break;
645 case LFUN_DOT: handleAccent(bv, LM_dot); break;
646 case LFUN_CARON: handleAccent(bv, LM_check); break;
647 case LFUN_BREVE: handleAccent(bv, LM_breve); break;
648 case LFUN_VECTOR: handleAccent(bv, LM_vec); break;
652 if (!greek_kb_flag) {
654 bv->owner()->message(_("Math greek mode on"));
660 case LFUN_GREEK_TOGGLE:
661 greek_kb_flag = greek_kb_flag ? 0 : 2;
663 bv->owner()->message(_("Math greek keyboard on"));
665 bv->owner()->message(_("Math greek keyboard off"));
669 case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
670 case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
671 case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
672 case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
673 case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
674 case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
677 handleFont(bv, LM_TC_TEXTRM);
678 //bv->owner()->message(_("math text mode toggled"));
683 if (!mathcursor->Selection()) {
684 mathcursor->handleFont(LM_TC_TEX);
685 //bv->owner()->message(_("TeX mode toggled"));
690 case LFUN_MATH_LIMITS:
691 bv->lockedInsetStoreUndo(Undo::INSERT);
692 if (mathcursor->toggleLimits())
698 bv->lockedInsetStoreUndo(Undo::INSERT);
699 latexkeys const * l = in_word_set(arg);
700 mathcursor->SetSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
705 case LFUN_INSERT_MATRIX:
707 bv->lockedInsetStoreUndo(Undo::INSERT);
708 mathcursor->Interpret("matrix " + arg);
713 case LFUN_INSERT_MATH:
715 bv->lockedInsetStoreUndo(Undo::INSERT);
716 mathcursor->Interpret(arg);
721 case LFUN_MATH_DELIM:
723 bv->lockedInsetStoreUndo(Undo::INSERT);
726 static const string vdelim("(){}[]./|");
727 lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
732 istringstream is(arg.c_str());
736 lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
737 lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
740 latexkeys const * l = in_word_set(lt);
743 } else if (vdelim.find(lt[0]) != string::npos)
747 latexkeys const * l = in_word_set(rt);
750 } else if (vdelim.find(rt[0]) != string::npos)
753 handleDelim(bv, ilt, irt);
758 case LFUN_PROTECTEDSPACE:
759 bv->lockedInsetStoreUndo(Undo::INSERT);
760 mathcursor->insert(new MathSpaceInset(1));
765 bv->owner()->message(_("Invalid action in math mode!"));
769 case LFUN_MATH_HALIGN:
771 bv->lockedInsetStoreUndo(Undo::INSERT);
772 lyxerr << "handling halign '" << arg << "'\n";
774 MathArrayInset * p = matrixpar(idx);
777 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
782 case LFUN_MATH_VALIGN:
784 bv->lockedInsetStoreUndo(Undo::INSERT);
785 lyxerr << "handling valign '" << arg << "'\n";
787 MathArrayInset * p = matrixpar(idx);
790 p->valign(arg.size() ? arg[0] : 'c');
795 case LFUN_MATH_ROW_INSERT:
797 bv->lockedInsetStoreUndo(Undo::INSERT);
799 MathArrayInset * p = matrixpar(idx);
800 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
803 p->addRow(p->row(idx));
808 case LFUN_MATH_ROW_DELETE:
810 bv->lockedInsetStoreUndo(Undo::INSERT);
812 MathArrayInset * p = matrixpar(idx);
813 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
816 p->delRow(p->row(idx));
821 case LFUN_MATH_COLUMN_INSERT:
823 bv->lockedInsetStoreUndo(Undo::INSERT);
825 MathArrayInset * p = matrixpar(idx);
828 p->addCol(p->col(idx));
833 case LFUN_MATH_COLUMN_DELETE:
835 bv->lockedInsetStoreUndo(Undo::INSERT);
837 MathArrayInset * p = matrixpar(idx);
840 p->delCol(p->col(idx));
845 case LFUN_EXEC_COMMAND:
846 result = UNDISPATCHED;
850 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
851 unsigned char c = arg[0];
852 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
853 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
854 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
855 bv->lockedInsetStoreUndo(Undo::INSERT);
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;
973 mathcursor->normalize();
975 if (mathcursor && was_macro != mathcursor->InMacroMode()
977 && action != LFUN_BACKSPACE)
983 if (mathcursor && (mathcursor->Selection() || was_selection))
984 toggleInsetSelection(bv);
986 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
987 result == UNDISPATCHED)
990 bv->unlockInset(this);
992 return result; // original version
997 /* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
999 bool math_insert_greek(BufferView * bv, char c)
1001 if (!bv->available())
1009 if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
1010 int greek_kb_flag_save = greek_kb_flag;
1011 InsetFormula * new_inset = new InsetFormula();
1012 bv->beforeChange(bv->text);
1013 if (!bv->insertInset(new_inset)) {
1018 new_inset->edit(bv, 0, 0, 0);
1019 new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
1020 if (greek_kb_flag_save < 2) {
1021 bv->unlockInset(new_inset); // bv->theLockingInset());
1022 bv->text->cursorRight(bv, true);
1025 if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
1026 bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
1027 static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
1029 lyxerr << "Math error: attempt to write on a wrong "
1030 "class of inset." << endl;
1036 Inset::Code InsetFormulaBase::lyxCode() const
1038 return Inset::MATH_CODE;
1042 LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
1044 // We have already discussed what was here
1047 font.setLatex(LyXFont::OFF);
1052 MathInset * InsetFormulaBase::par() const
1058 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
1060 if (bv->available()) {
1061 // Feature "Read math inset from selection" disabled.
1062 // // use selection if available..
1064 // if (action == LFUN_MATH_IMPORT_SELECTION)
1067 // sel = bv->getLyXText()->selectionAsString(bv->buffer());
1070 // if (sel.empty()) {
1071 f = new InsetFormula;
1072 if (openNewInset(bv, f)) {
1073 // don't do that also for LFUN_MATH_MODE unless you want end up with
1074 // always changing to mathrm when opening an inlined inset
1075 // -- I really hate "LyXfunc overloading"...
1077 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
1078 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
1081 // f = new InsetFormula(sel);
1082 // bv->getLyXText()->cutSelection(bv);
1083 // openNewInset(bv, f);
1086 bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
1089 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
1091 mathDispatchCreation(bv, arg, true);
1094 void mathDispatchMathMode(BufferView * bv, string const & arg)
1096 mathDispatchCreation(bv, arg, false);
1099 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
1101 mathDispatchCreation(bv, arg, true);
1104 void mathDispatchMathMacro(BufferView * bv, string const & arg)
1106 if (bv->available()) {
1109 bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
1111 string const s1 = token(s, ' ', 1);
1112 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1113 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1118 void mathDispatchMathDelim(BufferView * bv, string const & arg)
1120 if (bv->available()) {
1121 if (openNewInset(bv, new InsetFormula))
1122 bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
1127 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
1129 if (bv->available()) {
1130 if (openNewInset(bv, new InsetFormula))
1131 bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
1135 void mathDispatchInsertMath(BufferView * bv, string const & arg)
1137 if (bv->available()) {
1138 if (arg.size() && arg[0] == '\\') {
1139 InsetFormula * f = new InsetFormula(arg);
1140 openNewInset(bv, f);
1142 mathDispatchMathMode(bv, arg);