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