3 * Purpose: Implementation of common parts of the LyX math insets
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
7 * Copyright: 1996-1998 Alejandro Aguilar Sierra
9 * Version: 0.4, Lyx project.
11 * You are free to use and modify this code under the terms of
12 * the GNU General Public Licence version 2 or later.
19 #include "support/LAssert.h"
22 #pragma implementation
26 #include "formulamacro.h"
28 #include "funcrequest.h"
29 #include "BufferView.h"
32 #include "LaTeXFeatures.h"
34 #include "math_support.h"
35 #include "math_metricsinfo.h"
36 #include "support/lstrings.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/font_metrics.h"
39 #include "frontends/mouse_state.h"
41 #include "math_arrayinset.h"
42 #include "math_charinset.h"
43 #include "math_deliminset.h"
44 #include "math_cursor.h"
45 #include "math_factory.h"
46 #include "math_fontinset.h"
47 #include "math_hullinset.h"
48 #include "math_iterator.h"
49 #include "math_macrotable.h"
50 #include "math_parser.h"
52 #include "math_spaceinset.h"
53 #include "undo_funcs.h"
54 #include "textpainter.h"
55 #include "frontends/Dialogs.h"
57 #include "insets/insetcommandparams.h"
58 #include "ref_inset.h"
66 MathCursor * mathcursor = 0;
77 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
79 if (!bv->insertInset(new_inset)) {
83 new_inset->edit(bv, true);
92 InsetFormulaBase::InsetFormulaBase()
93 : font_(), xo_(0), yo_(0)
95 // This is needed as long the math parser is not re-entrant
97 //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
98 //lyxerr << "sizeof MathMetricsInfo: " << sizeof(MathMetricsInfo) << "\n";
99 //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << "\n";
100 //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << "\n";
104 // simply scrap this function if you want
105 void InsetFormulaBase::mutateToText()
108 // translate to latex
110 latex(NULL, os, false, false);
111 string str = os.str();
114 LyXText * lt = view_->getLyXText();
115 string::const_iterator cit = str.begin();
116 string::const_iterator end = str.end();
117 for (; cit != end; ++cit)
118 view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
121 //view_->owner()->dispatch(LFUN_ESCAPE);
126 void InsetFormulaBase::handleFont
127 (BufferView * bv, string const & arg, string const & font)
129 // this whole function is a hack and won't work for incremental font
131 bv->lockedInsetStoreUndo(Undo::EDIT);
132 if (mathcursor->par()->name() == font) {
133 mathcursor->handleFont(font);
134 updateLocal(bv, true);
136 bool sel = mathcursor->selection();
138 updateLocal(bv, true);
139 mathcursor->handleNest(createMathInset(font));
140 mathcursor->insert(arg);
142 updateLocal(bv, false);
147 // Check if uses AMS macros
148 void InsetFormulaBase::validate(LaTeXFeatures &) const
152 void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
159 void InsetFormulaBase::metrics(BufferView * bv) const
162 view_ = bv->owner()->view();
164 mi.base.style = LM_ST_TEXT;
165 mi.base.font = font_;
166 mi.base.font.setColor(LColor::math);
171 string const InsetFormulaBase::editMessage() const
173 return _("Math editor mode");
177 void InsetFormulaBase::edit(BufferView * bv, int x, int y, mouse_button::state)
179 if (!bv->lockInset(this))
180 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
181 releaseMathCursor(bv);
182 mathcursor = new MathCursor(this, true);
184 mathcursor->setPos(x + xo_, y + yo_);
185 // if that is removed, we won't get the magenta box when entering an
186 // inset for the first time
187 bv->updateInset(this, false);
191 void InsetFormulaBase::edit(BufferView * bv, bool front)
193 if (!bv->lockInset(this))
194 lyxerr << "Cannot lock math inset in edit call!\n";
195 releaseMathCursor(bv);
196 mathcursor = new MathCursor(this, front);
198 bv->updateInset(this, false);
202 void InsetFormulaBase::insetUnlock(BufferView * bv)
205 if (mathcursor->inMacroMode()) {
206 mathcursor->macroModeClose();
207 updateLocal(bv, true);
209 releaseMathCursor(bv);
212 bv->updateInset(this, false);
216 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
218 // calling metrics here destroys the cached xo,yo positions e.g. in
219 // MathParboxinset. And it would be too expensive anyway...
222 lyxerr << "getCursorPos - should not happen";
226 mathcursor->getPos(x, y);
227 x = mathcursor->targetX();
230 //lyxerr << "getCursorPos: " << x << ' ' << y << endl;
234 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
237 lyxerr << "toggleInsetCursor impossible" << endl;
240 //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
241 if (isCursorVisible())
248 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
251 lyxerr << "showInsetCursor impossible" << endl;
254 if (isCursorVisible())
257 mathcursor->getPos(x, y);
258 math_font_max_dim(font_, asc, des);
259 bv->showLockedInsetCursor(x, y - yo_, asc, des);
260 setCursorVisible(true);
261 //lyxerr << "showInsetCursor: " << x << ' ' << y << endl;
265 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
269 if (!isCursorVisible())
271 bv->hideLockedInsetCursor();
272 setCursorVisible(false);
273 //lyxerr << "hideInsetCursor: " << endl;
277 void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
282 math_font_max_dim(font_, asc, des);
283 getCursorPos(bv, x, y);
285 //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl;
286 bv->fitLockedInsetCursor(x, y, asc, des);
290 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
293 bv->updateInset(this, false);
297 vector<string> const InsetFormulaBase::getLabelList() const
299 return vector<string>();
303 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
305 bv->updateInset(this, dirty);
309 Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
314 BufferView * bv = cmd.view();
317 bv->updateInset(this, false);
318 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
320 if (cmd.button() == mouse_button::button3) {
321 // try to dispatch to enclosed insets first
322 if (mathcursor->dispatch(cmd) == MathInset::UNDISPATCHED) {
323 // launch math panel for right mouse button
324 bv->owner()->getDialogs().showMathPanel();
329 if (cmd.button() == mouse_button::button2) {
330 mathcursor->selClear();
331 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
332 mathcursor->insert(asArray(bv->getClipboard()));
333 bv->updateInset(this, true);
337 if (cmd.button() == mouse_button::button1) {
338 // try to dispatch to enclosed insets first
339 mathcursor->dispatch(cmd);
340 cmd.view()->stuffClipboard(mathcursor->grabSelection());
341 // try to set the cursor
343 //mathcursor = new MathCursor(this, x == 0);
345 //mathcursor->setPos(x + xo_, y + yo_);
353 Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
355 BufferView * bv = cmd.view();
356 //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
358 if (!mathcursor || mathcursor->formula() != this) {
359 lyxerr << "re-create cursor" << endl;
360 releaseMathCursor(bv);
361 mathcursor = new MathCursor(this, cmd.x == 0);
363 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
366 if (cmd.button() == mouse_button::button3) {
367 mathcursor->dispatch(cmd);
371 if (cmd.button() == mouse_button::button1) {
374 mathcursor->selClear();
375 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
376 mathcursor->dispatch(cmd);
380 bv->updateInset(this, false);
385 Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
390 if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
393 // only select with button 1
394 if (cmd.button() != mouse_button::button1)
397 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
403 if (!mathcursor->selection())
404 mathcursor->selStart();
406 BufferView * bv = cmd.view();
408 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
410 bv->updateInset(this, false);
415 Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
417 //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
418 // << " arg: '" << cmd.argument
419 // << " x: '" << cmd.x
420 // << " y: '" << cmd.y
421 // << "' button: " << cmd.button() << endl;
423 switch (cmd.action) {
424 case LFUN_MOUSE_PRESS:
425 return lfunMousePress(cmd);
426 case LFUN_MOUSE_MOTION:
427 return lfunMouseMotion(cmd);
428 case LFUN_MOUSE_RELEASE:
429 return lfunMouseRelease(cmd);
430 case LFUN_MOUSE_DOUBLE:
431 //lyxerr << "Mouse double\n";
432 return localDispatch(FuncRequest(LFUN_WORDSEL));
440 BufferView * bv = cmd.view();
441 string argument = cmd.argument;
442 RESULT result = DISPATCHED;
444 bool was_macro = mathcursor->inMacroMode();
445 bool was_selection = mathcursor->selection();
449 mathcursor->normalize();
452 switch (cmd.action) {
454 case LFUN_MATH_MUTATE:
455 case LFUN_MATH_DISPLAY:
456 case LFUN_MATH_NUMBER:
457 case LFUN_MATH_NONUMBER:
460 case LFUN_DELETE_LINE_FORWARD:
461 case LFUN_INSERT_LABEL:
462 case LFUN_MATH_EXTERN:
463 case LFUN_TABULAR_FEATURE:
464 case LFUN_PASTESELECTION:
465 case LFUN_MATH_LIMITS:
466 bv->lockedInsetStoreUndo(Undo::EDIT);
467 mathcursor->dispatch(cmd);
468 updateLocal(bv, true);
472 sel = true; // fall through...
474 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
475 //lyxerr << "calling scroll 20\n";
477 updateLocal(bv, false);
478 // write something to the minibuffer
479 //bv->owner()->message(mathcursor->info());
483 sel = true; // fall through
485 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
486 updateLocal(bv, false);
490 sel = true; // fall through
492 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
493 updateLocal(bv, false);
497 sel = true; // fall through
499 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
500 updateLocal(bv, false);
504 mathcursor->home(false);
505 mathcursor->end(true);
506 updateLocal(bv, false);
509 case LFUN_UP_PARAGRAPHSEL:
510 case LFUN_UP_PARAGRAPH:
511 case LFUN_DOWN_PARAGRAPHSEL:
512 case LFUN_DOWN_PARAGRAPH:
514 updateLocal(bv, false);
518 case LFUN_WORDLEFTSEL:
519 sel = true; // fall through
522 result = mathcursor->home(sel) ? DISPATCHED : FINISHED;
523 updateLocal(bv, false);
527 case LFUN_WORDRIGHTSEL:
528 sel = true; // fall through
531 result = mathcursor->end(sel) ? DISPATCHED : FINISHED_RIGHT;
532 updateLocal(bv, false);
537 case LFUN_BEGINNINGBUFSEL:
538 case LFUN_BEGINNINGBUF:
539 result = FINISHED_UP;
540 updateLocal(bv, false);
547 result = FINISHED_DOWN;
548 updateLocal(bv, false);
552 mathcursor->idxNext();
553 updateLocal(bv, false);
557 mathcursor->idxPrev();
558 updateLocal(bv, false);
561 case LFUN_DELETE_WORD_BACKWARD:
563 bv->lockedInsetStoreUndo(Undo::DELETE);
564 mathcursor->backspace();
565 updateLocal(bv, true);
568 case LFUN_DELETE_WORD_FORWARD:
570 bv->lockedInsetStoreUndo(Undo::DELETE);
572 bv->updateInset(this, true);
576 // sprintf(dispatch_buffer, "%d %d",);
577 // dispatch_result = dispatch_buffer;
580 lyxerr << "LFUN_SETXY broken!\n";
583 istringstream is(cmd.argument.c_str());
585 mathcursor->setPos(x, y);
586 updateLocal(bv, false);
592 mathcursor->macroModeClose();
593 bv->lockedInsetStoreUndo(Undo::EDIT);
594 mathcursor->selPaste();
595 updateLocal(bv, true);
599 bv->lockedInsetStoreUndo(Undo::DELETE);
600 mathcursor->selCut();
601 updateLocal(bv, true);
605 mathcursor->selCopy();
609 // Special casing for superscript in case of LyX handling
611 case LFUN_CIRCUMFLEX:
612 if (cmd.argument.empty()) {
613 // do superscript if LyX handles
615 bv->lockedInsetStoreUndo(Undo::EDIT);
616 mathcursor->script(true);
617 updateLocal(bv, true);
634 case LFUN_HUNG_UMLAUT:
638 case LFUN_GREEK_TOGGLE: handleFont(bv, cmd.argument, "lyxgreek"); break;
639 case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break;
640 case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break;
641 case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break;
642 case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break;
643 case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break;
644 case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break;
645 case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break;
646 case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break;
647 case LFUN_FREE: handleFont(bv, cmd.argument, "textrm"); break;
648 case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break;
651 handleFont(bv, cmd.argument, "lyxgreek1");
652 if (cmd.argument.size())
653 mathcursor->insert(asArray(cmd.argument));
657 if (mathcursor->currentMode() == MathInset::TEXT_MODE) {
658 mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
659 updateLocal(bv, true);
661 handleFont(bv, cmd.argument, "textrm");
663 //bv->owner()->message(_("math text mode toggled"));
669 bv->lockedInsetStoreUndo(Undo::EDIT);
670 mathcursor->setSize(arg);
671 updateLocal(bv, true);
676 case LFUN_INSERT_MATRIX: {
677 bv->lockedInsetStoreUndo(Undo::EDIT);
682 istringstream is(STRCONV(argument));
683 is >> m >> n >> v_align >> h_align;
687 mathcursor->niceInsert(
688 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
689 updateLocal(bv, true);
693 case LFUN_SUPERSCRIPT:
696 bv->lockedInsetStoreUndo(Undo::EDIT);
697 mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
698 updateLocal(bv, true);
702 case LFUN_MATH_DELIM:
704 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
706 string rs = split(cmd.argument, ls, ' ');
707 // Reasonable default values
713 bv->lockedInsetStoreUndo(Undo::EDIT);
714 mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
715 updateLocal(bv, true);
719 case LFUN_PROTECTEDSPACE:
720 case LFUN_MATH_SPACE:
721 bv->lockedInsetStoreUndo(Undo::EDIT);
722 mathcursor->insert(MathAtom(new MathSpaceInset(",")));
723 updateLocal(bv, true);
727 bv->owner()->message(_("Invalid action in math mode!"));
731 case LFUN_EXEC_COMMAND:
732 result = UNDISPATCHED;
736 // interpret this as if a backslash was typed
737 bv->lockedInsetStoreUndo(Undo::EDIT);
738 mathcursor->interpret('\\');
739 updateLocal(bv, true);
742 case LFUN_BREAKPARAGRAPH:
743 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
744 case LFUN_BREAKPARAGRAPH_SKIP:
748 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
749 // handling such that "self-insert" works on "arbitrary stuff" too, and
750 // math-insert only handles special math things like "matrix".
751 case LFUN_INSERT_MATH:
752 bv->lockedInsetStoreUndo(Undo::EDIT);
753 mathcursor->niceInsert(argument);
754 updateLocal(bv, true);
758 case LFUN_SELFINSERT:
759 if (!argument.empty()) {
760 bv->lockedInsetStoreUndo(Undo::EDIT);
761 if (argument.size() == 1)
762 result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
764 mathcursor->insert(asArray(argument));
765 updateLocal(bv, true);
769 case LFUN_MATH_PANEL:
770 result = UNDISPATCHED;
774 if (mathcursor->selection())
775 mathcursor->selClear();
777 result = UNDISPATCHED;
780 case LFUN_INSET_TOGGLE:
781 mathcursor->insetToggle();
782 updateLocal(bv, true);
785 case LFUN_REF_INSERT:
786 //if (argument.empty()) {
787 // InsetCommandParams p("ref");
788 // owner_->getDialogs().createRef(p.getAsString());
790 // InsetCommandParams p;
791 // p.setFromString(argument);
793 // InsetRef * inset = new InsetRef(p, *buffer_);
794 // if (!insertInset(inset))
797 // updateInset(inset, true);
800 if (cmd.argument.empty()) {
801 InsetCommandParams p("ref");
802 bv->owner()->getDialogs().createRef(p.getAsString());
804 //mathcursor->handleNest(new InsetRef2);
805 //mathcursor->insert(arg);
806 mathcursor->insert(MathAtom(new RefInset(cmd.argument)));
808 updateLocal(bv, true);
812 result = UNDISPATCHED;
815 mathcursor->normalize();
818 lyx::Assert(mathcursor);
820 if (mathcursor->selection() || was_selection)
821 toggleInsetSelection(bv);
823 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
824 result == UNDISPATCHED) {
828 cmd.view()->stuffClipboard(mathcursor->grabSelection());
830 releaseMathCursor(bv);
831 bv->unlockInset(this);
834 return result; // original version
838 void InsetFormulaBase::revealCodes(BufferView * bv) const
842 bv->owner()->message(mathcursor->info());
845 // write something to the minibuffer
846 // translate to latex
847 mathcursor->markInsert();
850 string str = os.str();
851 mathcursor->markErase();
852 string::size_type pos = 0;
854 for (string::iterator it = str.begin(); it != str.end(); ++it) {
857 else if (*it == '\0') {
859 pos = it - str.begin();
865 res = res.substr(pos - 30);
867 res = res.substr(0, 60);
868 bv->owner()->message(res);
873 Inset::Code InsetFormulaBase::lyxCode() const
875 return Inset::MATH_CODE;
879 int InsetFormulaBase::ylow() const
881 return yo_ - ascent(view(), font_);
885 int InsetFormulaBase::yhigh() const
887 return yo_ + descent(view(), font_);
891 int InsetFormulaBase::xlow() const
897 int InsetFormulaBase::xhigh() const
899 return xo_ + width(view(), font_);
903 /////////////////////////////////////////////////////////////////////
906 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
912 static InsetFormulaBase * lastformula = 0;
913 static MathIterator current = MathIterator(ibegin(par().nucleus()));
915 static string laststr;
917 if (lastformula != this || laststr != str) {
918 //lyxerr << "reset lastformula to " << this << "\n";
921 current = ibegin(par().nucleus());
923 mathed_parse_cell(ar, str);
927 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
929 for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
930 if (it.cell().matchpart(ar, it.back().pos_)) {
931 bv->unlockInset(bv->theLockingInset());
932 if (!bv->lockInset(this)) {
933 lyxerr << "Cannot lock inset" << endl;
937 mathcursor = new MathCursor(this, true);
939 mathcursor->setSelection(it, ar.size());
942 updateLocal(bv, false);
947 //lyxerr << "not found!\n";
953 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
956 lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
957 return searchForward(bv, what, a, b);
961 bool InsetFormulaBase::display() const
963 return par()->asHullInset() && par()->asHullInset()->display();
967 string InsetFormulaBase::selectionAsString() const
969 return mathcursor ? mathcursor->grabSelection() : string();
972 /////////////////////////////////////////////////////////////////////
975 void mathDispatchCreation(FuncRequest const & cmd, bool display)
977 BufferView * bv = cmd.view();
978 // use selection if available..
980 //if (action == LFUN_MATH_IMPORT_SELECTION)
984 string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
987 InsetFormula * f = new InsetFormula(bv);
988 if (openNewInset(bv, f)) {
989 bv->theLockingInset()->
990 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
991 // don't do that also for LFUN_MATH_MODE unless you want end up with
992 // always changing to mathrm when opening an inlined inset
993 // -- I really hate "LyXfunc overloading"...
995 f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
996 f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
999 // create a macro if we see "\\newcommand" somewhere, and an ordinary
1000 // formula otherwise
1001 InsetFormulaBase * f;
1002 if (sel.find("\\newcommand") == string::npos &&
1003 sel.find("\\def") == string::npos)
1004 f = new InsetFormula(sel);
1006 f = new InsetFormulaMacro(sel);
1007 bv->getLyXText()->cutSelection(bv);
1008 openNewInset(bv, f);
1010 cmd.message(N_("Math editor mode"));
1014 void mathDispatch(FuncRequest const & cmd)
1016 BufferView * bv = cmd.view();
1017 if (!bv->available())
1020 switch (cmd.action) {
1022 case LFUN_MATH_DISPLAY:
1023 mathDispatchCreation(cmd, true);
1026 case LFUN_MATH_MODE:
1027 mathDispatchCreation(cmd, false);
1030 case LFUN_MATH_IMPORT_SELECTION:
1031 mathDispatchCreation(cmd, false);
1034 case LFUN_MATH_MACRO:
1035 if (cmd.argument.empty())
1036 cmd.errorMessage(N_("Missing argument"));
1038 string s = cmd.argument;
1039 string const s1 = token(s, ' ', 1);
1040 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1041 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1046 case LFUN_INSERT_MATH:
1047 case LFUN_INSERT_MATRIX:
1048 case LFUN_MATH_DELIM: {
1049 InsetFormula * f = new InsetFormula(bv);
1050 if (openNewInset(bv, f)) {
1051 bv->theLockingInset()->
1052 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1053 bv->theLockingInset()->localDispatch(cmd);