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