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"
23 #include "formulamacro.h"
25 #include "funcrequest.h"
26 #include "BufferView.h"
29 #include "LaTeXFeatures.h"
31 #include "math_support.h"
32 #include "math_metricsinfo.h"
33 #include "support/lstrings.h"
34 #include "frontends/LyXView.h"
35 #include "frontends/font_metrics.h"
36 #include "frontends/mouse_state.h"
38 #include "math_arrayinset.h"
39 #include "math_charinset.h"
40 #include "math_deliminset.h"
41 #include "math_cursor.h"
42 #include "math_factory.h"
43 #include "math_fontinset.h"
44 #include "math_hullinset.h"
45 #include "math_iterator.h"
46 #include "math_macrotable.h"
47 #include "math_parser.h"
49 #include "math_spaceinset.h"
50 #include "undo_funcs.h"
51 #include "textpainter.h"
52 #include "frontends/Dialogs.h"
54 #include "insets/insetcommandparams.h"
55 #include "ref_inset.h"
63 MathCursor * mathcursor = 0;
74 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
76 if (!bv->insertInset(new_inset)) {
80 new_inset->edit(bv, true);
89 InsetFormulaBase::InsetFormulaBase()
90 : font_(), xo_(0), yo_(0)
92 // This is needed as long the math parser is not re-entrant
94 //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
95 //lyxerr << "sizeof MathMetricsInfo: " << sizeof(MathMetricsInfo) << "\n";
96 //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << "\n";
97 //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << "\n";
101 // simply scrap this function if you want
102 void InsetFormulaBase::mutateToText()
105 // translate to latex
107 latex(NULL, os, false, false);
108 string str = os.str();
111 LyXText * lt = view_->getLyXText();
112 string::const_iterator cit = str.begin();
113 string::const_iterator end = str.end();
114 for (; cit != end; ++cit)
115 view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
118 //view_->owner()->dispatch(LFUN_ESCAPE);
123 void InsetFormulaBase::handleFont
124 (BufferView * bv, string const & arg, string const & font)
126 // this whole function is a hack and won't work for incremental font
128 bv->lockedInsetStoreUndo(Undo::EDIT);
129 if (mathcursor->par()->name() == font) {
130 mathcursor->handleFont(font);
131 updateLocal(bv, true);
133 bool sel = mathcursor->selection();
135 updateLocal(bv, true);
136 mathcursor->handleNest(createMathInset(font));
137 mathcursor->insert(arg);
139 updateLocal(bv, false);
144 // Check if uses AMS macros
145 void InsetFormulaBase::validate(LaTeXFeatures &) const
149 void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
156 void InsetFormulaBase::metrics(BufferView * bv) const
159 view_ = bv->owner()->view();
161 mi.base.style = LM_ST_TEXT;
162 mi.base.font = font_;
163 mi.base.font.setColor(LColor::math);
168 string const InsetFormulaBase::editMessage() const
170 return _("Math editor mode");
174 void InsetFormulaBase::edit(BufferView * bv, int x, int y, mouse_button::state)
176 if (!bv->lockInset(this))
177 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
178 releaseMathCursor(bv);
179 mathcursor = new MathCursor(this, true);
181 mathcursor->setPos(x + xo_, y + yo_);
182 // if that is removed, we won't get the magenta box when entering an
183 // inset for the first time
184 bv->updateInset(this, false);
188 void InsetFormulaBase::edit(BufferView * bv, bool front)
190 if (!bv->lockInset(this))
191 lyxerr << "Cannot lock math inset in edit call!\n";
192 releaseMathCursor(bv);
193 mathcursor = new MathCursor(this, front);
195 bv->updateInset(this, false);
199 void InsetFormulaBase::insetUnlock(BufferView * bv)
202 if (mathcursor->inMacroMode()) {
203 mathcursor->macroModeClose();
204 updateLocal(bv, true);
206 releaseMathCursor(bv);
209 bv->updateInset(this, false);
213 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
215 // calling metrics here destroys the cached xo,yo positions e.g. in
216 // MathParboxinset. And it would be too expensive anyway...
219 lyxerr << "getCursorPos - should not happen";
223 mathcursor->getPos(x, y);
224 x = mathcursor->targetX();
227 //lyxerr << "getCursorPos: " << x << ' ' << y << endl;
231 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
234 lyxerr[Debug::MATHED] << "toggleInsetCursor impossible" << endl;
237 //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
238 if (isCursorVisible())
245 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
248 lyxerr << "showInsetCursor impossible" << endl;
251 if (isCursorVisible())
254 mathcursor->getPos(x, y);
255 math_font_max_dim(font_, asc, des);
256 bv->showLockedInsetCursor(x, y - yo_, asc, des);
257 setCursorVisible(true);
258 //lyxerr << "showInsetCursor: " << x << ' ' << y << endl;
262 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
266 if (!isCursorVisible())
268 bv->hideLockedInsetCursor();
269 setCursorVisible(false);
270 //lyxerr << "hideInsetCursor: " << endl;
274 void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
279 math_font_max_dim(font_, asc, des);
280 getCursorPos(bv, x, y);
282 //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl;
283 bv->fitLockedInsetCursor(x, y, asc, des);
287 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
290 bv->updateInset(this, false);
294 vector<string> const InsetFormulaBase::getLabelList() const
296 return vector<string>();
300 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
302 bv->updateInset(this, dirty);
306 Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
311 BufferView * bv = cmd.view();
314 bv->updateInset(this, false);
315 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
317 if (cmd.button() == mouse_button::button3) {
318 // try to dispatch to enclosed insets first
319 if (mathcursor->dispatch(cmd) == MathInset::UNDISPATCHED) {
320 // launch math panel for right mouse button
321 bv->owner()->getDialogs().showMathPanel();
326 if (cmd.button() == mouse_button::button2) {
327 mathcursor->selClear();
328 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
329 mathcursor->insert(asArray(bv->getClipboard()));
330 bv->updateInset(this, true);
334 if (cmd.button() == mouse_button::button1) {
335 // try to dispatch to enclosed insets first
336 mathcursor->dispatch(cmd);
337 cmd.view()->stuffClipboard(mathcursor->grabSelection());
338 // try to set the cursor
340 //mathcursor = new MathCursor(this, x == 0);
342 //mathcursor->setPos(x + xo_, y + yo_);
350 Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
352 BufferView * bv = cmd.view();
353 //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
355 if (!mathcursor || mathcursor->formula() != this) {
356 lyxerr[Debug::MATHED] << "re-create cursor" << endl;
357 releaseMathCursor(bv);
358 mathcursor = new MathCursor(this, cmd.x == 0);
360 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
363 if (cmd.button() == mouse_button::button3) {
364 mathcursor->dispatch(cmd);
368 if (cmd.button() == mouse_button::button1) {
371 mathcursor->selClear();
372 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
373 mathcursor->dispatch(cmd);
377 bv->updateInset(this, false);
382 Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
387 if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
390 // only select with button 1
391 if (cmd.button() != mouse_button::button1)
394 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
400 if (!mathcursor->selection())
401 mathcursor->selStart();
403 BufferView * bv = cmd.view();
405 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
407 bv->updateInset(this, false);
412 Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
414 //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
415 // << " arg: '" << cmd.argument
416 // << " x: '" << cmd.x
417 // << " y: '" << cmd.y
418 // << "' button: " << cmd.button() << endl;
420 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
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:
540 updateLocal(bv, false);
547 result = FINISHED_RIGHT;
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::EDIT);
564 if (mathcursor->backspace()) {
570 updateLocal(bv, true);
573 case LFUN_DELETE_WORD_FORWARD:
575 bv->lockedInsetStoreUndo(Undo::EDIT);
576 if (mathcursor->erase()) {
582 updateLocal(bv, true);
586 // sprintf(dispatch_buffer, "%d %d",);
587 // dispatch_result = dispatch_buffer;
590 lyxerr << "LFUN_SETXY broken!\n";
593 istringstream is(cmd.argument.c_str());
595 mathcursor->setPos(x, y);
596 updateLocal(bv, false);
602 mathcursor->macroModeClose();
603 bv->lockedInsetStoreUndo(Undo::EDIT);
604 mathcursor->selPaste();
605 updateLocal(bv, true);
609 bv->lockedInsetStoreUndo(Undo::DELETE);
610 mathcursor->selCut();
611 updateLocal(bv, true);
615 mathcursor->selCopy();
619 // Special casing for superscript in case of LyX handling
621 case LFUN_CIRCUMFLEX:
622 if (cmd.argument.empty()) {
623 // do superscript if LyX handles
625 bv->lockedInsetStoreUndo(Undo::EDIT);
626 mathcursor->script(true);
627 updateLocal(bv, true);
644 case LFUN_HUNG_UMLAUT:
648 case LFUN_GREEK_TOGGLE: handleFont(bv, cmd.argument, "lyxgreek"); break;
649 case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break;
650 case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break;
651 case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break;
652 case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break;
653 case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break;
654 case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break;
655 case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break;
656 case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break;
657 case LFUN_FREE: handleFont(bv, cmd.argument, "textrm"); break;
658 case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break;
661 handleFont(bv, cmd.argument, "lyxgreek1");
662 if (cmd.argument.size())
663 mathcursor->insert(asArray(cmd.argument));
667 if (mathcursor->currentMode() == MathInset::TEXT_MODE) {
668 mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
669 updateLocal(bv, true);
671 handleFont(bv, cmd.argument, "textrm");
673 //bv->owner()->message(_("math text mode toggled"));
679 bv->lockedInsetStoreUndo(Undo::EDIT);
680 mathcursor->setSize(arg);
681 updateLocal(bv, true);
686 case LFUN_INSERT_MATRIX: {
687 bv->lockedInsetStoreUndo(Undo::EDIT);
692 istringstream is(STRCONV(argument));
693 is >> m >> n >> v_align >> h_align;
697 mathcursor->niceInsert(
698 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
699 updateLocal(bv, true);
703 case LFUN_SUPERSCRIPT:
706 bv->lockedInsetStoreUndo(Undo::EDIT);
707 mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
708 updateLocal(bv, true);
712 case LFUN_MATH_DELIM:
714 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
716 string rs = split(cmd.argument, ls, ' ');
717 // Reasonable default values
723 bv->lockedInsetStoreUndo(Undo::EDIT);
724 mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
725 updateLocal(bv, true);
729 case LFUN_PROTECTEDSPACE:
730 case LFUN_MATH_SPACE:
731 bv->lockedInsetStoreUndo(Undo::EDIT);
732 mathcursor->insert(MathAtom(new MathSpaceInset(",")));
733 updateLocal(bv, true);
737 bv->owner()->message(_("Invalid action in math mode!"));
741 case LFUN_EXEC_COMMAND:
742 result = UNDISPATCHED;
746 // interpret this as if a backslash was typed
747 bv->lockedInsetStoreUndo(Undo::EDIT);
748 mathcursor->interpret('\\');
749 updateLocal(bv, true);
752 case LFUN_BREAKPARAGRAPH:
753 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
754 case LFUN_BREAKPARAGRAPH_SKIP:
758 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
759 // handling such that "self-insert" works on "arbitrary stuff" too, and
760 // math-insert only handles special math things like "matrix".
761 case LFUN_INSERT_MATH:
762 bv->lockedInsetStoreUndo(Undo::EDIT);
763 mathcursor->niceInsert(argument);
764 updateLocal(bv, true);
768 case LFUN_SELFINSERT:
769 if (!argument.empty()) {
770 bv->lockedInsetStoreUndo(Undo::EDIT);
771 if (argument.size() == 1)
772 result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
774 mathcursor->insert(asArray(argument));
775 updateLocal(bv, true);
779 case LFUN_MATH_PANEL:
780 result = UNDISPATCHED;
784 if (mathcursor->selection())
785 mathcursor->selClear();
787 result = UNDISPATCHED;
790 case LFUN_INSET_TOGGLE:
791 mathcursor->insetToggle();
792 updateLocal(bv, true);
795 case LFUN_REF_INSERT:
796 //if (argument.empty()) {
797 // InsetCommandParams p("ref");
798 // owner_->getDialogs().createRef(p.getAsString());
800 // InsetCommandParams p;
801 // p.setFromString(argument);
803 // InsetRef * inset = new InsetRef(p, *buffer_);
804 // if (!insertInset(inset))
807 // updateInset(inset, true);
810 if (cmd.argument.empty()) {
811 InsetCommandParams p("ref");
812 bv->owner()->getDialogs().createRef(p.getAsString());
814 //mathcursor->handleNest(new InsetRef2);
815 //mathcursor->insert(arg);
816 mathcursor->insert(MathAtom(new RefInset(cmd.argument)));
818 updateLocal(bv, true);
822 result = UNDISPATCHED;
825 mathcursor->normalize();
828 lyx::Assert(mathcursor);
830 if (mathcursor->selection() || was_selection)
831 toggleInsetSelection(bv);
833 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
834 result == UNDISPATCHED) {
838 cmd.view()->stuffClipboard(mathcursor->grabSelection());
840 releaseMathCursor(bv);
841 bv->unlockInset(this);
843 bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
846 return result; // original version
850 void InsetFormulaBase::revealCodes(BufferView * bv) const
854 bv->owner()->message(mathcursor->info());
857 // write something to the minibuffer
858 // translate to latex
859 mathcursor->markInsert();
862 string str = os.str();
863 mathcursor->markErase();
864 string::size_type pos = 0;
866 for (string::iterator it = str.begin(); it != str.end(); ++it) {
869 else if (*it == '\0') {
871 pos = it - str.begin();
877 res = res.substr(pos - 30);
879 res = res.substr(0, 60);
880 bv->owner()->message(res);
885 Inset::Code InsetFormulaBase::lyxCode() const
887 return Inset::MATH_CODE;
891 int InsetFormulaBase::ylow() const
893 return yo_ - ascent(view(), font_);
897 int InsetFormulaBase::yhigh() const
899 return yo_ + descent(view(), font_);
903 int InsetFormulaBase::xlow() const
909 int InsetFormulaBase::xhigh() const
911 return xo_ + width(view(), font_);
915 /////////////////////////////////////////////////////////////////////
918 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
924 static InsetFormulaBase * lastformula = 0;
925 static MathIterator current = MathIterator(ibegin(par().nucleus()));
927 static string laststr;
929 if (lastformula != this || laststr != str) {
930 //lyxerr << "reset lastformula to " << this << "\n";
933 current = ibegin(par().nucleus());
935 mathed_parse_cell(ar, str);
939 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
941 for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
942 if (it.cell().matchpart(ar, it.back().pos_)) {
943 bv->unlockInset(bv->theLockingInset());
944 if (!bv->lockInset(this)) {
945 lyxerr << "Cannot lock inset" << endl;
949 mathcursor = new MathCursor(this, true);
951 mathcursor->setSelection(it, ar.size());
954 updateLocal(bv, false);
959 //lyxerr << "not found!\n";
965 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
968 lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
969 return searchForward(bv, what, a, b);
973 bool InsetFormulaBase::display() const
975 return par()->asHullInset() && par()->asHullInset()->display();
979 string InsetFormulaBase::selectionAsString() const
981 return mathcursor ? mathcursor->grabSelection() : string();
984 /////////////////////////////////////////////////////////////////////
987 void mathDispatchCreation(FuncRequest const & cmd, bool display)
989 BufferView * bv = cmd.view();
990 // use selection if available..
992 //if (action == LFUN_MATH_IMPORT_SELECTION)
996 string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
999 InsetFormula * f = new InsetFormula(bv);
1000 if (openNewInset(bv, f)) {
1001 bv->theLockingInset()->
1002 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1003 // don't do that also for LFUN_MATH_MODE unless you want end up with
1004 // always changing to mathrm when opening an inlined inset
1005 // -- I really hate "LyXfunc overloading"...
1007 f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
1008 f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
1011 // create a macro if we see "\\newcommand" somewhere, and an ordinary
1012 // formula otherwise
1013 InsetFormulaBase * f;
1014 if (sel.find("\\newcommand") == string::npos &&
1015 sel.find("\\def") == string::npos)
1016 f = new InsetFormula(sel);
1018 f = new InsetFormulaMacro(sel);
1019 bv->getLyXText()->cutSelection(bv);
1020 openNewInset(bv, f);
1022 cmd.message(N_("Math editor mode"));
1026 void mathDispatch(FuncRequest const & cmd)
1028 BufferView * bv = cmd.view();
1029 if (!bv->available())
1032 switch (cmd.action) {
1034 case LFUN_MATH_DISPLAY:
1035 mathDispatchCreation(cmd, true);
1038 case LFUN_MATH_MODE:
1039 mathDispatchCreation(cmd, false);
1042 case LFUN_MATH_IMPORT_SELECTION:
1043 mathDispatchCreation(cmd, false);
1046 case LFUN_MATH_MACRO:
1047 if (cmd.argument.empty())
1048 cmd.errorMessage(N_("Missing argument"));
1050 string s = cmd.argument;
1051 string const s1 = token(s, ' ', 1);
1052 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1053 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1058 case LFUN_INSERT_MATH:
1059 case LFUN_INSERT_MATRIX:
1060 case LFUN_MATH_DELIM: {
1061 InsetFormula * f = new InsetFormula(bv);
1062 if (openNewInset(bv, f)) {
1063 bv->theLockingInset()->
1064 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1065 bv->theLockingInset()->localDispatch(cmd);