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