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.
8 * Copyright: 1996-1998 Alejandro Aguilar Sierra
10 * Version: 0.4, Lyx project.
12 * You are free to use and modify this code under the terms of
13 * the GNU General Public Licence version 2 or later.
21 #pragma implementation "formula.h"
25 #include "commandtags.h"
26 #include "math_cursor.h"
27 #include "math_parser.h"
29 #include "minibuffer.h"
30 #include "BufferView.h"
33 #include "LaTeXFeatures.h"
35 #include "lyx_gui_misc.h"
36 #include "support/LOstream.h"
40 #include "support/lyxlib.h"
42 #include "math_defs.h"
43 #include "math_inset.h"
44 #include "math_parinset.h"
45 #include "math_matrixinset.h"
46 #include "math_rowst.h"
47 #include "math_spaceinset.h"
48 #include "math_deliminset.h"
66 extern string mathed_label;
68 extern char const * latex_special_chars;
70 int greek_kb_flag = 0;
72 LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_fonts (Lgb)
74 static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
81 MathedCursor * InsetFormula::mathcursor = 0;
83 void mathed_init_fonts();
87 void mathedValidate(LaTeXFeatures & features, MathParInset * par);
90 LyXFont WhichFont(short type, int size)
120 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
130 f.setSize(lfont_size);
134 if (type == LM_TC_BSYM) {
144 case LM_ST_SCRIPTSCRIPT:
149 lyxerr << "Mathed Error: wrong font size: " << size << endl;
153 if (type != LM_TC_TEXTRM)
154 f.setColor(LColor::math);
159 void mathed_init_fonts() //removed 'static' because DEC cxx does not
161 // Probably because this func is declared as a friend in math_defs.h
165 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
167 for (int i = 0 ; i < 8 ; ++i) {
168 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
170 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
172 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
174 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
175 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
177 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
179 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
180 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
182 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
184 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
186 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
188 LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
189 MathedInset::df_asc = lyxfont::maxAscent(f);
190 MathedInset::df_des = lyxfont::maxDescent(f);
191 MathedInset::df_width = lyxfont::width('I', f);
205 InsetFormula::InsetFormula(bool display)
207 par = new MathParInset; // this leaks
212 par->SetType(LM_OT_PAR);
213 par->SetStyle(LM_ST_DISPLAY);
218 InsetFormula::InsetFormula(MathParInset * p)
220 if (is_matrix_type(p->GetType()))
221 lyxerr << "InsetFormula::InsetFormula: This shouldn't happen" << endl;
222 par = is_multiline(p->GetType()) ?
223 new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
227 disp_flag = (par->GetType()>0);
232 InsetFormula::~InsetFormula()
238 Inset * InsetFormula::Clone(Buffer const &) const
240 InsetFormula * f = new InsetFormula(par);
246 void InsetFormula::Write(Buffer const * buf, ostream & os) const
249 Latex(buf, os, false, false);
253 int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
256 //#warning Alejandro, the number of lines is not returned in this case
257 // This problem will disapear at 0.13.
258 mathed_write(par, os, &ret, fragile, label);
263 int InsetFormula::Ascii(Buffer const *, ostream & os, int) const
265 par->Write(os, false);
270 int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const
272 return Ascii(buf, os, 0);
276 int InsetFormula::DocBook(Buffer const * buf, ostream & os) const
278 return Ascii(buf, os, 0);
282 // Check if uses AMS macros
283 void InsetFormula::Validate(LaTeXFeatures & features) const
285 if (is_ams(par->GetType()))
286 features.amsstyle = true;
288 // Validation is necessary only if not using AMS math.
289 // To be safe, we will always run mathedValidate.
290 //if (!features.amsstyle)
291 mathedValidate(features, par);
295 void InsetFormula::Read(Buffer const *, LyXLex & lex)
297 istream & is = lex.getStream();
299 mathed_parser_file(is, lex.GetLineNo());
301 // Silly hack to read labels.
303 mathed_label.erase();
305 mathed_parse(0, 0, &par);
307 disp_flag = (par->GetType() > 0);
309 // Update line number
310 lex.setLineNo(mathed_parser_lineno());
312 //if (mathed_label) {
313 if (!mathed_label.empty()) {
314 label = mathed_label;
316 mathed_label.erase();
319 // reading of end_inset in the inset!!!
322 if (lex.GetString() == "\\end_inset")
324 lyxerr << "InsetFormula::Read: Garbage before \\end_inset,"
325 " or missing \\end_inset!" << endl;
334 int InsetFormula::ascent(BufferView *, LyXFont const &) const
336 return par->Ascent() + ((disp_flag) ? 8 : 1);
340 int InsetFormula::descent(BufferView *, LyXFont const &) const
342 return par->Descent() + ((disp_flag) ? 8 : 1);
346 int InsetFormula::width(BufferView * bv, LyXFont const & f) const
348 MathedInset::workWidth = bv->workWidth();
349 lfont_size = f.size();
351 return par->Width(); //+2;
355 void InsetFormula::draw(BufferView * bv, LyXFont const & f,
356 int baseline, float & x, bool) const
358 MathedInset::workWidth = bv->workWidth();
359 Painter & pain = bv->painter();
360 // Seems commenting out solves a problem.
361 LyXFont font = mathed_get_font(LM_TC_TEXTRM, LM_ST_TEXT);
362 font.setSize(f.size());
363 lfont_size = font.size();
364 /// Let's try to wait a bit with this... (Lgb)
365 //UpdatableInset::draw(pain, font, baseline, x);
367 // otherwise a segfault could occur
368 // in some XDrawRectangles (i.e. matrix) (Matthias)
369 if (mathcursor && mathcursor->GetPar() == par) {
370 if (mathcursor->Selection()) {
374 mathcursor->SelGetArea(&xp, &yp, n);
375 pain.fillPolygon(xp, yp, n, LColor::selection);
377 mathcursor->draw(pain, int(x), baseline);
379 par->draw(pain, int(x), baseline);
381 x += float(width(bv, font));
383 if (is_numbered(par->GetType())) {
384 LyXFont wfont = WhichFont(LM_TC_BF, par->size);
385 wfont.setLatex(LyXFont::OFF);
387 if (is_singlely_numbered(par->GetType())) {
390 str = string("(") + label + ")";
393 pain.text(int(x + 20), baseline, str, wfont);
395 MathMatrixInset * mt =
396 static_cast<MathMatrixInset*>(par);
398 MathedRowSt const * crow = mt->getRowSt();
400 y = baseline + crow->getBaseline();
401 if (crow->isNumbered()) {
403 if (!crow->getLabel().empty())
404 str = string("(") + crow->getLabel() + ")";
407 pain.text(int(x + 20), y, str, wfont);
409 crow = crow->getNext();
413 cursor_visible = false;
417 string const InsetFormula::EditMessage() const
419 return _("Math editor mode");
423 void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
425 mathcursor = new MathedCursor(par);
426 if (!bv->lockInset(this))
427 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
429 bv->updateInset(this, false);
432 mathcursor->SetPos(x, y);
438 void InsetFormula::InsetUnlock(BufferView * bv)
441 if (mathcursor->InMacroMode()) {
442 mathcursor->MacroModeClose();
448 bv->updateInset(this, false);
452 // Now a symbol can be inserted only if the inset is locked
453 void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
455 if (s.empty() || !mathcursor) return;
456 mathcursor->Interpret(s);
461 void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const
463 mathcursor->GetPos(x, y);
469 void InsetFormula::ToggleInsetCursor(BufferView * bv)
476 mathcursor->GetPos(x, y);
479 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
480 int asc = lyxfont::maxAscent(font);
481 int desc = lyxfont::maxDescent(font);
484 bv->hideLockedInsetCursor();
486 bv->showLockedInsetCursor(x, y, asc, desc);
487 cursor_visible = !cursor_visible;
491 void InsetFormula::ShowInsetCursor(BufferView * bv, bool)
493 if (!cursor_visible) {
497 mathcursor->GetPos(x, y);
500 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
501 int asc = lyxfont::maxAscent(font);
502 int desc = lyxfont::maxDescent(font);
503 bv->fitLockedInsetCursor(x, y, asc, desc);
505 ToggleInsetCursor(bv);
510 void InsetFormula::HideInsetCursor(BufferView * bv)
513 ToggleInsetCursor(bv);
517 void InsetFormula::ToggleInsetSelection(BufferView * bv)
525 //mathcursor->SelGetArea(n);
526 // XFillPolygon(fl_get_display(), pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin);
530 bv->updateInset(this, false);
535 void InsetFormula::display(bool dspf)
537 if (dspf != disp_flag) {
539 par->SetType(LM_OT_PAR);
540 par->SetStyle(LM_ST_DISPLAY);
542 if (is_multiline(par->GetType())) {
543 MathParInset * p = new MathParInset(par);
547 mathcursor->SetPar(par);
549 par->SetType(LM_OT_MIN);
550 par->SetStyle(LM_ST_TEXT);
551 if (!label.empty()) {
560 vector<string> const InsetFormula::getLabelList() const
562 //#warning This is dirty, I know. Ill clean it at 0.11
563 // Correction, the only way to clean this is with a new kernel: 0.13.
565 vector<string> label_list;
567 if (is_multi_numbered(par->GetType())) {
568 MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
569 MathedRowSt const * crow = mt->getRowSt();
571 if (!crow->getLabel().empty())
572 label_list.push_back(crow->getLabel());
573 crow = crow->getNext();
575 } else if (!label.empty())
576 label_list.push_back(label);
582 void InsetFormula::UpdateLocal(BufferView * bv)
584 par->Metrics(); // To inform lyx kernel the exact size
585 // (there were problems with arrays).
586 bv->updateInset(this, true);
590 void InsetFormula::InsetButtonRelease(BufferView * bv,
591 int x, int y, int /*button*/)
597 mathcursor->SetPos(x, y);
602 bv->updateInset(this, false);
608 void InsetFormula::InsetButtonPress(BufferView * bv,
609 int x, int y, int /*button*/)
612 sel_x = x; sel_y = y;
613 if (mathcursor && mathcursor->Selection()) {
614 mathcursor->SelClear();
615 bv->updateInset(this, false);
620 void InsetFormula::InsetMotionNotify(BufferView * bv,
621 int x, int y, int /*button*/)
623 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
626 mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo);
627 mathcursor->SelStart();
629 mathcursor->GetPos(sel_x, sel_y);
630 } else if (sel_flag) {
634 mathcursor->SetPos(x, y);
636 mathcursor->GetPos(x, y);
637 if (sel_x!= x || sel_y!= y)
638 bv->updateInset(this, false);
639 sel_x = x; sel_y = y;
644 void InsetFormula::InsetKeyPress(XKeyEvent *)
646 lyxerr[Debug::MATHED] << "Used InsetFormula::InsetKeyPress." << endl;
650 // Special Mathed functions
651 bool InsetFormula::SetNumber(bool numbf)
654 short type = par->GetType();
655 bool oldf = is_numbered(type);
656 if (numbf && !oldf) ++type;
657 if (!numbf && oldf) --type;
665 UpdatableInset::RESULT
666 InsetFormula::LocalDispatch(BufferView * bv,
667 int action, string const & arg)
669 // extern char *dispatch_result;
670 MathedTextCodes varcode = LM_TC_MIN;
671 bool was_macro = mathcursor->InMacroMode();
673 bool space_on = false;
674 bool was_selection = mathcursor->Selection();
675 RESULT result = DISPATCHED;
676 static MathSpaceInset * sp= 0;
680 if (mathcursor->getLastCode() == LM_TC_TEX) {
685 // --- Cursor Movements ---------------------------------------------
686 case LFUN_RIGHTSEL: sel = true;
689 result = DISPATCH_RESULT(mathcursor->Right(sel));
690 if (!sel && (result == DISPATCHED))
691 result = DISPATCHED_NOUPDATE;
694 case LFUN_LEFTSEL: sel = true;
697 result = DISPATCH_RESULT(mathcursor->Left(sel));
698 if (!sel && (result == DISPATCHED))
699 result = DISPATCHED_NOUPDATE;
702 case LFUN_UPSEL: sel = true;
704 result = DISPATCH_RESULT(mathcursor->Up(sel));
705 if (!sel && (result == DISPATCHED))
706 result = DISPATCHED_NOUPDATE;
709 case LFUN_DOWNSEL: sel = true;
711 result = DISPATCH_RESULT(mathcursor->Down(sel));
712 if (!sel && (result == DISPATCHED))
713 result = DISPATCHED_NOUPDATE;
717 result = DISPATCHED_NOUPDATE;
721 result = DISPATCHED_NOUPDATE;
723 case LFUN_DELETE_LINE_FORWARD:
724 bv->lockedInsetStoreUndo(Undo::DELETE);
725 mathcursor->DelLine();
730 bv->lockedInsetStoreUndo(Undo::INSERT);
731 byte c = arg.empty() ? '1' : arg[0];
732 mathcursor->Insert(c, LM_TC_CR);
733 if (!label.empty()) {
734 mathcursor->setLabel(label);
737 par = mathcursor->GetPar();
742 bv->lockedInsetStoreUndo(Undo::INSERT);
743 mathcursor->Insert(0, LM_TC_TAB);
747 bv->lockedInsetStoreUndo(Undo::INSERT);
748 mathcursor->Insert('T', LM_TC_TAB);
752 if (!mathcursor->Left())
755 if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
756 bv->updateInset(this, true);
761 bv->lockedInsetStoreUndo(Undo::DELETE);
762 mathcursor->Delete();
763 bv->updateInset(this, true);
766 // sprintf(dispatch_buffer, "%d %d",);
767 // dispatch_result = dispatch_buffer;
775 istringstream ist(arg.c_str());
778 mathcursor->SetPos(x1 + x, y1 + y);
782 /* cursor selection ---------------------------- */
786 mathcursor->MacroModeClose();
787 bv->lockedInsetStoreUndo(Undo::INSERT);
788 mathcursor->SelPaste(); UpdateLocal(bv); break;
790 bv->lockedInsetStoreUndo(Undo::DELETE);
791 mathcursor->SelCut(); UpdateLocal(bv); break;
792 case LFUN_COPY: mathcursor->SelCopy(); break;
795 case LFUN_WORDRIGHTSEL:
796 case LFUN_WORDLEFTSEL:
799 // --- accented characters ------------------------------
801 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
802 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
803 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
804 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
805 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
806 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
807 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
808 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
809 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
810 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
815 if (!greek_kb_flag) {
817 bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
824 case LFUN_GREEK_TOGGLE:
826 greek_kb_flag = (greek_kb_flag) ? 0 : 2;
828 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
830 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
835 case LFUN_BOLD: mathcursor->toggleLastCode(LM_TC_BF); break;
836 case LFUN_SANS: mathcursor->toggleLastCode(LM_TC_SF); break;
837 case LFUN_EMPH: mathcursor->toggleLastCode(LM_TC_CAL); break;
838 case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
839 case LFUN_CODE: mathcursor->toggleLastCode(LM_TC_TT); break;
840 case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR); break;
843 // varcode = LM_TC_TEX;
844 mathcursor->setLastCode(LM_TC_TEX);
845 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
849 case LFUN_MATH_NUMBER:
851 bv->lockedInsetStoreUndo(Undo::INSERT);
853 short type = par->GetType();
854 if (is_numbered(type)) {
856 if (!label.empty()) {
859 bv->owner()->getMiniBuffer()->Set(_("No number"));
862 bv->owner()->getMiniBuffer()->Set(_("Number"));
870 case LFUN_MATH_NONUMBER:
872 if (is_multi_numbered(par->GetType())) {
873 // MathMatrixInset *mt = (MathMatrixInset*)par;
875 // mt->SetNumbered(!mt->IsNumbered());
877 #warning This is a terrible hack! We should find a better solution.
878 while (mathcursor->getLabel() == MathedXIter::error_label) {
879 if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
882 mathcursor->setNumbered();
888 case LFUN_MATH_LIMITS:
890 bv->lockedInsetStoreUndo(Undo::INSERT);
891 if (mathcursor->Limits())
897 latexkeys * l = in_word_set (arg);
898 int sz = (l) ? l->id: -1;
899 mathcursor->SetSize(sz);
904 case LFUN_INSERT_MATH:
906 bv->lockedInsetStoreUndo(Undo::INSERT);
907 InsertSymbol(bv, arg);
911 case LFUN_INSERT_MATRIX:
913 bv->lockedInsetStoreUndo(Undo::INSERT);
915 char s[80], arg2[80];
916 // This is just so that too long args won't ooze out of s.
917 strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
918 k = sscanf(arg2, "%d %d %s", &m, &n, s);
927 MathMatrixInset * p = new MathMatrixInset(m, n);
928 if (mathcursor && p) {
929 if (k > 2 && int(strlen(s)) > m)
930 p->SetAlign(s[0], &s[1]);
931 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
937 case LFUN_MATH_DELIM:
939 bv->lockedInsetStoreUndo(Undo::INSERT);
940 char lf[40], rg[40], arg2[40];
941 int ilf = '(', irg = '.';
943 string vdelim("(){}[]./|");
947 ::strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
948 int n = sscanf(arg2, "%s %s", lf, rg);
949 lf[39] = '\0'; rg[39] = '\0';
956 l = in_word_set(lf, strlen(lf));
957 // Long words will cause l == 0; so check.
960 if (vdelim.find(lf[0]) != string::npos)
968 l = in_word_set(rg, strlen(rg));
971 if (vdelim.find(rg[0]) != string::npos)
976 MathDelimInset * p = new MathDelimInset(ilf, irg);
977 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
982 case LFUN_PROTECTEDSPACE:
984 bv->lockedInsetStoreUndo(Undo::INSERT);
985 sp = new MathSpaceInset(1);
986 mathcursor->Insert(sp);
992 case LFUN_INSERT_LABEL:
994 bv->lockedInsetStoreUndo(Undo::INSERT);
995 if (par->GetType() < LM_OT_PAR)
998 string old_label = is_multiline(par->GetType())
999 ? mathcursor->getLabel() : label;
1001 #warning This is a terrible hack! We should find a better solution.
1002 /// This is needed becuase in some positions mathcursor->cursor->crow
1003 /// is equal to 0, and therefore the label cannot be inserted.
1004 /// So we move the cursor left until mathcursor->cursor->crow != 0.
1005 while (old_label == MathedXIter::error_label) {
1006 if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
1008 old_label = mathcursor->getLabel();
1011 string new_label = arg;
1012 if (new_label.empty()) {
1013 string default_label = (lyxrc.label_init_length >= 0) ? "eq:" : "";
1014 pair<bool, string> res = old_label.empty()
1015 ? askForText(_("Enter new label to insert:"), default_label)
1016 : askForText(_("Enter label:"), old_label);
1019 new_label = frontStrip(strip(res.second));
1022 if (new_label == old_label)
1023 break; // Nothing to do
1025 if (!new_label.empty())
1028 if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
1031 if (is_multi_numbered(par->GetType()))
1032 mathcursor->setLabel(new_label);
1033 // MathMatrixInset *mt = (MathMatrixInset*)par;
1034 // mt->SetLabel(new_label);
1041 case LFUN_MATH_DISPLAY:
1042 bv->lockedInsetStoreUndo(Undo::EDIT);
1043 display(!disp_flag);
1047 // Invalid actions under math mode
1048 case LFUN_MATH_MODE:
1050 if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
1051 bv->owner()->getMiniBuffer()->Set(_("math text mode"));
1052 varcode = LM_TC_TEXTRM;
1054 varcode = LM_TC_VAR;
1056 mathcursor->setLastCode(varcode);
1060 bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
1063 //------- dummy actions
1064 case LFUN_EXEC_COMMAND:
1065 bv->owner()->getMiniBuffer()->PrepareForCommand();
1069 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
1070 unsigned char c = arg[0];
1071 bv->lockedInsetStoreUndo(Undo::INSERT);
1073 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
1075 mathcursor->setAccent(0);
1077 if (c == 0) { // Dead key, do nothing
1078 //lyxerr << "deadkey" << endl;
1082 if (mathcursor->getLastCode() == LM_TC_TEX) {
1083 mathcursor->MacroModeOpen();
1084 mathcursor->clearLastCode();
1085 varcode = LM_TC_MIN;
1088 short f = (mathcursor->getLastCode()) ?
1089 mathcursor->getLastCode() :
1090 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1091 varcode = MathIsAlphaFont(f) ?
1092 static_cast<MathedTextCodes>(f) :
1096 // lyxerr << "Varcode << vardoce;
1097 MathedTextCodes char_code = varcode;
1098 if (greek_kb_flag) {
1100 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
1101 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
1102 'Y', 0, 0, 0, 0 , 'Z' };
1103 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
1104 char_code = LM_TC_RM;
1107 char_code = LM_TC_SYMB;
1109 mathcursor->Insert(c, char_code);
1110 if (greek_kb_flag && char_code == LM_TC_RM )
1111 mathcursor->setLastCode(LM_TC_VAR);
1112 varcode = LM_TC_MIN;
1113 if (greek_kb_flag<2) greek_kb_flag = 0;
1115 if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
1116 mathcursor->Insert(c, LM_TC_TEX);
1118 mathcursor->Insert('}', LM_TC_TEX);
1121 mathcursor->clearLastCode();
1122 // varcode = LM_TC_MIN;
1124 if (c == '_' && varcode == LM_TC_TEX) {
1125 mathcursor->Insert(c, LM_TC_SPECIAL);
1126 mathcursor->clearLastCode();
1127 // varcode = LM_TC_MIN;
1129 if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
1130 mathcursor->MacroModeOpen();
1131 mathcursor->clearLastCode();
1132 mathcursor->Insert(c, LM_TC_MIN);
1135 if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c))
1136 mathcursor->Insert(c, LM_TC_CONST);
1138 if (strchr("+/-*<>=", c))
1139 mathcursor->Insert(c, LM_TC_BOP);
1141 if (strchr(latex_special_chars, c) && c!= '_')
1142 mathcursor->Insert(c, LM_TC_SPECIAL);
1144 if (c == '_' || c == '^') {
1148 mathcursor->Interpret (s);
1152 short f = (mathcursor->getLastCode()) ?
1153 mathcursor->getLastCode() :
1154 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1155 varcode = MathIsAlphaFont(f) ?
1156 static_cast<MathedTextCodes>(f) :
1159 if (varcode == LM_TC_TEXTRM) {
1160 mathcursor->Insert(c, LM_TC_TEXTRM);
1163 mathcursor->MacroModeClose();
1166 int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
1170 if (!mathcursor->Pop() && mathcursor->IsEnd())
1174 if (c == '\'' || c == '@') {
1175 mathcursor->Insert (c, LM_TC_VAR);
1179 mathcursor->MacroModeClose();
1180 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
1181 mathcursor->setLastCode(LM_TC_TEX);
1184 } else if (action == LFUN_MATH_PANEL) {
1185 result = UNDISPATCHED;
1187 // lyxerr << "Closed by action " << action << endl;
1191 if (was_macro != mathcursor->InMacroMode()
1193 && action != LFUN_BACKSPACE)
1195 if (sp && !space_on) sp = 0;
1196 if (mathcursor->Selection() || was_selection)
1197 ToggleInsetSelection(bv);
1199 if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE) ||
1200 (result == UNDISPATCHED))
1201 ShowInsetCursor(bv);
1203 bv->unlockInset(this);
1211 void mathedValidate(LaTeXFeatures & features, MathParInset * par)
1213 MathedIter it(par->GetData());
1215 while (it.OK() && !(features.binom && features.boldsymbol)) {
1217 if (it.IsActive()) {
1218 MathParInset * p = it.GetActiveInset();
1219 if (!features.binom && p->GetType() == LM_OT_MACRO &&
1220 p->GetName() == "binom") {
1221 features.binom = true;
1223 for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
1224 p->setArgumentIdx(i);
1225 mathedValidate(features, p);
1229 MathedInset* p = it.GetInset();
1230 if (!features.boldsymbol &&
1231 p->GetName() == "boldsymbol") {
1232 features.boldsymbol = true;