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 "ref_inset.h"
62 MathCursor * mathcursor = 0;
73 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
75 if (!bv->insertInset(new_inset)) {
79 new_inset->edit(bv, true);
88 InsetFormulaBase::InsetFormulaBase()
89 : font_(), xo_(0), yo_(0)
91 // This is needed as long the math parser is not re-entrant
93 //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
94 //lyxerr << "sizeof MathMetricsInfo: " << sizeof(MathMetricsInfo) << "\n";
95 //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << "\n";
96 //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << "\n";
100 // simply scrap this function if you want
101 void InsetFormulaBase::mutateToText()
104 // translate to latex
106 latex(NULL, os, false, false);
107 string str = os.str();
110 LyXText * lt = view_->getLyXText();
111 string::const_iterator cit = str.begin();
112 string::const_iterator end = str.end();
113 for (; cit != end; ++cit)
114 view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
117 //view_->owner()->dispatch(LFUN_ESCAPE);
122 void InsetFormulaBase::handleFont
123 (BufferView * bv, string const & arg, string const & font)
125 // this whole function is a hack and won't work for incremental font
127 bv->lockedInsetStoreUndo(Undo::EDIT);
128 if (mathcursor->par()->name() == font) {
129 mathcursor->handleFont(font);
130 updateLocal(bv, true);
132 bool sel = mathcursor->selection();
134 updateLocal(bv, true);
135 mathcursor->handleNest(createMathInset(font));
136 mathcursor->insert(arg);
138 updateLocal(bv, false);
143 // Check if uses AMS macros
144 void InsetFormulaBase::validate(LaTeXFeatures &) const
148 void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
155 void InsetFormulaBase::metrics(BufferView * bv) const
158 view_ = bv->owner()->view();
160 mi.base.style = LM_ST_TEXT;
161 mi.base.font = font_;
162 mi.base.font.setColor(LColor::math);
167 string const InsetFormulaBase::editMessage() const
169 return _("Math editor mode");
173 void InsetFormulaBase::edit(BufferView * bv, int x, int y, mouse_button::state)
175 if (!bv->lockInset(this))
176 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
177 releaseMathCursor(bv);
178 mathcursor = new MathCursor(this, true);
180 mathcursor->setPos(x + xo_, y + yo_);
181 // if that is removed, we won't get the magenta box when entering an
182 // inset for the first time
183 bv->updateInset(this, false);
187 void InsetFormulaBase::edit(BufferView * bv, bool front)
189 if (!bv->lockInset(this))
190 lyxerr << "Cannot lock math inset in edit call!\n";
191 releaseMathCursor(bv);
192 mathcursor = new MathCursor(this, front);
194 bv->updateInset(this, false);
198 void InsetFormulaBase::insetUnlock(BufferView * bv)
201 if (mathcursor->inMacroMode()) {
202 mathcursor->macroModeClose();
203 updateLocal(bv, true);
205 releaseMathCursor(bv);
208 bv->updateInset(this, false);
212 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
214 // calling metrics here destroys the cached xo,yo positions e.g. in
215 // MathParboxinset. And it would be too expensive anyway...
218 lyxerr << "getCursorPos - should not happen";
222 mathcursor->getPos(x, y);
223 x = mathcursor->targetX();
226 //lyxerr << "getCursorPos: " << x << ' ' << y << endl;
230 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
233 lyxerr[Debug::MATHED] << "toggleInsetCursor impossible" << endl;
236 //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
237 if (isCursorVisible())
244 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
247 lyxerr << "showInsetCursor impossible" << endl;
250 if (isCursorVisible())
253 mathcursor->getPos(x, y);
254 math_font_max_dim(font_, asc, des);
255 bv->showLockedInsetCursor(x, y - yo_, asc, des);
256 setCursorVisible(true);
257 //lyxerr << "showInsetCursor: " << x << ' ' << y << endl;
261 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
265 if (!isCursorVisible())
267 bv->hideLockedInsetCursor();
268 setCursorVisible(false);
269 //lyxerr << "hideInsetCursor: " << endl;
273 void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
278 math_font_max_dim(font_, asc, des);
279 getCursorPos(bv, x, y);
281 //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl;
282 bv->fitLockedInsetCursor(x, y, asc, des);
286 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
289 bv->updateInset(this, false);
293 vector<string> const InsetFormulaBase::getLabelList() const
295 return vector<string>();
299 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
301 bv->updateInset(this, dirty);
305 dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
310 BufferView * bv = cmd.view();
313 bv->updateInset(this, false);
314 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
316 if (cmd.button() == mouse_button::button3) {
317 // try to dispatch to enclosed insets first
318 if (mathcursor->dispatch(cmd) == UNDISPATCHED) {
319 // launch math panel for right mouse button
320 lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
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 dispatch_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 dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
387 if (mathcursor->dispatch(FuncRequest(cmd)) != 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 dispatch_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)
421 bool remove_inset = false;
423 switch (cmd.action) {
424 case LFUN_MOUSE_PRESS:
425 //lyxerr << "Mouse single press\n";
426 return lfunMousePress(cmd);
427 case LFUN_MOUSE_MOTION:
428 //return lfunMouseMotion(cmd);
429 case LFUN_MOUSE_RELEASE:
430 lyxerr << "Mouse single release\n";
431 return lfunMouseRelease(cmd);
432 case LFUN_MOUSE_DOUBLE:
433 //lyxerr << "Mouse double\n";
434 return localDispatch(FuncRequest(LFUN_WORDSEL));
442 BufferView * bv = cmd.view();
443 string argument = cmd.argument;
444 RESULT result = DISPATCHED;
446 bool was_macro = mathcursor->inMacroMode();
447 bool was_selection = mathcursor->selection();
451 mathcursor->normalize();
454 switch (cmd.action) {
456 case LFUN_MATH_MUTATE:
457 case LFUN_MATH_DISPLAY:
458 case LFUN_MATH_NUMBER:
459 case LFUN_MATH_NONUMBER:
462 case LFUN_DELETE_LINE_FORWARD:
463 case LFUN_INSERT_LABEL:
464 case LFUN_MATH_EXTERN:
465 case LFUN_TABULAR_FEATURE:
466 case LFUN_PASTESELECTION:
467 case LFUN_MATH_LIMITS:
468 bv->lockedInsetStoreUndo(Undo::EDIT);
469 mathcursor->dispatch(cmd);
470 updateLocal(bv, true);
474 sel = true; // fall through...
476 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
477 //lyxerr << "calling scroll 20\n";
479 updateLocal(bv, false);
480 // write something to the minibuffer
481 //bv->owner()->message(mathcursor->info());
485 sel = true; // fall through
487 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
488 updateLocal(bv, false);
492 sel = true; // fall through
494 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
495 updateLocal(bv, false);
499 sel = true; // fall through
501 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
502 updateLocal(bv, false);
506 mathcursor->home(false);
507 mathcursor->end(true);
508 updateLocal(bv, false);
511 case LFUN_UP_PARAGRAPHSEL:
512 case LFUN_UP_PARAGRAPH:
513 case LFUN_DOWN_PARAGRAPHSEL:
514 case LFUN_DOWN_PARAGRAPH:
516 updateLocal(bv, false);
520 case LFUN_WORDLEFTSEL:
521 sel = true; // fall through
524 result = mathcursor->home(sel) ? DISPATCHED : FINISHED;
525 updateLocal(bv, false);
529 case LFUN_WORDRIGHTSEL:
530 sel = true; // fall through
533 result = mathcursor->end(sel) ? DISPATCHED : FINISHED_RIGHT;
534 updateLocal(bv, false);
539 case LFUN_BEGINNINGBUFSEL:
540 case LFUN_BEGINNINGBUF:
542 updateLocal(bv, false);
549 result = FINISHED_RIGHT;
550 updateLocal(bv, false);
554 mathcursor->idxNext();
555 updateLocal(bv, false);
559 mathcursor->idxPrev();
560 updateLocal(bv, false);
563 case LFUN_DELETE_WORD_BACKWARD:
565 bv->lockedInsetStoreUndo(Undo::EDIT);
566 if (mathcursor->backspace()) {
572 updateLocal(bv, true);
575 case LFUN_DELETE_WORD_FORWARD:
577 bv->lockedInsetStoreUndo(Undo::EDIT);
578 if (mathcursor->erase()) {
584 updateLocal(bv, true);
588 // sprintf(dispatch_buffer, "%d %d",);
589 // dispatch_result = dispatch_buffer;
592 lyxerr << "LFUN_SETXY broken!\n";
595 istringstream is(cmd.argument.c_str());
597 mathcursor->setPos(x, y);
598 updateLocal(bv, false);
604 mathcursor->macroModeClose();
605 bv->lockedInsetStoreUndo(Undo::EDIT);
606 mathcursor->selPaste();
607 updateLocal(bv, true);
611 bv->lockedInsetStoreUndo(Undo::DELETE);
612 mathcursor->selCut();
613 updateLocal(bv, true);
617 mathcursor->selCopy();
621 // Special casing for superscript in case of LyX handling
623 case LFUN_CIRCUMFLEX:
624 if (cmd.argument.empty()) {
625 // do superscript if LyX handles
627 bv->lockedInsetStoreUndo(Undo::EDIT);
628 mathcursor->script(true);
629 updateLocal(bv, true);
646 case LFUN_HUNG_UMLAUT:
650 case LFUN_GREEK_TOGGLE: handleFont(bv, cmd.argument, "lyxgreek"); break;
651 case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break;
652 case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break;
653 case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break;
654 case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break;
655 case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break;
656 case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break;
657 case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break;
658 case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break;
659 case LFUN_FREE: handleFont(bv, cmd.argument, "textrm"); break;
660 case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break;
663 handleFont(bv, cmd.argument, "lyxgreek1");
664 if (cmd.argument.size())
665 mathcursor->insert(asArray(cmd.argument));
669 if (mathcursor->currentMode() == MathInset::TEXT_MODE) {
670 mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
671 updateLocal(bv, true);
673 handleFont(bv, cmd.argument, "textrm");
675 //bv->owner()->message(_("math text mode toggled"));
681 bv->lockedInsetStoreUndo(Undo::EDIT);
682 mathcursor->setSize(arg);
683 updateLocal(bv, true);
688 case LFUN_INSERT_MATRIX: {
689 bv->lockedInsetStoreUndo(Undo::EDIT);
694 istringstream is(STRCONV(argument));
695 is >> m >> n >> v_align >> h_align;
699 mathcursor->niceInsert(
700 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
701 updateLocal(bv, true);
705 case LFUN_SUPERSCRIPT:
708 bv->lockedInsetStoreUndo(Undo::EDIT);
709 mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
710 updateLocal(bv, true);
714 case LFUN_MATH_DELIM:
716 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
718 string rs = split(cmd.argument, ls, ' ');
719 // Reasonable default values
725 bv->lockedInsetStoreUndo(Undo::EDIT);
726 mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
727 updateLocal(bv, true);
731 case LFUN_PROTECTEDSPACE:
732 case LFUN_MATH_SPACE:
733 bv->lockedInsetStoreUndo(Undo::EDIT);
734 mathcursor->insert(MathAtom(new MathSpaceInset(",")));
735 updateLocal(bv, true);
739 bv->owner()->message(_("Invalid action in math mode!"));
743 case LFUN_EXEC_COMMAND:
744 result = UNDISPATCHED;
748 // interpret this as if a backslash was typed
749 bv->lockedInsetStoreUndo(Undo::EDIT);
750 mathcursor->interpret('\\');
751 updateLocal(bv, true);
754 case LFUN_BREAKPARAGRAPH:
755 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
756 case LFUN_BREAKPARAGRAPH_SKIP:
760 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
761 // handling such that "self-insert" works on "arbitrary stuff" too, and
762 // math-insert only handles special math things like "matrix".
763 case LFUN_INSERT_MATH:
764 bv->lockedInsetStoreUndo(Undo::EDIT);
765 mathcursor->niceInsert(argument);
766 updateLocal(bv, true);
770 case LFUN_SELFINSERT:
771 if (!argument.empty()) {
772 bv->lockedInsetStoreUndo(Undo::EDIT);
773 if (argument.size() == 1)
774 result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
776 mathcursor->insert(asArray(argument));
777 updateLocal(bv, true);
781 case LFUN_MATH_PANEL:
782 result = UNDISPATCHED;
786 if (mathcursor->selection())
787 mathcursor->selClear();
789 result = UNDISPATCHED;
792 case LFUN_INSET_TOGGLE:
793 mathcursor->insetToggle();
794 updateLocal(bv, true);
797 case LFUN_DIALOG_SHOW_NEW_INSET: {
798 string const & name = argument;
800 string data = "LatexCommand \\ref{}\n\\end_inset\n\n";
801 bv->owner()->getDialogs().show(name, data, 0);
803 result = UNDISPATCHED;
807 case LFUN_REF_APPLY: {
809 bv->owner()->getDialogs().getOpenInset("ref");
812 result = base->localDispatch(cmd);
814 // Turn 'argument' into a temporary RefInset.
816 if (string2RefInset(argument, ar)) {
817 mathcursor->insert(ar);
819 result = UNDISPATCHED;
822 if (result == DISPATCHED)
823 updateLocal(bv, true);
828 result = UNDISPATCHED;
831 mathcursor->normalize();
834 lyx::Assert(mathcursor);
836 if (mathcursor->selection() || was_selection)
837 toggleInsetSelection(bv);
839 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
840 result == UNDISPATCHED) {
844 cmd.view()->stuffClipboard(mathcursor->grabSelection());
846 releaseMathCursor(bv);
847 bv->unlockInset(this);
849 bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
852 return result; // original version
856 void InsetFormulaBase::revealCodes(BufferView * bv) const
860 bv->owner()->message(mathcursor->info());
863 // write something to the minibuffer
864 // translate to latex
865 mathcursor->markInsert();
868 string str = os.str();
869 mathcursor->markErase();
870 string::size_type pos = 0;
872 for (string::iterator it = str.begin(); it != str.end(); ++it) {
875 else if (*it == '\0') {
877 pos = it - str.begin();
883 res = res.substr(pos - 30);
885 res = res.substr(0, 60);
886 bv->owner()->message(res);
891 Inset::Code InsetFormulaBase::lyxCode() const
893 return Inset::MATH_CODE;
897 int InsetFormulaBase::ylow() const
899 return yo_ - ascent(view(), font_);
903 int InsetFormulaBase::yhigh() const
905 return yo_ + descent(view(), font_);
909 int InsetFormulaBase::xlow() const
915 int InsetFormulaBase::xhigh() const
917 return xo_ + width(view(), font_);
921 /////////////////////////////////////////////////////////////////////
924 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
930 static InsetFormulaBase * lastformula = 0;
931 static MathIterator current = MathIterator(ibegin(par().nucleus()));
933 static string laststr;
935 if (lastformula != this || laststr != str) {
936 //lyxerr << "reset lastformula to " << this << "\n";
939 current = ibegin(par().nucleus());
941 mathed_parse_cell(ar, str);
945 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
947 for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
948 if (it.cell().matchpart(ar, it.back().pos_)) {
949 bv->unlockInset(bv->theLockingInset());
950 if (!bv->lockInset(this)) {
951 lyxerr << "Cannot lock inset" << endl;
955 mathcursor = new MathCursor(this, true);
957 mathcursor->setSelection(it, ar.size());
960 updateLocal(bv, false);
965 //lyxerr << "not found!\n";
971 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
974 lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
975 return searchForward(bv, what, a, b);
979 bool InsetFormulaBase::display() const
981 return par()->asHullInset() && par()->asHullInset()->display();
985 string InsetFormulaBase::selectionAsString() const
987 return mathcursor ? mathcursor->grabSelection() : string();
990 /////////////////////////////////////////////////////////////////////
993 void mathDispatchCreation(FuncRequest const & cmd, bool display)
995 BufferView * bv = cmd.view();
996 // use selection if available..
998 //if (action == LFUN_MATH_IMPORT_SELECTION)
1002 string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
1005 InsetFormula * f = new InsetFormula(bv);
1006 if (openNewInset(bv, f)) {
1007 bv->theLockingInset()->
1008 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1009 // don't do that also for LFUN_MATH_MODE unless you want end up with
1010 // always changing to mathrm when opening an inlined inset
1011 // -- I really hate "LyXfunc overloading"...
1013 f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
1014 f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
1017 // create a macro if we see "\\newcommand" somewhere, and an ordinary
1018 // formula otherwise
1019 InsetFormulaBase * f;
1020 if (sel.find("\\newcommand") == string::npos &&
1021 sel.find("\\def") == string::npos)
1022 f = new InsetFormula(sel);
1024 f = new InsetFormulaMacro(sel);
1025 bv->getLyXText()->cutSelection(bv);
1026 openNewInset(bv, f);
1028 cmd.message(N_("Math editor mode"));
1032 void mathDispatch(FuncRequest const & cmd)
1034 BufferView * bv = cmd.view();
1035 if (!bv->available())
1038 switch (cmd.action) {
1040 case LFUN_MATH_DISPLAY:
1041 mathDispatchCreation(cmd, true);
1044 case LFUN_MATH_MODE:
1045 mathDispatchCreation(cmd, false);
1048 case LFUN_MATH_IMPORT_SELECTION:
1049 mathDispatchCreation(cmd, false);
1052 case LFUN_MATH_MACRO:
1053 if (cmd.argument.empty())
1054 cmd.errorMessage(N_("Missing argument"));
1056 string s = cmd.argument;
1057 string const s1 = token(s, ' ', 1);
1058 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1059 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1064 case LFUN_INSERT_MATH:
1065 case LFUN_INSERT_MATRIX:
1066 case LFUN_MATH_DELIM: {
1067 InsetFormula * f = new InsetFormula(bv);
1068 if (openNewInset(bv, f)) {
1069 bv->theLockingInset()->
1070 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1071 bv->theLockingInset()->localDispatch(cmd);