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 BufferView * InsetFormulaBase::view() const
145 return view_.lock().get();
149 void InsetFormulaBase::validate(LaTeXFeatures &) const
153 void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
160 void InsetFormulaBase::metrics(BufferView * bv) const
163 view_ = bv->owner()->view();
165 mi.base.style = LM_ST_TEXT;
166 mi.base.font = font_;
167 mi.base.font.setColor(LColor::math);
172 string const InsetFormulaBase::editMessage() const
174 return _("Math editor mode");
178 void InsetFormulaBase::edit(BufferView * bv, int x, int y, mouse_button::state)
180 if (!bv->lockInset(this))
181 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
182 releaseMathCursor(bv);
183 mathcursor = new MathCursor(this, true);
185 mathcursor->setPos(x + xo_, y + yo_);
186 // if that is removed, we won't get the magenta box when entering an
187 // inset for the first time
188 bv->updateInset(this, false);
192 void InsetFormulaBase::edit(BufferView * bv, bool front)
194 if (!bv->lockInset(this))
195 lyxerr << "Cannot lock math inset in edit call!\n";
196 releaseMathCursor(bv);
197 mathcursor = new MathCursor(this, front);
199 bv->updateInset(this, false);
203 void InsetFormulaBase::insetUnlock(BufferView * bv)
206 if (mathcursor->inMacroMode()) {
207 mathcursor->macroModeClose();
208 updateLocal(bv, true);
210 releaseMathCursor(bv);
213 bv->updateInset(this, false);
217 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
219 // calling metrics here destroys the cached xo,yo positions e.g. in
220 // MathParboxinset. And it would be too expensive anyway...
223 lyxerr << "getCursorPos - should not happen";
227 mathcursor->getPos(x, y);
228 x = mathcursor->targetX();
231 //lyxerr << "getCursorPos: " << x << ' ' << y << endl;
235 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
238 lyxerr[Debug::MATHED] << "toggleInsetCursor impossible" << endl;
241 //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
242 if (isCursorVisible())
249 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
252 lyxerr << "showInsetCursor impossible" << endl;
255 if (isCursorVisible())
258 mathcursor->getPos(x, y);
259 math_font_max_dim(font_, asc, des);
260 bv->showLockedInsetCursor(x, y - yo_, asc, des);
261 setCursorVisible(true);
262 //lyxerr << "showInsetCursor: " << x << ' ' << y << endl;
266 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
270 if (!isCursorVisible())
272 bv->hideLockedInsetCursor();
273 setCursorVisible(false);
274 //lyxerr << "hideInsetCursor: " << endl;
278 void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
283 math_font_max_dim(font_, asc, des);
284 getCursorPos(bv, x, y);
286 //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl;
287 bv->fitLockedInsetCursor(x, y, asc, des);
291 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
294 bv->updateInset(this, false);
298 vector<string> const InsetFormulaBase::getLabelList() const
300 return vector<string>();
304 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
306 bv->updateInset(this, dirty);
310 dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
315 BufferView * bv = cmd.view();
318 bv->updateInset(this, false);
319 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
321 if (cmd.button() == mouse_button::button3) {
322 // try to dispatch to enclosed insets first
323 if (mathcursor->dispatch(cmd) == UNDISPATCHED) {
324 // launch math panel for right mouse button
325 lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
326 bv->owner()->getDialogs().showMathPanel();
331 if (cmd.button() == mouse_button::button2) {
332 mathcursor->selClear();
333 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
334 mathcursor->insert(asArray(bv->getClipboard()));
335 bv->updateInset(this, true);
339 if (cmd.button() == mouse_button::button1) {
340 // try to dispatch to enclosed insets first
341 mathcursor->dispatch(cmd);
342 cmd.view()->stuffClipboard(mathcursor->grabSelection());
343 // try to set the cursor
345 //mathcursor = new MathCursor(this, x == 0);
347 //mathcursor->setPos(x + xo_, y + yo_);
355 dispatch_result InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
357 BufferView * bv = cmd.view();
358 //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
360 if (!mathcursor || mathcursor->formula() != this) {
361 lyxerr[Debug::MATHED] << "re-create cursor" << endl;
362 releaseMathCursor(bv);
363 mathcursor = new MathCursor(this, cmd.x == 0);
365 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
368 if (cmd.button() == mouse_button::button3) {
369 mathcursor->dispatch(cmd);
373 if (cmd.button() == mouse_button::button1) {
376 mathcursor->selClear();
377 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
378 mathcursor->dispatch(cmd);
382 bv->updateInset(this, false);
387 dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
392 if (mathcursor->dispatch(FuncRequest(cmd)) != UNDISPATCHED)
395 // only select with button 1
396 if (cmd.button() != mouse_button::button1)
399 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
405 if (!mathcursor->selection())
406 mathcursor->selStart();
408 BufferView * bv = cmd.view();
410 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
412 bv->updateInset(this, false);
417 dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
419 //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
420 // << " arg: '" << cmd.argument
421 // << " x: '" << cmd.x
422 // << " y: '" << cmd.y
423 // << "' button: " << cmd.button() << endl;
425 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
426 bool remove_inset = false;
428 switch (cmd.action) {
429 case LFUN_MOUSE_PRESS:
430 //lyxerr << "Mouse single press\n";
431 return lfunMousePress(cmd);
432 case LFUN_MOUSE_MOTION:
433 //return lfunMouseMotion(cmd);
434 case LFUN_MOUSE_RELEASE:
435 //lyxerr << "Mouse single release\n";
436 return lfunMouseRelease(cmd);
437 case LFUN_MOUSE_DOUBLE:
438 //lyxerr << "Mouse double\n";
439 return localDispatch(FuncRequest(LFUN_WORDSEL));
447 BufferView * bv = cmd.view();
448 string argument = cmd.argument;
449 RESULT result = DISPATCHED;
451 bool was_macro = mathcursor->inMacroMode();
452 bool was_selection = mathcursor->selection();
456 mathcursor->normalize();
459 switch (cmd.action) {
461 case LFUN_MATH_MUTATE:
462 case LFUN_MATH_DISPLAY:
463 case LFUN_MATH_NUMBER:
464 case LFUN_MATH_NONUMBER:
467 case LFUN_DELETE_LINE_FORWARD:
468 case LFUN_INSERT_LABEL:
469 case LFUN_MATH_EXTERN:
470 case LFUN_TABULAR_FEATURE:
471 case LFUN_PASTESELECTION:
472 case LFUN_MATH_LIMITS:
473 bv->lockedInsetStoreUndo(Undo::EDIT);
474 mathcursor->dispatch(cmd);
475 updateLocal(bv, true);
479 sel = true; // fall through...
481 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
482 //lyxerr << "calling scroll 20\n";
484 updateLocal(bv, false);
485 // write something to the minibuffer
486 //bv->owner()->message(mathcursor->info());
490 sel = true; // fall through
492 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
493 updateLocal(bv, false);
497 sel = true; // fall through
499 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
500 updateLocal(bv, false);
504 sel = true; // fall through
506 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
507 updateLocal(bv, false);
511 mathcursor->home(false);
512 mathcursor->end(true);
513 updateLocal(bv, false);
516 case LFUN_UP_PARAGRAPHSEL:
517 case LFUN_UP_PARAGRAPH:
518 case LFUN_DOWN_PARAGRAPHSEL:
519 case LFUN_DOWN_PARAGRAPH:
521 updateLocal(bv, false);
525 case LFUN_WORDLEFTSEL:
526 sel = true; // fall through
529 result = mathcursor->home(sel) ? DISPATCHED : FINISHED;
530 updateLocal(bv, false);
534 case LFUN_WORDRIGHTSEL:
535 sel = true; // fall through
538 result = mathcursor->end(sel) ? DISPATCHED : FINISHED_RIGHT;
539 updateLocal(bv, false);
544 case LFUN_BEGINNINGBUFSEL:
545 case LFUN_BEGINNINGBUF:
547 updateLocal(bv, false);
554 result = FINISHED_RIGHT;
555 updateLocal(bv, false);
559 mathcursor->idxNext();
560 updateLocal(bv, false);
564 mathcursor->idxPrev();
565 updateLocal(bv, false);
568 case LFUN_DELETE_WORD_BACKWARD:
570 bv->lockedInsetStoreUndo(Undo::EDIT);
571 if (mathcursor->backspace()) {
577 updateLocal(bv, true);
580 case LFUN_DELETE_WORD_FORWARD:
582 bv->lockedInsetStoreUndo(Undo::EDIT);
583 if (mathcursor->erase()) {
589 updateLocal(bv, true);
593 // sprintf(dispatch_buffer, "%d %d",);
594 // dispatch_result = dispatch_buffer;
597 lyxerr << "LFUN_SETXY broken!\n";
600 istringstream is(cmd.argument.c_str());
602 mathcursor->setPos(x, y);
603 updateLocal(bv, false);
609 mathcursor->macroModeClose();
610 bv->lockedInsetStoreUndo(Undo::EDIT);
611 mathcursor->selPaste();
612 updateLocal(bv, true);
616 bv->lockedInsetStoreUndo(Undo::DELETE);
617 mathcursor->selCut();
618 updateLocal(bv, true);
622 mathcursor->selCopy();
626 // Special casing for superscript in case of LyX handling
628 case LFUN_CIRCUMFLEX:
629 if (cmd.argument.empty()) {
630 // do superscript if LyX handles
632 bv->lockedInsetStoreUndo(Undo::EDIT);
633 mathcursor->script(true);
634 updateLocal(bv, true);
651 case LFUN_HUNG_UMLAUT:
655 case LFUN_GREEK_TOGGLE: handleFont(bv, cmd.argument, "lyxgreek"); break;
656 case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break;
657 case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break;
658 case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break;
659 case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break;
660 case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break;
661 case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break;
662 case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break;
663 case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break;
664 case LFUN_FREE: handleFont(bv, cmd.argument, "textrm"); break;
665 case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break;
668 handleFont(bv, cmd.argument, "lyxgreek1");
669 if (cmd.argument.size())
670 mathcursor->insert(asArray(cmd.argument));
674 if (mathcursor->currentMode() == MathInset::TEXT_MODE) {
675 mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
676 updateLocal(bv, true);
678 handleFont(bv, cmd.argument, "textrm");
680 //bv->owner()->message(_("math text mode toggled"));
686 bv->lockedInsetStoreUndo(Undo::EDIT);
687 mathcursor->setSize(arg);
688 updateLocal(bv, true);
693 case LFUN_INSERT_MATRIX: {
694 bv->lockedInsetStoreUndo(Undo::EDIT);
699 istringstream is(STRCONV(argument));
700 is >> m >> n >> v_align >> h_align;
704 mathcursor->niceInsert(
705 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
706 updateLocal(bv, true);
710 case LFUN_SUPERSCRIPT:
713 bv->lockedInsetStoreUndo(Undo::EDIT);
714 mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
715 updateLocal(bv, true);
719 case LFUN_MATH_DELIM:
721 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
723 string rs = split(cmd.argument, ls, ' ');
724 // Reasonable default values
730 bv->lockedInsetStoreUndo(Undo::EDIT);
731 mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
732 updateLocal(bv, true);
736 case LFUN_PROTECTEDSPACE:
737 case LFUN_MATH_SPACE:
738 bv->lockedInsetStoreUndo(Undo::EDIT);
739 mathcursor->insert(MathAtom(new MathSpaceInset(",")));
740 updateLocal(bv, true);
744 bv->owner()->message(_("Invalid action in math mode!"));
748 case LFUN_EXEC_COMMAND:
749 result = UNDISPATCHED;
753 // interpret this as if a backslash was typed
754 bv->lockedInsetStoreUndo(Undo::EDIT);
755 mathcursor->interpret('\\');
756 updateLocal(bv, true);
759 case LFUN_BREAKPARAGRAPH:
760 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
761 case LFUN_BREAKPARAGRAPH_SKIP:
765 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
766 // handling such that "self-insert" works on "arbitrary stuff" too, and
767 // math-insert only handles special math things like "matrix".
768 case LFUN_INSERT_MATH:
769 bv->lockedInsetStoreUndo(Undo::EDIT);
770 mathcursor->niceInsert(argument);
771 updateLocal(bv, true);
775 case LFUN_SELFINSERT:
776 if (!argument.empty()) {
777 bv->lockedInsetStoreUndo(Undo::EDIT);
778 if (argument.size() == 1)
779 result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
781 mathcursor->insert(asArray(argument));
782 updateLocal(bv, true);
786 case LFUN_MATH_PANEL:
787 result = UNDISPATCHED;
791 if (mathcursor->selection())
792 mathcursor->selClear();
794 result = UNDISPATCHED;
797 case LFUN_INSET_TOGGLE:
798 mathcursor->insetToggle();
799 updateLocal(bv, true);
802 case LFUN_DIALOG_SHOW_NEW_INSET: {
803 string const & name = argument;
807 data = tmp.createDialogStr(name);
811 result = UNDISPATCHED;
813 bv->owner()->getDialogs().show(name, data, 0);
818 case LFUN_INSET_APPLY: {
819 string const name = cmd.getArg(0);
821 bv->owner()->getDialogs().getOpenInset(name);
824 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
825 result = base->localDispatch(fr);
828 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
829 mathcursor->insert(ar);
832 result = UNDISPATCHED;
835 if (result == DISPATCHED)
836 updateLocal(bv, true);
841 result = UNDISPATCHED;
844 mathcursor->normalize();
847 lyx::Assert(mathcursor);
849 if (mathcursor->selection() || was_selection)
850 toggleInsetSelection(bv);
852 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
853 result == UNDISPATCHED) {
857 cmd.view()->stuffClipboard(mathcursor->grabSelection());
859 releaseMathCursor(bv);
860 bv->unlockInset(this);
862 bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
865 return result; // original version
869 void InsetFormulaBase::revealCodes(BufferView * bv) const
873 bv->owner()->message(mathcursor->info());
876 // write something to the minibuffer
877 // translate to latex
878 mathcursor->markInsert();
881 string str = os.str();
882 mathcursor->markErase();
883 string::size_type pos = 0;
885 for (string::iterator it = str.begin(); it != str.end(); ++it) {
888 else if (*it == '\0') {
890 pos = it - str.begin();
896 res = res.substr(pos - 30);
898 res = res.substr(0, 60);
899 bv->owner()->message(res);
904 Inset::Code InsetFormulaBase::lyxCode() const
906 return Inset::MATH_CODE;
910 int InsetFormulaBase::ylow() const
912 return yo_ - ascent(view(), font_);
916 int InsetFormulaBase::yhigh() const
918 return yo_ + descent(view(), font_);
922 int InsetFormulaBase::xlow() const
928 int InsetFormulaBase::xhigh() const
930 return xo_ + width(view(), font_);
934 /////////////////////////////////////////////////////////////////////
937 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
943 static InsetFormulaBase * lastformula = 0;
944 static MathIterator current = MathIterator(ibegin(par().nucleus()));
946 static string laststr;
948 if (lastformula != this || laststr != str) {
949 //lyxerr << "reset lastformula to " << this << "\n";
952 current = ibegin(par().nucleus());
954 mathed_parse_cell(ar, str);
958 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
960 for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
961 if (it.cell().matchpart(ar, it.back().pos_)) {
962 bv->unlockInset(bv->theLockingInset());
963 if (!bv->lockInset(this)) {
964 lyxerr << "Cannot lock inset" << endl;
968 mathcursor = new MathCursor(this, true);
970 mathcursor->setSelection(it, ar.size());
973 updateLocal(bv, false);
978 //lyxerr << "not found!\n";
984 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
987 lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
988 return searchForward(bv, what, a, b);
992 bool InsetFormulaBase::display() const
994 return par()->asHullInset() && par()->asHullInset()->display();
998 string InsetFormulaBase::selectionAsString() const
1000 return mathcursor ? mathcursor->grabSelection() : string();
1003 /////////////////////////////////////////////////////////////////////
1006 void mathDispatchCreation(FuncRequest const & cmd, bool display)
1008 BufferView * bv = cmd.view();
1009 // use selection if available..
1011 //if (action == LFUN_MATH_IMPORT_SELECTION)
1015 string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
1018 InsetFormula * f = new InsetFormula(bv);
1019 if (openNewInset(bv, f)) {
1020 bv->theLockingInset()->
1021 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1022 // don't do that also for LFUN_MATH_MODE unless you want end up with
1023 // always changing to mathrm when opening an inlined inset
1024 // -- I really hate "LyXfunc overloading"...
1026 f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
1027 f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
1030 // create a macro if we see "\\newcommand" somewhere, and an ordinary
1031 // formula otherwise
1032 InsetFormulaBase * f;
1033 if (sel.find("\\newcommand") == string::npos &&
1034 sel.find("\\def") == string::npos)
1035 f = new InsetFormula(sel);
1037 f = new InsetFormulaMacro(sel);
1038 bv->getLyXText()->cutSelection(bv);
1039 openNewInset(bv, f);
1041 cmd.message(N_("Math editor mode"));
1045 void mathDispatch(FuncRequest const & cmd)
1047 BufferView * bv = cmd.view();
1048 if (!bv->available())
1051 switch (cmd.action) {
1053 case LFUN_MATH_DISPLAY:
1054 mathDispatchCreation(cmd, true);
1057 case LFUN_MATH_MODE:
1058 mathDispatchCreation(cmd, false);
1061 case LFUN_MATH_IMPORT_SELECTION:
1062 mathDispatchCreation(cmd, false);
1065 case LFUN_MATH_MACRO:
1066 if (cmd.argument.empty())
1067 cmd.errorMessage(N_("Missing argument"));
1069 string s = cmd.argument;
1070 string const s1 = token(s, ' ', 1);
1071 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1072 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1077 case LFUN_INSERT_MATH:
1078 case LFUN_INSERT_MATRIX:
1079 case LFUN_MATH_DELIM: {
1080 InsetFormula * f = new InsetFormula(bv);
1081 if (openNewInset(bv, f)) {
1082 bv->theLockingInset()->
1083 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1084 bv->theLockingInset()->localDispatch(cmd);