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