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