]> git.lyx.org Git - features.git/blob - src/mathed/formulabase.C
031893628706e4e139234de6e5eab1ce2f5eec2d
[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         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 UpdatableInset::RESULT
309 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
310                             string const & arg)
311 {
312         //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
313         //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
314
315         if (!mathcursor) 
316                 return UNDISPATCHED;
317
318         RESULT result      = DISPATCHED;
319         bool sel           = false;
320         bool was_macro     = mathcursor->inMacroMode();
321         bool was_selection = mathcursor->selection();
322
323         hideInsetCursor(bv);
324
325         mathcursor->normalize();
326
327         switch (action) {
328
329                 // --- Cursor Movements ---------------------------------------------
330
331         case LFUN_RIGHTSEL:
332                 sel = true; // fall through...
333
334         case LFUN_RIGHT:
335                 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
336                 updateLocal(bv, false);
337                 break;
338
339
340         case LFUN_LEFTSEL:
341                 sel = true; // fall through
342
343         case LFUN_LEFT:
344                 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
345                 updateLocal(bv, false);
346                 break;
347
348
349         case LFUN_UPSEL:
350                 sel = true;
351
352         case LFUN_UP:
353                 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
354                 updateLocal(bv, false);
355                 break;
356
357
358         case LFUN_DOWNSEL:
359                 sel = true;
360
361         case LFUN_DOWN:
362                 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
363                 updateLocal(bv, false);
364                 break;
365
366         case LFUN_HOMESEL:
367                 sel = true;
368
369         case LFUN_HOME:
370                 mathcursor->home(sel);
371                 updateLocal(bv, false);
372                 break;
373
374         case LFUN_ENDSEL:
375                 sel = true;
376
377         case LFUN_END:
378                 mathcursor->end(sel);
379                 updateLocal(bv, false);
380                 break;
381
382         case LFUN_DELETE_LINE_FORWARD:
383                 bv->lockedInsetStoreUndo(Undo::DELETE);
384                 mathcursor->delLine();
385                 updateLocal(bv, true);
386                 break;
387
388         case LFUN_TAB:
389                 mathcursor->idxNext();
390                 updateLocal(bv, false);
391                 break;
392
393         case LFUN_SHIFT_TAB:
394                 mathcursor->idxPrev();
395                 updateLocal(bv, false);
396                 break;
397
398         case LFUN_TABINSERT:
399                 bv->lockedInsetStoreUndo(Undo::EDIT);
400                 mathcursor->splitCell();
401                 updateLocal(bv, true);
402                 break;
403
404         case LFUN_BACKSPACE:
405                 bv->lockedInsetStoreUndo(Undo::DELETE);
406                 mathcursor->backspace();
407                 bv->updateInset(this, true);
408                 break;
409
410         case LFUN_DELETE:
411                 bv->lockedInsetStoreUndo(Undo::DELETE);
412                 mathcursor->erase();
413                 bv->updateInset(this, true);
414                 break;
415
416                 //    case LFUN_GETXY:
417                 //      sprintf(dispatch_buffer, "%d %d",);
418                 //      dispatch_result = dispatch_buffer;
419                 //      break;
420         case LFUN_SETXY: {
421                 lyxerr << "LFUN_SETXY broken!\n";
422                 int x;
423                 int y;
424                 int x1;
425                 int y1;
426                 istringstream is(arg.c_str());
427                 is >> x >> y;
428                 par()->getXY(x1, y1);
429                 mathcursor->setPos(x1 + x, y1 + y);
430                 updateLocal(bv, false);
431                 break;
432         }
433
434         case LFUN_PASTE:
435                 if (was_macro)
436                         mathcursor->macroModeClose();
437                 bv->lockedInsetStoreUndo(Undo::INSERT);
438                 mathcursor->selPaste();
439                 updateLocal(bv, true);
440                 break;
441
442         case LFUN_CUT:
443                 bv->lockedInsetStoreUndo(Undo::DELETE);
444                 mathcursor->selCut();
445                 updateLocal(bv, true);
446                 break;
447
448         case LFUN_COPY:
449                 mathcursor->selCopy();
450                 break;
451
452         case LFUN_WORDRIGHTSEL:
453         case LFUN_WORDLEFTSEL:
454                 break;
455
456                 // --- accented characters ------------------------------
457
458         case LFUN_UMLAUT:       handleAccent(bv, "ddot"); break;
459         case LFUN_CIRCUMFLEX:   handleAccent(bv, "hat"); break;
460         case LFUN_GRAVE:        handleAccent(bv, "grave"); break;
461         case LFUN_ACUTE:        handleAccent(bv, "acute"); break;
462         case LFUN_TILDE:        handleAccent(bv, "tilde"); break;
463         case LFUN_MACRON:       handleAccent(bv, "bar"); break;
464         case LFUN_DOT:          handleAccent(bv, "dot"); break;
465         case LFUN_CARON:        handleAccent(bv, "check"); break;
466         case LFUN_BREVE:        handleAccent(bv, "breve"); break;
467         case LFUN_VECTOR:       handleAccent(bv, "vec"); break;
468
469         //  Math fonts
470         case LFUN_GREEK:        handleFont(bv, LM_TC_GREEK1); break;
471         case LFUN_GREEK_TOGGLE: handleFont(bv, LM_TC_GREEK); break;
472         case LFUN_BOLD:         handleFont(bv, LM_TC_BF); break;
473         case LFUN_SANS:         handleFont(bv, LM_TC_SF); break;
474         case LFUN_EMPH:         handleFont(bv, LM_TC_CAL); break;
475         case LFUN_ROMAN:        handleFont(bv, LM_TC_RM); break;
476         case LFUN_CODE:         handleFont(bv, LM_TC_TT); break;
477         case LFUN_NOUN:         handleFont(bv, LM_TC_BB); break;
478         case LFUN_DEFAULT:      handleFont(bv, LM_TC_VAR); 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                 //MathSpaceInset * p = mathcursor->prevSpaceInset();
512                 //if (p) 
513                 //      p->incSpace();
514                 //else
515                 //      mathcursor->insert(new MathSpaceInset(1));
516                 mathcursor->insert(new MathSpaceInset(1));
517                 updateLocal(bv, true);
518                 break;
519         }
520
521         case LFUN_MATH_DELIM:
522         {
523                 bv->lockedInsetStoreUndo(Undo::INSERT);
524                 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
525                 string ls;
526                 string rs;
527                 istringstream is(arg.c_str());
528                 is >> ls >> rs;
529                 if (!is) {
530                         lyxerr << "can't parse delimeters from '" << arg << "'\n";
531                         break;
532                 }
533                 bv->lockedInsetStoreUndo(Undo::EDIT);
534                 mathcursor->handleDelim(ls, rs);
535                 updateLocal(bv, true);
536                 break;
537         }
538
539         case LFUN_PROTECTEDSPACE:
540                 //lyxerr << " called LFUN_PROTECTEDSPACE\n";
541                 bv->lockedInsetStoreUndo(Undo::INSERT);
542                 mathcursor->insert(new MathSpaceInset(1));
543                 updateLocal(bv, true);
544                 break;
545
546         case LFUN_UNDO:
547                 bv->owner()->message(_("Invalid action in math mode!"));
548                 break;
549
550
551         case LFUN_MATH_HALIGN:
552         {
553                 bv->lockedInsetStoreUndo(Undo::INSERT);
554                 lyxerr << "handling halign '" << arg << "'\n";
555                 MathInset::idx_type idx;
556                 MathArrayInset * p = matrixpar(idx);
557                 if (!p)
558                         break; 
559                 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
560                 updateLocal(bv, true);
561                 break;
562         }
563
564         case LFUN_MATH_VALIGN:
565         {
566                 bv->lockedInsetStoreUndo(Undo::INSERT);
567                 lyxerr << "handling valign '" << arg << "'\n";
568                 MathInset::idx_type idx;
569                 MathArrayInset * p = matrixpar(idx);
570                 if (!p)
571                         break; 
572                 p->valign(arg.size() ? arg[0] : 'c');
573                 updateLocal(bv, true);
574                 break;
575         }
576
577         case LFUN_MATH_ROW_INSERT:
578         {
579                 bv->lockedInsetStoreUndo(Undo::INSERT);
580                 MathInset::idx_type idx;
581                 MathArrayInset * p = matrixpar(idx);
582                 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
583                 if (!p)
584                         break; 
585                 p->addRow(p->row(idx));
586                 updateLocal(bv, true);
587                 break;
588         }
589
590         case LFUN_MATH_ROW_DELETE:
591         {
592                 bv->lockedInsetStoreUndo(Undo::INSERT);
593                 MathInset::idx_type idx;
594                 MathArrayInset * p = matrixpar(idx);
595                 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
596                 if (!p)
597                         break; 
598                 p->delRow(p->row(idx));
599                 updateLocal(bv, true);
600                 break;
601         }
602
603         case LFUN_MATH_COLUMN_INSERT:
604         {
605                 bv->lockedInsetStoreUndo(Undo::INSERT);
606                 MathInset::idx_type idx;
607                 MathArrayInset * p = matrixpar(idx);
608                 if (!p)
609                         break; 
610                 p->addCol(p->col(idx));
611                 updateLocal(bv, true);
612                 break;
613         }
614
615         case LFUN_MATH_COLUMN_DELETE:
616         {
617                 bv->lockedInsetStoreUndo(Undo::INSERT);
618                 MathInset::idx_type idx;
619                 MathArrayInset * p = matrixpar(idx);
620                 if (!p)
621                         break; 
622                 p->delCol(p->col(idx));
623                 updateLocal(bv, true);
624                 break;
625         }
626
627         case LFUN_EXEC_COMMAND:
628                 result = UNDISPATCHED;
629                 break;
630
631         case -1:
632         case LFUN_INSERT_MATH:
633         case LFUN_SELFINSERT:
634                 if (!arg.empty()) {
635                         bv->lockedInsetStoreUndo(Undo::INSERT);
636                         mathcursor->interpret(arg);
637                         updateLocal(bv, true);
638                 }
639                 break;
640
641         case LFUN_MATH_PANEL:
642                 result = UNDISPATCHED;
643                 break;
644
645         default:
646                 result = UNDISPATCHED;
647         }
648
649         //mathcursor->normalize();
650
651         if (was_macro != mathcursor->inMacroMode()
652                                 && action >= 0 && action != LFUN_BACKSPACE) 
653                 updateLocal(bv, true);
654         
655         if (mathcursor->selection() || was_selection)
656                 toggleInsetSelection(bv);
657
658         if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
659             result == UNDISPATCHED)
660                 showInsetCursor(bv);
661         else
662                 bv->unlockInset(this);
663
664         return result;  // original version
665 }
666
667
668 Inset::Code InsetFormulaBase::lyxCode() const
669 {
670         return Inset::MATH_CODE;
671 }
672
673
674 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
675 {
676         if (bv->available()) {
677                 // use selection if available..
678                 //string sel;
679                 //if (action == LFUN_MATH_IMPORT_SELECTION)
680                 //      sel = "";
681                 //else
682
683                 string sel = bv->getLyXText()->selectionAsString(bv->buffer(),
684                                                                  false);
685
686                 InsetFormulaBase * f;
687                 if (sel.empty()) {
688                         f = new InsetFormula;
689                         if (openNewInset(bv, f)) {
690                                 // don't do that also for LFUN_MATH_MODE unless you want end up with
691                                 // always changing to mathrm when opening an inlined inset
692                                 // -- I really hate "LyXfunc overloading"...
693                                 if (display)
694                                         f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
695                                 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
696                         }
697                 } else {
698                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
699                         // formula otherwise
700                         if (sel.find("\\newcommand") == string::npos) 
701                                 f = new InsetFormula(sel);
702                         else
703                                 f = new InsetFormulaMacro(sel);
704                         bv->getLyXText()->cutSelection(bv);
705                         openNewInset(bv, f);
706                 }
707         }
708         bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
709 }
710
711
712 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
713 {
714         mathDispatchCreation(bv, arg, true);
715 }
716
717         
718 void mathDispatchMathMode(BufferView * bv, string const & arg)
719 {
720         mathDispatchCreation(bv, arg, false);
721 }
722
723
724 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
725 {
726         mathDispatchCreation(bv, arg, true);
727 }
728
729
730 void mathDispatchMathMacro(BufferView * bv, string const & arg)
731 {
732         if (bv->available()) {
733                 if (arg.empty())
734                         bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
735                 else {
736                         string s(arg);
737                         string const s1 = token(s, ' ', 1);
738                         int const na = s1.empty() ? 0 : lyx::atoi(s1);
739                         openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
740                 }
741         }
742 }
743
744
745 void mathDispatchMathDelim(BufferView * bv, string const & arg)
746 {          
747         if (bv->available()) { 
748                 if (openNewInset(bv, new InsetFormula))
749                         bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
750         }
751 }          
752
753
754 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
755 {          
756         if (bv->available()) { 
757                 if (openNewInset(bv, new InsetFormula))
758                         bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
759         }
760 }          
761
762
763 void mathDispatchInsertMath(BufferView * bv, string const & arg)
764 {
765         if (bv->available()) {
766                 if (arg.size() && arg[0] == '\\')
767                         openNewInset(bv, new InsetFormula(arg));
768                 else
769                         mathDispatchMathMode(bv, arg);
770         }
771 }
772
773
774 void mathDispatchGreek(BufferView * bv, string const & arg)
775 {          
776         if (bv->available()) { 
777                 InsetFormula * f = new InsetFormula;
778                 if (openNewInset(bv, f)) {
779                         bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, string());
780                         bv->theLockingInset()->localDispatch(bv, LFUN_SELFINSERT, arg);
781                         bv->unlockInset(f);
782                 }
783         }
784 }          
785