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