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/insetcommand.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 dispatch_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) == UNDISPATCHED) {
320 // launch math panel for right mouse button
321 lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
322 bv->owner()->getDialogs().showMathPanel();
327 if (cmd.button() == mouse_button::button2) {
328 mathcursor->selClear();
329 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
330 mathcursor->insert(asArray(bv->getClipboard()));
331 bv->updateInset(this, true);
335 if (cmd.button() == mouse_button::button1) {
336 // try to dispatch to enclosed insets first
337 mathcursor->dispatch(cmd);
338 cmd.view()->stuffClipboard(mathcursor->grabSelection());
339 // try to set the cursor
341 //mathcursor = new MathCursor(this, x == 0);
343 //mathcursor->setPos(x + xo_, y + yo_);
351 dispatch_result InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
353 BufferView * bv = cmd.view();
354 //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
356 if (!mathcursor || mathcursor->formula() != this) {
357 lyxerr[Debug::MATHED] << "re-create cursor" << endl;
358 releaseMathCursor(bv);
359 mathcursor = new MathCursor(this, cmd.x == 0);
361 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
364 if (cmd.button() == mouse_button::button3) {
365 mathcursor->dispatch(cmd);
369 if (cmd.button() == mouse_button::button1) {
372 mathcursor->selClear();
373 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
374 mathcursor->dispatch(cmd);
378 bv->updateInset(this, false);
383 dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
388 if (mathcursor->dispatch(FuncRequest(cmd)) != UNDISPATCHED)
391 // only select with button 1
392 if (cmd.button() != mouse_button::button1)
395 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
401 if (!mathcursor->selection())
402 mathcursor->selStart();
404 BufferView * bv = cmd.view();
406 mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
408 bv->updateInset(this, false);
413 dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
415 //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
416 // << " arg: '" << cmd.argument
417 // << " x: '" << cmd.x
418 // << " y: '" << cmd.y
419 // << "' button: " << cmd.button() << endl;
421 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
422 bool remove_inset = false;
424 switch (cmd.action) {
425 case LFUN_MOUSE_PRESS:
426 //lyxerr << "Mouse single press\n";
427 return lfunMousePress(cmd);
428 case LFUN_MOUSE_MOTION:
429 //return lfunMouseMotion(cmd);
430 case LFUN_MOUSE_RELEASE:
431 lyxerr << "Mouse single release\n";
432 return lfunMouseRelease(cmd);
433 case LFUN_MOUSE_DOUBLE:
434 //lyxerr << "Mouse double\n";
435 return localDispatch(FuncRequest(LFUN_WORDSEL));
443 BufferView * bv = cmd.view();
444 string argument = cmd.argument;
445 RESULT result = DISPATCHED;
447 bool was_macro = mathcursor->inMacroMode();
448 bool was_selection = mathcursor->selection();
452 mathcursor->normalize();
455 switch (cmd.action) {
457 case LFUN_MATH_MUTATE:
458 case LFUN_MATH_DISPLAY:
459 case LFUN_MATH_NUMBER:
460 case LFUN_MATH_NONUMBER:
463 case LFUN_DELETE_LINE_FORWARD:
464 case LFUN_INSERT_LABEL:
465 case LFUN_MATH_EXTERN:
466 case LFUN_TABULAR_FEATURE:
467 case LFUN_PASTESELECTION:
468 case LFUN_MATH_LIMITS:
469 bv->lockedInsetStoreUndo(Undo::EDIT);
470 mathcursor->dispatch(cmd);
471 updateLocal(bv, true);
475 sel = true; // fall through...
477 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
478 //lyxerr << "calling scroll 20\n";
480 updateLocal(bv, false);
481 // write something to the minibuffer
482 //bv->owner()->message(mathcursor->info());
486 sel = true; // fall through
488 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
489 updateLocal(bv, false);
493 sel = true; // fall through
495 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
496 updateLocal(bv, false);
500 sel = true; // fall through
502 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
503 updateLocal(bv, false);
507 mathcursor->home(false);
508 mathcursor->end(true);
509 updateLocal(bv, false);
512 case LFUN_UP_PARAGRAPHSEL:
513 case LFUN_UP_PARAGRAPH:
514 case LFUN_DOWN_PARAGRAPHSEL:
515 case LFUN_DOWN_PARAGRAPH:
517 updateLocal(bv, false);
521 case LFUN_WORDLEFTSEL:
522 sel = true; // fall through
525 result = mathcursor->home(sel) ? DISPATCHED : FINISHED;
526 updateLocal(bv, false);
530 case LFUN_WORDRIGHTSEL:
531 sel = true; // fall through
534 result = mathcursor->end(sel) ? DISPATCHED : FINISHED_RIGHT;
535 updateLocal(bv, false);
540 case LFUN_BEGINNINGBUFSEL:
541 case LFUN_BEGINNINGBUF:
543 updateLocal(bv, false);
550 result = FINISHED_RIGHT;
551 updateLocal(bv, false);
555 mathcursor->idxNext();
556 updateLocal(bv, false);
560 mathcursor->idxPrev();
561 updateLocal(bv, false);
564 case LFUN_DELETE_WORD_BACKWARD:
566 bv->lockedInsetStoreUndo(Undo::EDIT);
567 if (mathcursor->backspace()) {
573 updateLocal(bv, true);
576 case LFUN_DELETE_WORD_FORWARD:
578 bv->lockedInsetStoreUndo(Undo::EDIT);
579 if (mathcursor->erase()) {
585 updateLocal(bv, true);
589 // sprintf(dispatch_buffer, "%d %d",);
590 // dispatch_result = dispatch_buffer;
593 lyxerr << "LFUN_SETXY broken!\n";
596 istringstream is(cmd.argument.c_str());
598 mathcursor->setPos(x, y);
599 updateLocal(bv, false);
605 mathcursor->macroModeClose();
606 bv->lockedInsetStoreUndo(Undo::EDIT);
607 mathcursor->selPaste();
608 updateLocal(bv, true);
612 bv->lockedInsetStoreUndo(Undo::DELETE);
613 mathcursor->selCut();
614 updateLocal(bv, true);
618 mathcursor->selCopy();
622 // Special casing for superscript in case of LyX handling
624 case LFUN_CIRCUMFLEX:
625 if (cmd.argument.empty()) {
626 // do superscript if LyX handles
628 bv->lockedInsetStoreUndo(Undo::EDIT);
629 mathcursor->script(true);
630 updateLocal(bv, true);
647 case LFUN_HUNG_UMLAUT:
651 case LFUN_GREEK_TOGGLE: handleFont(bv, cmd.argument, "lyxgreek"); break;
652 case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break;
653 case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break;
654 case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break;
655 case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break;
656 case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break;
657 case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break;
658 case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break;
659 case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break;
660 case LFUN_FREE: handleFont(bv, cmd.argument, "textrm"); break;
661 case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break;
664 handleFont(bv, cmd.argument, "lyxgreek1");
665 if (cmd.argument.size())
666 mathcursor->insert(asArray(cmd.argument));
670 if (mathcursor->currentMode() == MathInset::TEXT_MODE) {
671 mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
672 updateLocal(bv, true);
674 handleFont(bv, cmd.argument, "textrm");
676 //bv->owner()->message(_("math text mode toggled"));
682 bv->lockedInsetStoreUndo(Undo::EDIT);
683 mathcursor->setSize(arg);
684 updateLocal(bv, true);
689 case LFUN_INSERT_MATRIX: {
690 bv->lockedInsetStoreUndo(Undo::EDIT);
695 istringstream is(STRCONV(argument));
696 is >> m >> n >> v_align >> h_align;
700 mathcursor->niceInsert(
701 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
702 updateLocal(bv, true);
706 case LFUN_SUPERSCRIPT:
709 bv->lockedInsetStoreUndo(Undo::EDIT);
710 mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
711 updateLocal(bv, true);
715 case LFUN_MATH_DELIM:
717 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
719 string rs = split(cmd.argument, ls, ' ');
720 // Reasonable default values
726 bv->lockedInsetStoreUndo(Undo::EDIT);
727 mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
728 updateLocal(bv, true);
732 case LFUN_PROTECTEDSPACE:
733 case LFUN_MATH_SPACE:
734 bv->lockedInsetStoreUndo(Undo::EDIT);
735 mathcursor->insert(MathAtom(new MathSpaceInset(",")));
736 updateLocal(bv, true);
740 bv->owner()->message(_("Invalid action in math mode!"));
744 case LFUN_EXEC_COMMAND:
745 result = UNDISPATCHED;
749 // interpret this as if a backslash was typed
750 bv->lockedInsetStoreUndo(Undo::EDIT);
751 mathcursor->interpret('\\');
752 updateLocal(bv, true);
755 case LFUN_BREAKPARAGRAPH:
756 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
757 case LFUN_BREAKPARAGRAPH_SKIP:
761 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
762 // handling such that "self-insert" works on "arbitrary stuff" too, and
763 // math-insert only handles special math things like "matrix".
764 case LFUN_INSERT_MATH:
765 bv->lockedInsetStoreUndo(Undo::EDIT);
766 mathcursor->niceInsert(argument);
767 updateLocal(bv, true);
771 case LFUN_SELFINSERT:
772 if (!argument.empty()) {
773 bv->lockedInsetStoreUndo(Undo::EDIT);
774 if (argument.size() == 1)
775 result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
777 mathcursor->insert(asArray(argument));
778 updateLocal(bv, true);
782 case LFUN_MATH_PANEL:
783 result = UNDISPATCHED;
787 if (mathcursor->selection())
788 mathcursor->selClear();
790 result = UNDISPATCHED;
793 case LFUN_INSET_TOGGLE:
794 mathcursor->insetToggle();
795 updateLocal(bv, true);
798 case LFUN_DIALOG_SHOW_NEW_INSET: {
799 string const & name = argument;
801 InsetCommandParams p(name);
802 string data = InsetCommandMailer::params2string(p);
803 bv->owner()->getDialogs().show(name, data, 0);
805 result = UNDISPATCHED;
809 case LFUN_REF_APPLY: {
810 InsetCommandParams params;
811 InsetCommandMailer::string2params(argument, params);
813 // It would be nice if RefInset could handle an
814 // InsetCommandParams arg, but for now we convert it to
815 // 'foo|++|bar|++|nonsense'.
816 string const tmp = params.getAsString();
819 bv->owner()->getDialogs().getOpenInset("ref");
821 RefInset * inset = dynamic_cast<RefInset *>(base);
823 result = UNDISPATCHED;
827 *inset = RefInset(tmp);
829 mathcursor->insert(MathAtom(new RefInset(tmp)));
831 updateLocal(bv, true);
836 result = UNDISPATCHED;
839 mathcursor->normalize();
842 lyx::Assert(mathcursor);
844 if (mathcursor->selection() || was_selection)
845 toggleInsetSelection(bv);
847 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
848 result == UNDISPATCHED) {
852 cmd.view()->stuffClipboard(mathcursor->grabSelection());
854 releaseMathCursor(bv);
855 bv->unlockInset(this);
857 bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
860 return result; // original version
864 void InsetFormulaBase::revealCodes(BufferView * bv) const
868 bv->owner()->message(mathcursor->info());
871 // write something to the minibuffer
872 // translate to latex
873 mathcursor->markInsert();
876 string str = os.str();
877 mathcursor->markErase();
878 string::size_type pos = 0;
880 for (string::iterator it = str.begin(); it != str.end(); ++it) {
883 else if (*it == '\0') {
885 pos = it - str.begin();
891 res = res.substr(pos - 30);
893 res = res.substr(0, 60);
894 bv->owner()->message(res);
899 Inset::Code InsetFormulaBase::lyxCode() const
901 return Inset::MATH_CODE;
905 int InsetFormulaBase::ylow() const
907 return yo_ - ascent(view(), font_);
911 int InsetFormulaBase::yhigh() const
913 return yo_ + descent(view(), font_);
917 int InsetFormulaBase::xlow() const
923 int InsetFormulaBase::xhigh() const
925 return xo_ + width(view(), font_);
929 /////////////////////////////////////////////////////////////////////
932 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
938 static InsetFormulaBase * lastformula = 0;
939 static MathIterator current = MathIterator(ibegin(par().nucleus()));
941 static string laststr;
943 if (lastformula != this || laststr != str) {
944 //lyxerr << "reset lastformula to " << this << "\n";
947 current = ibegin(par().nucleus());
949 mathed_parse_cell(ar, str);
953 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
955 for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
956 if (it.cell().matchpart(ar, it.back().pos_)) {
957 bv->unlockInset(bv->theLockingInset());
958 if (!bv->lockInset(this)) {
959 lyxerr << "Cannot lock inset" << endl;
963 mathcursor = new MathCursor(this, true);
965 mathcursor->setSelection(it, ar.size());
968 updateLocal(bv, false);
973 //lyxerr << "not found!\n";
979 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
982 lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
983 return searchForward(bv, what, a, b);
987 bool InsetFormulaBase::display() const
989 return par()->asHullInset() && par()->asHullInset()->display();
993 string InsetFormulaBase::selectionAsString() const
995 return mathcursor ? mathcursor->grabSelection() : string();
998 /////////////////////////////////////////////////////////////////////
1001 void mathDispatchCreation(FuncRequest const & cmd, bool display)
1003 BufferView * bv = cmd.view();
1004 // use selection if available..
1006 //if (action == LFUN_MATH_IMPORT_SELECTION)
1010 string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
1013 InsetFormula * f = new InsetFormula(bv);
1014 if (openNewInset(bv, f)) {
1015 bv->theLockingInset()->
1016 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1017 // don't do that also for LFUN_MATH_MODE unless you want end up with
1018 // always changing to mathrm when opening an inlined inset
1019 // -- I really hate "LyXfunc overloading"...
1021 f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
1022 f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
1025 // create a macro if we see "\\newcommand" somewhere, and an ordinary
1026 // formula otherwise
1027 InsetFormulaBase * f;
1028 if (sel.find("\\newcommand") == string::npos &&
1029 sel.find("\\def") == string::npos)
1030 f = new InsetFormula(sel);
1032 f = new InsetFormulaMacro(sel);
1033 bv->getLyXText()->cutSelection(bv);
1034 openNewInset(bv, f);
1036 cmd.message(N_("Math editor mode"));
1040 void mathDispatch(FuncRequest const & cmd)
1042 BufferView * bv = cmd.view();
1043 if (!bv->available())
1046 switch (cmd.action) {
1048 case LFUN_MATH_DISPLAY:
1049 mathDispatchCreation(cmd, true);
1052 case LFUN_MATH_MODE:
1053 mathDispatchCreation(cmd, false);
1056 case LFUN_MATH_IMPORT_SELECTION:
1057 mathDispatchCreation(cmd, false);
1060 case LFUN_MATH_MACRO:
1061 if (cmd.argument.empty())
1062 cmd.errorMessage(N_("Missing argument"));
1064 string s = cmd.argument;
1065 string const s1 = token(s, ' ', 1);
1066 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1067 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1072 case LFUN_INSERT_MATH:
1073 case LFUN_INSERT_MATRIX:
1074 case LFUN_MATH_DELIM: {
1075 InsetFormula * f = new InsetFormula(bv);
1076 if (openNewInset(bv, f)) {
1077 bv->theLockingInset()->
1078 localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
1079 bv->theLockingInset()->localDispatch(cmd);