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