]> git.lyx.org Git - features.git/blob - src/mathed/formulabase.C
new parser
[features.git] / src / mathed / formulabase.C
1  /*
2 *  File:        formula.C
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.
7 *
8 *  Copyright: 1996-1998 Alejandro Aguilar Sierra
9 *
10 *  Version: 0.4, Lyx project.
11 *
12 *   You are free to use and modify this code under the terms of
13 *   the GNU General Public Licence version 2 or later.
14 */
15
16 #include <config.h>
17 #include <fstream>
18
19 #include "Lsstream.h"
20
21 #ifdef __GNUG__
22 #pragma implementation
23 #endif
24
25 #include "formula.h"
26 #include "formulamacro.h"
27 #include "commandtags.h"
28 #include "math_cursor.h"
29 #include "math_parser.h"
30 #include "BufferView.h"
31 #include "lyxtext.h"
32 #include "lyxfunc.h"
33 #include "gettext.h"
34 #include "LaTeXFeatures.h"
35 #include "debug.h"
36 #include "support.h"
37 #include "support/lstrings.h"
38 #include "LyXView.h"
39 #include "Painter.h"
40 #include "font.h"
41 #include "math_arrayinset.h"
42 #include "math_spaceinset.h"
43 #include "math_scopeinset.h"
44 #include "math_macrotable.h"
45 #include "math_factory.h"
46 #include "support/lyxlib.h"
47 #include "undo_funcs.h"
48
49 using std::endl;
50 using std::ostream;
51 using std::vector;
52
53 extern char const * latex_mathenv[];
54 MathCursor        * mathcursor = 0;
55
56
57 namespace {
58
59
60 // local global
61 int sel_x;
62 int sel_y;
63 bool sel_flag;
64
65 void mathed_init_fonts();
66
67 string nicelabel(string const & label)
68 {
69         return "(" + (label.empty() ? "#" : label) + ")";
70 }
71
72 void handleFont(BufferView * bv, MathTextCodes t) 
73 {
74         if (mathcursor->selection())
75                 bv->lockedInsetStoreUndo(Undo::EDIT);
76         mathcursor->handleFont(t);
77 }
78
79
80 void handleAccent(BufferView * bv, string const & name)
81 {
82         bv->lockedInsetStoreUndo(Undo::EDIT);
83         mathcursor->insert(createMathInset(name));
84 }
85
86
87 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
88 {
89         LyXText * lt = bv->getLyXText();
90         
91         bv->beforeChange(lt);
92         finishUndo();
93         if (!bv->insertInset(new_inset)) {
94                 delete new_inset;
95                 return false;
96         }
97         new_inset->edit(bv, 0, 0, 0);
98         return true;
99 }
100
101
102 // returns the nearest enclosing grid
103 MathArrayInset * matrixpar(int & idx)
104 {
105         idx = 0;
106         return (mathcursor ? mathcursor->enclosingArray(idx) : 0); 
107 }
108
109
110 } // namespace anon
111
112
113
114 InsetFormulaBase::InsetFormulaBase()
115 {
116 #ifdef WITH_WARNINGS
117 #warning This is needed as long the math parser is not re-entrant
118 #endif
119         MathMacroTable::builtinMacros();
120         //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
121 }
122
123
124 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
125 {
126         read(lex);
127 }
128
129
130 void InsetFormulaBase::write(Buffer const *, ostream & os) const
131 {
132         write(os);
133 }
134
135
136 int InsetFormulaBase::latex(Buffer const *, ostream & os,
137         bool fragile, bool spacing) const
138 {
139         return latex(os, fragile, spacing);
140 }
141
142
143 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
144 {
145         return ascii(os, spacing);
146 }
147
148
149 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
150 {
151         return linuxdoc(os);
152 }
153
154
155 int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
156 {
157         return docBook(os);
158 }
159
160
161
162 // Check if uses AMS macros
163 void InsetFormulaBase::validate(LaTeXFeatures &) const
164 {}
165
166
167 string const InsetFormulaBase::editMessage() const
168 {
169         return _("Math editor mode");
170 }
171
172
173 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
174 {
175         mathcursor = new MathCursor(this);
176
177         if (!bv->lockInset(this))
178                 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
179
180         metrics();
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);
184         if (x == 0)
185                 mathcursor->first();
186         else
187                 mathcursor->last();
188         sel_x = 0;
189         sel_y = 0;
190         sel_flag = false;
191 }
192
193
194 void InsetFormulaBase::edit(BufferView * bv, bool front)
195 {
196         // looks hackish but seems to work
197         edit(bv, front ? 0 : 1, 0, 0);
198 }
199
200
201 void InsetFormulaBase::insetUnlock(BufferView * bv)
202 {
203         if (mathcursor) {
204                 if (mathcursor->inMacroMode()) {
205                         mathcursor->macroModeClose();
206                         updateLocal(bv, true);
207                 }
208                 delete mathcursor;
209                 mathcursor = 0;
210         }
211         bv->updateInset(this, false);
212 }
213
214
215 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
216 {
217         mathcursor->getPos(x, y);
218         x -= par()->xo();
219         y -= par()->yo();
220 }
221
222
223 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
224 {
225         if (!mathcursor)
226                 return;
227
228         if (isCursorVisible())
229                 bv->hideLockedInsetCursor();
230         else {
231                 int x;
232                 int y;
233                 mathcursor->getPos(x, y);
234                 //x -= par()->xo();
235                 y -= par()->yo();
236                 int asc;
237                 int desc;
238                 math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
239                 bv->showLockedInsetCursor(x, y, asc, desc);
240         }
241
242         toggleCursorVisible();
243 }
244
245
246 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
247 {
248         if (!isCursorVisible()) {
249                 if (mathcursor) {
250                         int x;
251                         int y;
252                         mathcursor->getPos(x, y);
253                         x -= par()->xo();
254                         y -= par()->yo();
255                         int asc;
256                         int desc;
257                         math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
258                         bv->fitLockedInsetCursor(x, y, asc, desc);
259                 }
260                 toggleInsetCursor(bv);
261         }
262 }
263
264
265 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
266 {
267         if (isCursorVisible())
268                 toggleInsetCursor(bv);
269 }
270
271
272 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
273 {
274         if (mathcursor)
275                 bv->updateInset(this, false);
276 }
277
278
279 vector<string> const InsetFormulaBase::getLabelList() const
280 {
281   return std::vector<string>();
282 }
283
284
285 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
286 {
287         metrics();
288         bv->updateInset(this, dirty);
289 }
290
291
292 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
293                                           int x, int y, int /*button*/)
294 {
295         if (mathcursor) {
296                 hideInsetCursor(bv);
297                 x += par()->xo();
298                 y += par()->yo();
299                 mathcursor->setPos(x, y);
300                 showInsetCursor(bv);
301                 if (sel_flag) {
302                         sel_flag = false;
303                         sel_x = 0;
304                         sel_y = 0;
305                 }
306                 bv->updateInset(this, false);
307         }
308 }
309
310
311 void InsetFormulaBase::insetButtonPress(BufferView * bv,
312                                         int x, int y, int /*button*/)
313 {
314         sel_flag = false;
315         sel_x = x;
316         sel_y = y;
317         if (mathcursor && mathcursor->selection()) {
318                 mathcursor->selClear();
319                 bv->updateInset(this, false);
320         }
321 }
322
323
324 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
325                                          int x, int y, int /*button*/)
326 {
327         if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
328                 sel_flag = true;
329                 hideInsetCursor(bv);
330                 mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
331                 mathcursor->selStart();
332                 showInsetCursor(bv);
333                 mathcursor->getPos(sel_x, sel_y);
334         } else if (sel_flag) {
335                 hideInsetCursor(bv);
336                 x += par()->xo();
337                 y += par()->yo();
338                 mathcursor->setPos(x, y);
339                 showInsetCursor(bv);
340                 mathcursor->getPos(x, y);
341                 if (sel_x != x || sel_y != y)
342                         bv->updateInset(this, false);
343                 sel_x = x;
344                 sel_y = y;
345         }
346 }
347
348
349 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
350 {
351         lyxerr[Debug::MATHED] << "Used InsetFormulaBase::InsetKeyPress." << endl;
352 }
353
354
355 int greek_kb_flag = 0;
356
357 UpdatableInset::RESULT
358 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
359                             string const & arg)
360 {
361         //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
362         //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
363
364
365         if (!mathcursor) 
366                 return UNDISPATCHED;
367
368         RESULT result      = DISPATCHED;
369         bool sel           = false;
370         bool was_macro     = mathcursor->inMacroMode();
371         bool was_selection = mathcursor->selection();
372
373         hideInsetCursor(bv);
374
375         mathcursor->normalize();
376
377         switch (action) {
378
379                 // --- Cursor Movements ---------------------------------------------
380
381         case LFUN_RIGHTSEL:
382                 sel = true; // fall through...
383
384         case LFUN_RIGHT:
385                 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
386                 updateLocal(bv, false);
387                 break;
388
389
390         case LFUN_LEFTSEL:
391                 sel = true; // fall through
392
393         case LFUN_LEFT:
394                 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
395                 updateLocal(bv, false);
396                 break;
397
398
399         case LFUN_UPSEL:
400                 sel = true;
401
402         case LFUN_UP:
403                 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
404                 updateLocal(bv, false);
405                 break;
406
407
408         case LFUN_DOWNSEL:
409                 sel = true;
410
411         case LFUN_DOWN:
412                 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
413                 updateLocal(bv, false);
414                 break;
415
416         case LFUN_HOME:
417                 mathcursor->home();
418                 updateLocal(bv, false);
419                 break;
420
421         case LFUN_END:
422                 mathcursor->end();
423                 updateLocal(bv, false);
424                 break;
425
426         case LFUN_DELETE_LINE_FORWARD:
427                 bv->lockedInsetStoreUndo(Undo::DELETE);
428                 mathcursor->delLine();
429                 updateLocal(bv, true);
430                 break;
431
432         case LFUN_TAB:
433                 mathcursor->idxNext();
434                 updateLocal(bv, false);
435                 break;
436
437         case LFUN_SHIFT_TAB:
438                 mathcursor->idxPrev();
439                 updateLocal(bv, false);
440                 break;
441
442         case LFUN_TABINSERT:
443                 bv->lockedInsetStoreUndo(Undo::EDIT);
444                 mathcursor->splitCell();
445                 updateLocal(bv, true);
446                 break;
447
448         case LFUN_BACKSPACE:
449                 bv->lockedInsetStoreUndo(Undo::DELETE);
450                 mathcursor->backspace();
451                 bv->updateInset(this, true);
452                 break;
453
454         case LFUN_DELETE:
455                 bv->lockedInsetStoreUndo(Undo::DELETE);
456                 mathcursor->erase();
457                 bv->updateInset(this, true);
458                 break;
459
460                 //    case LFUN_GETXY:
461                 //      sprintf(dispatch_buffer, "%d %d",);
462                 //      dispatch_result = dispatch_buffer;
463                 //      break;
464         case LFUN_SETXY: {
465                 lyxerr << "LFUN_SETXY broken!\n";
466                 int x;
467                 int y;
468                 int x1;
469                 int y1;
470                 istringstream is(arg.c_str());
471                 is >> x >> y;
472                 par()->getXY(x1, y1);
473                 mathcursor->setPos(x1 + x, y1 + y);
474                 updateLocal(bv, false);
475                 break;
476         }
477
478         case LFUN_PASTE:
479                 if (was_macro)
480                         mathcursor->macroModeClose();
481                 bv->lockedInsetStoreUndo(Undo::INSERT);
482                 mathcursor->selPaste();
483                 updateLocal(bv, true);
484                 break;
485
486         case LFUN_CUT:
487                 bv->lockedInsetStoreUndo(Undo::DELETE);
488                 mathcursor->selCut();
489                 updateLocal(bv, true);
490                 break;
491
492         case LFUN_COPY:
493                 mathcursor->selCopy();
494                 break;
495
496         case LFUN_HOMESEL:
497         case LFUN_ENDSEL:
498         case LFUN_WORDRIGHTSEL:
499         case LFUN_WORDLEFTSEL:
500                 break;
501
502                 // --- accented characters ------------------------------
503
504         case LFUN_UMLAUT:       handleAccent(bv, "ddot"); break;
505         case LFUN_CIRCUMFLEX:   handleAccent(bv, "hat"); break;
506         case LFUN_GRAVE:        handleAccent(bv, "grave"); break;
507         case LFUN_ACUTE:        handleAccent(bv, "acute"); break;
508         case LFUN_TILDE:        handleAccent(bv, "tilde"); break;
509         case LFUN_MACRON:       handleAccent(bv, "bar"); break;
510         case LFUN_DOT:          handleAccent(bv, "dot"); break;
511         case LFUN_CARON:        handleAccent(bv, "check"); break;
512         case LFUN_BREVE:        handleAccent(bv, "breve"); break;
513         case LFUN_VECTOR:       handleAccent(bv, "vec"); break;
514
515         //  Math fonts
516         case LFUN_GREEK:        handleFont(bv, LM_TC_GREEK1); break;
517         case LFUN_GREEK_TOGGLE: handleFont(bv, LM_TC_GREEK); break;
518         case LFUN_BOLD:         handleFont(bv, LM_TC_BF); break;
519         case LFUN_SANS:         handleFont(bv, LM_TC_SF); break;
520         case LFUN_EMPH:         handleFont(bv, LM_TC_CAL); break;
521         case LFUN_ROMAN:        handleFont(bv, LM_TC_RM); break;
522         case LFUN_CODE:         handleFont(bv, LM_TC_TT); break;
523         case LFUN_DEFAULT:      handleFont(bv, LM_TC_VAR); break;
524
525         case LFUN_MATH_MODE:
526                 handleFont(bv, LM_TC_TEXTRM);
527                 //bv->owner()->message(_("math text mode toggled"));
528                 break;
529
530         case LFUN_MATH_LIMITS:
531                 bv->lockedInsetStoreUndo(Undo::INSERT);
532                 if (mathcursor->toggleLimits())
533                         updateLocal(bv, true);
534                 break;
535
536         case LFUN_MATH_SIZE:
537                 if (!arg.empty()) {
538                         bv->lockedInsetStoreUndo(Undo::INSERT);
539                         latexkeys const * l = in_word_set(arg);
540                         mathcursor->setSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
541                         updateLocal(bv, true);
542                 }
543                 break;
544
545         case LFUN_INSERT_MATRIX:
546                 if (!arg.empty()) {
547                         bv->lockedInsetStoreUndo(Undo::INSERT);
548                         mathcursor->interpret("matrix " + arg);
549                         updateLocal(bv, true);
550                 }
551                 break;
552
553         case LFUN_MATH_SPACE:
554         {
555                 bv->lockedInsetStoreUndo(Undo::EDIT);
556                 //MathSpaceInset * p = mathcursor->prevSpaceInset();
557                 //if (p) 
558                 //      p->incSpace();
559                 //else
560                 //      mathcursor->insert(new MathSpaceInset(1));
561                 mathcursor->insert(new MathSpaceInset(1));
562                 updateLocal(bv, true);
563                 break;
564         }
565
566         case LFUN_MATH_DELIM:
567         {
568                 bv->lockedInsetStoreUndo(Undo::INSERT);
569                 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
570                 string ls;
571                 string rs;
572                 istringstream is(arg.c_str());
573                 is >> ls >> rs;
574                 latexkeys const * l = in_word_set(ls);
575                 latexkeys const * r = in_word_set(rs);
576                 if (!is || !l || !r) {
577                         lyxerr << "can't parse delimeters from '" << arg << "'\n";
578                         break;
579                 }
580                 bv->lockedInsetStoreUndo(Undo::EDIT);
581                 mathcursor->handleDelim(l, r);
582                 updateLocal(bv, true);
583                 break;
584         }
585
586         case LFUN_PROTECTEDSPACE:
587                 //lyxerr << " called LFUN_PROTECTEDSPACE\n";
588                 bv->lockedInsetStoreUndo(Undo::INSERT);
589                 mathcursor->insert(new MathSpaceInset(1));
590                 updateLocal(bv, true);
591                 break;
592
593         case LFUN_UNDO:
594                 bv->owner()->message(_("Invalid action in math mode!"));
595                 break;
596
597
598         case LFUN_MATH_HALIGN:
599         {
600                 bv->lockedInsetStoreUndo(Undo::INSERT);
601                 lyxerr << "handling halign '" << arg << "'\n";
602                 int idx;
603                 MathArrayInset * p = matrixpar(idx);
604                 if (!p)
605                         break; 
606                 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
607                 updateLocal(bv, true);
608                 break;
609         }
610
611         case LFUN_MATH_VALIGN:
612         {
613                 bv->lockedInsetStoreUndo(Undo::INSERT);
614                 lyxerr << "handling valign '" << arg << "'\n";
615                 int idx;
616                 MathArrayInset * p = matrixpar(idx);
617                 if (!p)
618                         break; 
619                 p->valign(arg.size() ? arg[0] : 'c');
620                 updateLocal(bv, true);
621                 break;
622         }
623
624         case LFUN_MATH_ROW_INSERT:
625         {
626                 bv->lockedInsetStoreUndo(Undo::INSERT);
627                 int idx;
628                 MathArrayInset * p = matrixpar(idx);
629                 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
630                 if (!p)
631                         break; 
632                 p->addRow(p->row(idx));
633                 updateLocal(bv, true);
634                 break;
635         }
636
637         case LFUN_MATH_ROW_DELETE:
638         {
639                 bv->lockedInsetStoreUndo(Undo::INSERT);
640                 int idx;
641                 MathArrayInset * p = matrixpar(idx);
642                 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
643                 if (!p)
644                         break; 
645                 p->delRow(p->row(idx));
646                 updateLocal(bv, true);
647                 break;
648         }
649
650         case LFUN_MATH_COLUMN_INSERT:
651         {
652                 bv->lockedInsetStoreUndo(Undo::INSERT);
653                 int idx;
654                 MathArrayInset * p = matrixpar(idx);
655                 if (!p)
656                         break; 
657                 p->addCol(p->col(idx));
658                 updateLocal(bv, true);
659                 break;
660         }
661
662         case LFUN_MATH_COLUMN_DELETE:
663         {
664                 bv->lockedInsetStoreUndo(Undo::INSERT);
665                 int idx;
666                 MathArrayInset * p = matrixpar(idx);
667                 if (!p)
668                         break; 
669                 p->delCol(p->col(idx));
670                 updateLocal(bv, true);
671                 break;
672         }
673
674         case LFUN_EXEC_COMMAND:
675                 result = UNDISPATCHED;
676                 break;
677
678         case -1:
679         case LFUN_INSERT_MATH:
680         case LFUN_SELFINSERT:
681                 if (!arg.empty()) {
682                         bv->lockedInsetStoreUndo(Undo::INSERT);
683                         mathcursor->interpret(arg);
684                         updateLocal(bv, true);
685                 }
686                 break;
687
688         case LFUN_MATH_PANEL:
689                 result = UNDISPATCHED;
690                 break;
691
692         default:
693                 lyxerr << "Closed by action " << action << endl;
694                 result = FINISHED_RIGHT;
695         }
696
697         mathcursor->normalize();
698
699         if (was_macro != mathcursor->inMacroMode()
700                                 && action >= 0 && action != LFUN_BACKSPACE) 
701                 updateLocal(bv, true);
702         
703         if (mathcursor->selection() || was_selection)
704                 toggleInsetSelection(bv);
705
706         if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
707             result == UNDISPATCHED)
708                 showInsetCursor(bv);
709         else
710                 bv->unlockInset(this);
711
712         return result;  // original version
713 }
714
715
716 Inset::Code InsetFormulaBase::lyxCode() const
717 {
718         return Inset::MATH_CODE;
719 }
720
721
722 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
723 {
724         if (bv->available()) {
725                 // use selection if available..
726                 //string sel;
727                 //if (action == LFUN_MATH_IMPORT_SELECTION)
728                 //      sel = "";
729                 //else
730
731                 string sel = bv->getLyXText()->selectionAsString(bv->buffer());
732
733                 InsetFormulaBase * f;
734                 if (sel.empty()) {
735                                 f = new InsetFormula;
736                                 if (openNewInset(bv, f)) {
737                                         // don't do that also for LFUN_MATH_MODE unless you want end up with
738                                         // always changing to mathrm when opening an inlined inset
739                                         // -- I really hate "LyXfunc overloading"...
740                                         if (display)
741                                                 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
742                                         f->localDispatch(bv, LFUN_INSERT_MATH, arg);
743                                 }
744                 } else {
745                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
746                         // formula otherwise
747                         if (sel.find("\\newcommand") == string::npos) 
748                                 f = new InsetFormula(sel);
749                         else
750                                 f = new InsetFormulaMacro(sel);
751                         bv->getLyXText()->cutSelection(bv);
752                         openNewInset(bv, f);
753                 }
754         }
755         bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
756 }
757
758 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
759 {
760         mathDispatchCreation(bv, arg, true);
761 }
762
763         
764 void mathDispatchMathMode(BufferView * bv, string const & arg)
765 {
766         mathDispatchCreation(bv, arg, false);
767 }
768
769
770 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
771 {
772         mathDispatchCreation(bv, arg, true);
773 }
774
775
776 void mathDispatchMathMacro(BufferView * bv, string const & arg)
777 {
778         if (bv->available()) {
779                 if (arg.empty())
780                         bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
781                 else {
782                         string s(arg);
783                         string const s1 = token(s, ' ', 1);
784                         int const na = s1.empty() ? 0 : lyx::atoi(s1);
785                         openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
786                 }
787         }
788 }
789
790
791 void mathDispatchMathDelim(BufferView * bv, string const & arg)
792 {          
793         if (bv->available()) { 
794                 if (openNewInset(bv, new InsetFormula))
795                         bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
796         }
797 }          
798
799
800 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
801 {          
802         if (bv->available()) { 
803                 if (openNewInset(bv, new InsetFormula))
804                         bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
805         }
806 }          
807
808
809 void mathDispatchInsertMath(BufferView * bv, string const & arg)
810 {
811         if (bv->available()) {
812                 if (arg.size() && arg[0] == '\\')
813                         openNewInset(bv, new InsetFormula(arg));
814                 else
815                         mathDispatchMathMode(bv, arg);
816         }
817 }
818