3 * Purpose: Implementation of formula inset
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Allows the edition of math paragraphs inside Lyx.
8 * Copyright: 1996-1998 Alejandro Aguilar Sierra
10 * Version: 0.4, Lyx project.
12 * You are free to use and modify this code under the terms of
13 * the GNU General Public Licence version 2 or later.
22 #pragma implementation
26 #include "formulamacro.h"
27 #include "commandtags.h"
28 #include "math_cursor.h"
29 #include "math_parser.h"
30 #include "BufferView.h"
34 #include "LaTeXFeatures.h"
36 #include "support/LOstream.h"
40 #include "math_arrayinset.h"
41 #include "math_spaceinset.h"
42 #include "support/lyxlib.h"
43 #include "mathed/support.h"
44 #include "undo_funcs.h"
50 extern char const * latex_special_chars;
52 int greek_kb_flag = 0;
53 extern char const * latex_mathenv[];
54 LyXFont * Math_Fonts = 0;
55 MathCursor * mathcursor = 0;
66 void mathed_init_fonts();
68 string nicelabel(string const & label)
70 return "(" + (label.empty() ? "#" : label) + ")";
73 void handleFont(BufferView * bv, MathTextCodes t)
75 if (mathcursor->Selection())
76 bv->lockedInsetStoreUndo(Undo::EDIT);
77 mathcursor->handleFont(t);
80 void handleAccent(BufferView * bv, string const & name, int code)
82 bv->lockedInsetStoreUndo(Undo::EDIT);
83 mathcursor->handleAccent(name, code);
86 void handleDelim(BufferView * bv, int l, int r)
88 bv->lockedInsetStoreUndo(Undo::EDIT);
89 mathcursor->handleDelim(l, r);
92 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
94 LyXText * lt = bv->getLyXText();
98 if (!bv->insertInset(new_inset)) {
102 new_inset->edit(bv, 0, 0, 0);
111 LyXFont WhichFont(short type, int size)
148 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
162 if (type == LM_TC_BSYM) {
175 case LM_ST_SCRIPTSCRIPT:
181 lyxerr << "Math Error: wrong font size: " << size << endl;
185 if (type != LM_TC_TEXTRM)
186 f.setColor(LColor::math);
188 if (type == LM_TC_TEX)
189 f.setColor(LColor::latex);
197 void mathed_init_fonts()
199 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
202 for (int i = 0 ; i < 8 ; ++i) {
203 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
206 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
208 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
210 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
211 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
213 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
215 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
216 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
218 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
220 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
222 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
226 // returns the nearest enclosing matrix
227 MathArrayInset * matrixpar(int & idx)
231 static_cast<MathArrayInset *>
232 (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
239 InsetFormulaBase::InsetFormulaBase(MathInset * par)
244 InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
245 : UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
249 InsetFormulaBase::~InsetFormulaBase()
252 #warning leak this for a while...
258 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
263 void InsetFormulaBase::write(Buffer const *, ostream & os) const
268 int InsetFormulaBase::latex(Buffer const *, ostream & os,
269 bool fragile, bool spacing) const
271 return latex(os, fragile, spacing);
274 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
276 return ascii(os, spacing);
279 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
284 int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
291 // Check if uses AMS macros
292 void InsetFormulaBase::validate(LaTeXFeatures &) const
296 string const InsetFormulaBase::editMessage() const
298 return _("Math editor mode");
302 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
304 mathcursor = new MathCursor(this);
306 if (!bv->lockInset(this))
307 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
310 //bv->updateInset(this, false);
321 void InsetFormulaBase::edit(BufferView * bv, bool front)
323 #warning Please have a look if this is right (Jug)
324 edit(bv, front ? 0 : 1, 0, 0);
328 void InsetFormulaBase::insetUnlock(BufferView * bv)
331 if (mathcursor->InMacroMode()) {
332 mathcursor->MacroModeClose();
333 updateLocal(bv, true);
338 bv->updateInset(this, false);
342 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
344 mathcursor->GetPos(x, y);
350 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
355 if (isCursorVisible())
356 bv->hideLockedInsetCursor();
360 mathcursor->GetPos(x, y);
364 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
365 int const asc = lyxfont::maxAscent(font);
366 int const desc = lyxfont::maxDescent(font);
368 bv->showLockedInsetCursor(x, y, asc, desc);
371 toggleCursorVisible();
375 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
377 if (!isCursorVisible()) {
381 mathcursor->GetPos(x, y);
384 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
385 int const asc = lyxfont::maxAscent(font);
386 int const desc = lyxfont::maxDescent(font);
387 bv->fitLockedInsetCursor(x, y, asc, desc);
389 toggleInsetCursor(bv);
394 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
396 if (isCursorVisible())
397 toggleInsetCursor(bv);
401 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
404 bv->updateInset(this, false);
408 vector<string> const InsetFormulaBase::getLabelList() const
410 return std::vector<string>();
414 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
417 bv->updateInset(this, dirty);
421 void InsetFormulaBase::Metrics() const
423 const_cast<MathInset *>(par_)->Metrics(LM_ST_TEXT);
427 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
428 int x, int y, int /*button*/)
434 mathcursor->SetPos(x, y);
441 bv->updateInset(this, false);
446 void InsetFormulaBase::insetButtonPress(BufferView * bv,
447 int x, int y, int /*button*/)
452 if (mathcursor && mathcursor->Selection()) {
453 mathcursor->SelClear();
454 bv->updateInset(this, false);
459 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
460 int x, int y, int /*button*/)
462 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
465 mathcursor->SetPos(sel_x + par_->xo(), sel_y + par_->yo());
466 mathcursor->SelStart();
468 mathcursor->GetPos(sel_x, sel_y);
469 } else if (sel_flag) {
473 mathcursor->SetPos(x, y);
475 mathcursor->GetPos(x, y);
476 if (sel_x != x || sel_y != y)
477 bv->updateInset(this, false);
484 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
486 lyxerr[Debug::MATHED]
487 << "Used InsetFormulaBase::InsetKeyPress." << endl;
492 UpdatableInset::RESULT
493 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
496 //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
497 // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
502 MathTextCodes varcode = LM_TC_MIN;
503 bool was_macro = mathcursor->InMacroMode();
505 bool was_selection = mathcursor->Selection();
506 RESULT result = DISPATCHED;
510 if (mathcursor->getLastCode() == LM_TC_TEX)
513 mathcursor->normalize();
517 // --- Cursor Movements ---------------------------------------------
520 sel = true; // fall through...
523 result = DISPATCH_RESULT(mathcursor->Right(sel));
524 updateLocal(bv, false);
529 sel = true; // fall through
532 result = DISPATCH_RESULT(mathcursor->Left(sel));
533 updateLocal(bv, false);
541 result = DISPATCH_RESULT(mathcursor->Up(sel));
542 updateLocal(bv, false);
550 result = DISPATCH_RESULT(mathcursor->Down(sel));
551 updateLocal(bv, false);
556 updateLocal(bv, false);
561 updateLocal(bv, false);
564 case LFUN_DELETE_LINE_FORWARD:
565 bv->lockedInsetStoreUndo(Undo::DELETE);
566 mathcursor->DelLine();
567 updateLocal(bv, true);
571 mathcursor->idxNext();
572 updateLocal(bv, false);
576 mathcursor->idxPrev();
577 updateLocal(bv, false);
581 bv->lockedInsetStoreUndo(Undo::EDIT);
582 mathcursor->splitCell();
583 updateLocal(bv, true);
587 // if (!mathcursor->InMacroMode() && mathcursor->pos() == 0)
588 if (mathcursor->pos() == 0) {
589 bv->lockedInsetStoreUndo(Undo::DELETE);
590 mathcursor->pullArg();
591 bv->updateInset(this, true);
594 if (mathcursor->InMacroMode())
597 mathcursor->plainLeft();
601 bv->lockedInsetStoreUndo(Undo::DELETE);
602 mathcursor->Delete();
603 bv->updateInset(this, true);
607 // sprintf(dispatch_buffer, "%d %d",);
608 // dispatch_result = dispatch_buffer;
612 lyxerr << "LFUN_SETXY broken!\n";
617 istringstream is(arg.c_str());
620 mathcursor->SetPos(x1 + x, y1 + y);
621 updateLocal(bv, false);
625 // cursor selection ----------------------------
629 mathcursor->MacroModeClose();
630 bv->lockedInsetStoreUndo(Undo::INSERT);
631 mathcursor->SelPaste();
632 updateLocal(bv, true);
636 bv->lockedInsetStoreUndo(Undo::DELETE);
637 mathcursor->SelCut();
638 updateLocal(bv, true);
642 mathcursor->SelCopy();
647 case LFUN_WORDRIGHTSEL:
648 case LFUN_WORDLEFTSEL:
651 // --- accented characters ------------------------------
653 case LFUN_UMLAUT: handleAccent(bv, "ddot", LM_ddot); break;
654 case LFUN_CIRCUMFLEX: handleAccent(bv, "hat", LM_hat); break;
655 case LFUN_GRAVE: handleAccent(bv, "grave", LM_grave); break;
656 case LFUN_ACUTE: handleAccent(bv, "acute", LM_acute); break;
657 case LFUN_TILDE: handleAccent(bv, "tilde", LM_tilde); break;
658 case LFUN_MACRON: handleAccent(bv, "bar", LM_bar); break;
659 case LFUN_DOT: handleAccent(bv, "dot", LM_dot); break;
660 case LFUN_CARON: handleAccent(bv, "check", LM_check); break;
661 case LFUN_BREVE: handleAccent(bv, "breve", LM_breve); break;
662 case LFUN_VECTOR: handleAccent(bv, "vec", LM_vec); break;
666 if (!greek_kb_flag) {
668 bv->owner()->message(_("Math greek mode on"));
674 case LFUN_GREEK_TOGGLE:
675 greek_kb_flag = greek_kb_flag ? 0 : 2;
677 bv->owner()->message(_("Math greek keyboard on"));
679 bv->owner()->message(_("Math greek keyboard off"));
683 case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
684 case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
685 case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
686 case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
687 case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
688 case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
691 handleFont(bv, LM_TC_TEXTRM);
692 //bv->owner()->message(_("math text mode toggled"));
697 if (!mathcursor->Selection()) {
698 mathcursor->handleFont(LM_TC_TEX);
699 //bv->owner()->message(_("TeX mode toggled"));
704 case LFUN_MATH_LIMITS:
705 bv->lockedInsetStoreUndo(Undo::INSERT);
706 if (mathcursor->toggleLimits())
707 updateLocal(bv, true);
712 bv->lockedInsetStoreUndo(Undo::INSERT);
713 latexkeys const * l = in_word_set(arg);
714 mathcursor->SetSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
715 updateLocal(bv, true);
719 case LFUN_INSERT_MATRIX:
721 bv->lockedInsetStoreUndo(Undo::INSERT);
722 mathcursor->Interpret("matrix " + arg);
723 updateLocal(bv, true);
727 case LFUN_INSERT_MATH:
729 bv->lockedInsetStoreUndo(Undo::INSERT);
730 mathcursor->Interpret(arg);
731 updateLocal(bv, true);
735 case LFUN_MATH_DELIM:
737 bv->lockedInsetStoreUndo(Undo::INSERT);
740 static const string vdelim("(){}[]./|");
741 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
746 istringstream is(arg.c_str());
750 //lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
751 //lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
754 latexkeys const * l = in_word_set(lt);
757 } else if (vdelim.find(lt[0]) != string::npos)
761 latexkeys const * l = in_word_set(rt);
764 } else if (vdelim.find(rt[0]) != string::npos)
767 handleDelim(bv, ilt, irt);
768 updateLocal(bv, true);
772 case LFUN_PROTECTEDSPACE:
773 bv->lockedInsetStoreUndo(Undo::INSERT);
774 mathcursor->insert(new MathSpaceInset(1));
775 updateLocal(bv, true);
779 bv->owner()->message(_("Invalid action in math mode!"));
783 case LFUN_MATH_HALIGN:
785 bv->lockedInsetStoreUndo(Undo::INSERT);
786 lyxerr << "handling halign '" << arg << "'\n";
788 MathArrayInset * p = matrixpar(idx);
791 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
792 updateLocal(bv, true);
796 case LFUN_MATH_VALIGN:
798 bv->lockedInsetStoreUndo(Undo::INSERT);
799 lyxerr << "handling valign '" << arg << "'\n";
801 MathArrayInset * p = matrixpar(idx);
804 p->valign(arg.size() ? arg[0] : 'c');
805 updateLocal(bv, true);
809 case LFUN_MATH_ROW_INSERT:
811 bv->lockedInsetStoreUndo(Undo::INSERT);
813 MathArrayInset * p = matrixpar(idx);
814 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
817 p->addRow(p->row(idx));
818 updateLocal(bv, true);
822 case LFUN_MATH_ROW_DELETE:
824 bv->lockedInsetStoreUndo(Undo::INSERT);
826 MathArrayInset * p = matrixpar(idx);
827 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
830 p->delRow(p->row(idx));
831 updateLocal(bv, true);
835 case LFUN_MATH_COLUMN_INSERT:
837 bv->lockedInsetStoreUndo(Undo::INSERT);
839 MathArrayInset * p = matrixpar(idx);
842 p->addCol(p->col(idx));
843 updateLocal(bv, true);
847 case LFUN_MATH_COLUMN_DELETE:
849 bv->lockedInsetStoreUndo(Undo::INSERT);
851 MathArrayInset * p = matrixpar(idx);
854 p->delCol(p->col(idx));
855 updateLocal(bv, true);
859 case LFUN_EXEC_COMMAND:
860 result = UNDISPATCHED;
864 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
865 unsigned char c = arg[0];
867 lyxerr << "Action: " << action << endl;
869 lyxerr << "char: '" << c << "' int: " << int(c) << endl;
870 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
871 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
872 bv->lockedInsetStoreUndo(Undo::INSERT);
874 if (c == 0) { // Dead key, do nothing
875 //lyxerr << "deadkey" << endl;
880 if (mathcursor->getLastCode() == LM_TC_TEX) {
881 mathcursor->MacroModeOpen();
882 mathcursor->clearLastCode();
884 } else if (!varcode) {
885 short f = mathcursor->getLastCode() ?
886 mathcursor->getLastCode() :
887 mathcursor->nextCode();
888 varcode = MathIsAlphaFont(f) ?
889 static_cast<MathTextCodes>(f) :
893 // lyxerr << "Varcode << vardoce;
894 MathTextCodes char_code = varcode;
897 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
898 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
899 'Y', 0, 0, 0, 0 , 'Z' };
901 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
902 char_code = LM_TC_RM;
905 char_code = LM_TC_SYMB;
908 mathcursor->insert(c, char_code);
910 if (greek_kb_flag && char_code == LM_TC_RM )
911 mathcursor->setLastCode(LM_TC_VAR);
915 if (greek_kb_flag < 2)
918 } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
919 mathcursor->insert(c, LM_TC_TEX);
921 mathcursor->insert('}', LM_TC_TEX);
924 mathcursor->clearLastCode();
925 // varcode = LM_TC_MIN;
926 } else if (c == '_' && varcode == LM_TC_TEX) {
927 mathcursor->insert(c, LM_TC_SPECIAL);
928 mathcursor->clearLastCode();
929 // varcode = LM_TC_MIN;
930 } else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
931 mathcursor->MacroModeOpen();
932 mathcursor->clearLastCode();
933 mathcursor->insert(c, LM_TC_MIN);
934 } else if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) {
935 MathTextCodes code = mathcursor->getLastCode();
936 if (code != LM_TC_TEXTRM)
938 mathcursor->insert(c, code);
939 } else if (strchr("+/-*<>=", c)) {
940 MathTextCodes code = mathcursor->getLastCode();
941 if (code != LM_TC_TEXTRM)
943 mathcursor->insert(c, code);
944 } else if (strchr(latex_special_chars, c) && c != '_') {
945 MathTextCodes code = mathcursor->getLastCode();
946 if (code != LM_TC_TEXTRM)
947 code = LM_TC_SPECIAL;
948 mathcursor->insert(c, code);
949 } else if (c == '_' || c == '^') {
953 mathcursor->Interpret(s);
954 } else if (c == ' ') {
956 MathTextCodes f = (mathcursor->getLastCode()) ?
957 mathcursor->getLastCode() :
958 mathcursor->nextCode();
959 varcode = MathIsAlphaFont(f) ? f : LM_TC_VAR;
962 if (varcode == LM_TC_TEXTRM)
963 mathcursor->insert(c, LM_TC_TEXTRM);
965 mathcursor->MacroModeClose();
966 else if (mathcursor->pop())
967 mathcursor->plainRight();
969 // this would not work if the inset is in an table!
970 //bv->text->cursorRight(bv, true);
973 } else if (c == '\'' || c == '@') {
974 mathcursor->insert(c, LM_TC_VAR);
975 } else if (c == '\\') {
977 mathcursor->MacroModeClose();
978 bv->owner()->message(_("TeX mode"));
979 mathcursor->setLastCode(LM_TC_TEX);
981 updateLocal(bv, true);
982 } else if (action == LFUN_MATH_PANEL) {
983 result = UNDISPATCHED;
985 lyxerr << "Closed by action " << action << endl;
990 mathcursor->normalize();
992 if (was_macro != mathcursor->InMacroMode()
993 && action >= 0 && action != LFUN_BACKSPACE)
994 updateLocal(bv, true);
996 if (mathcursor->Selection() || was_selection)
997 toggleInsetSelection(bv);
999 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
1000 result == UNDISPATCHED)
1001 showInsetCursor(bv);
1003 bv->unlockInset(this);
1005 return result; // original version
1010 /* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
1012 bool math_insert_greek(BufferView * bv, char c)
1014 if (!bv->available())
1022 if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
1023 int greek_kb_flag_save = greek_kb_flag;
1024 InsetFormula * new_inset = new InsetFormula();
1025 bv->beforeChange(bv->text);
1026 if (!bv->insertInset(new_inset)) {
1031 new_inset->edit(bv, 0, 0, 0);
1032 new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
1033 if (greek_kb_flag_save < 2) {
1034 bv->unlockInset(new_inset); // bv->theLockingInset());
1035 bv->text->cursorRight(bv, true);
1038 if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
1039 bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
1040 static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
1042 lyxerr << "Math error: attempt to write on a wrong "
1043 "class of inset." << endl;
1049 Inset::Code InsetFormulaBase::lyxCode() const
1051 return Inset::MATH_CODE;
1055 LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
1057 // We have already discussed what was here
1060 font.setLatex(LyXFont::OFF);
1065 MathInset * InsetFormulaBase::par() const
1071 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
1073 if (bv->available()) {
1074 // Feature "Read math inset from selection" disabled.
1075 // // use selection if available..
1077 // if (action == LFUN_MATH_IMPORT_SELECTION)
1080 // sel = bv->getLyXText()->selectionAsString(bv->buffer());
1083 // if (sel.empty()) {
1084 f = new InsetFormula;
1085 if (openNewInset(bv, f)) {
1086 // don't do that also for LFUN_MATH_MODE unless you want end up with
1087 // always changing to mathrm when opening an inlined inset
1088 // -- I really hate "LyXfunc overloading"...
1090 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
1091 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
1094 // f = new InsetFormula(sel);
1095 // bv->getLyXText()->cutSelection(bv);
1096 // openNewInset(bv, f);
1099 bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
1102 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
1104 mathDispatchCreation(bv, arg, true);
1107 void mathDispatchMathMode(BufferView * bv, string const & arg)
1109 mathDispatchCreation(bv, arg, false);
1112 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
1114 mathDispatchCreation(bv, arg, true);
1117 void mathDispatchMathMacro(BufferView * bv, string const & arg)
1119 if (bv->available()) {
1121 bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
1124 string const s1 = token(s, ' ', 1);
1125 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1126 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1131 void mathDispatchMathDelim(BufferView * bv, string const & arg)
1133 if (bv->available()) {
1134 if (openNewInset(bv, new InsetFormula))
1135 bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
1140 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
1142 if (bv->available()) {
1143 if (openNewInset(bv, new InsetFormula))
1144 bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
1148 void mathDispatchInsertMath(BufferView * bv, string const & arg)
1150 if (bv->available()) {
1151 if (arg.size() && arg[0] == '\\')
1152 openNewInset(bv, new InsetFormula(arg));
1154 mathDispatchMathMode(bv, arg);