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