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_inset.h"
43 #include "math_parinset.h"
44 #include "math_matrixinset.h"
45 #include "math_rowst.h"
46 #include "math_spaceinset.h"
47 #include "math_deliminset.h"
48 #include "mathed/support.h"
65 extern string mathed_label;
67 extern char const * latex_special_chars;
69 int greek_kb_flag = 0;
71 LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_fonts (Lgb)
73 static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
80 MathedCursor * InsetFormula::mathcursor = 0;
82 void mathed_init_fonts();
86 void mathedValidate(LaTeXFeatures & features, MathParInset * par);
89 LyXFont WhichFont(short type, int size)
119 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
129 f.setSize(lfont_size);
133 if (type == LM_TC_BSYM) {
143 case LM_ST_SCRIPTSCRIPT:
148 lyxerr << "Mathed Error: wrong font size: " << size << endl;
152 if (type != LM_TC_TEXTRM)
153 f.setColor(LColor::math);
158 void mathed_init_fonts() //removed 'static' because DEC cxx does not
160 // Probably because this func is declared as a friend in math_defs.h
164 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
166 for (int i = 0 ; i < 8 ; ++i) {
167 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
169 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
171 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
173 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
174 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
176 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
178 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
179 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
181 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
183 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
185 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
187 LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
188 MathedInset::df_asc = lyxfont::maxAscent(f);
189 MathedInset::df_des = lyxfont::maxDescent(f);
190 MathedInset::df_width = lyxfont::width('I', f);
204 InsetFormula::InsetFormula(bool display)
206 par = new MathParInset; // this leaks
211 par->SetType(LM_OT_PAR);
212 par->SetStyle(LM_ST_DISPLAY);
217 InsetFormula::InsetFormula(MathParInset * p)
219 if (is_matrix_type(p->GetType()))
220 lyxerr << "InsetFormula::InsetFormula: This shouldn't happen" << endl;
221 par = is_multiline(p->GetType()) ?
222 new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
226 disp_flag = (par->GetType()>0);
231 InsetFormula::~InsetFormula()
237 Inset * InsetFormula::Clone(Buffer const &) const
239 InsetFormula * f = new InsetFormula(par);
245 void InsetFormula::Write(Buffer const * buf, ostream & os) const
248 Latex(buf, os, false, false);
252 int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
255 //#warning Alejandro, the number of lines is not returned in this case
256 // This problem will disapear at 0.13.
257 mathed_write(par, os, &ret, fragile, label);
262 int InsetFormula::Ascii(Buffer const *, ostream & os, int) const
264 par->Write(os, false);
269 int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const
271 return Ascii(buf, os, 0);
275 int InsetFormula::DocBook(Buffer const * buf, ostream & os) const
277 return Ascii(buf, os, 0);
281 // Check if uses AMS macros
282 void InsetFormula::Validate(LaTeXFeatures & features) const
284 if (is_ams(par->GetType()))
285 features.amsstyle = true;
287 // Validation is necessary only if not using AMS math.
288 // To be safe, we will always run mathedValidate.
289 //if (!features.amsstyle)
290 mathedValidate(features, par);
294 void InsetFormula::Read(Buffer const *, LyXLex & lex)
296 istream & is = lex.getStream();
298 mathed_parser_file(is, lex.GetLineNo());
300 // Silly hack to read labels.
302 mathed_label.erase();
304 mathed_parse(0, 0, &par);
306 disp_flag = (par->GetType() > 0);
308 // Update line number
309 lex.setLineNo(mathed_parser_lineno());
311 //if (mathed_label) {
312 if (!mathed_label.empty()) {
313 label = mathed_label;
315 mathed_label.erase();
318 // reading of end_inset in the inset!!!
321 if (lex.GetString() == "\\end_inset")
323 lyxerr << "InsetFormula::Read: Garbage before \\end_inset,"
324 " or missing \\end_inset!" << endl;
333 int InsetFormula::ascent(BufferView *, LyXFont const &) const
335 return par->Ascent() + ((disp_flag) ? 8 : 1);
339 int InsetFormula::descent(BufferView *, LyXFont const &) const
341 return par->Descent() + ((disp_flag) ? 8 : 1);
345 int InsetFormula::width(BufferView * bv, LyXFont const & f) const
347 MathedInset::workWidth = bv->workWidth();
348 lfont_size = f.size();
350 return par->Width(); //+2;
354 void InsetFormula::draw(BufferView * bv, LyXFont const & f,
355 int baseline, float & x, bool) const
357 MathedInset::workWidth = bv->workWidth();
358 Painter & pain = bv->painter();
359 // Seems commenting out solves a problem.
360 LyXFont font = mathed_get_font(LM_TC_TEXTRM, LM_ST_TEXT);
361 font.setSize(f.size());
362 lfont_size = font.size();
363 /// Let's try to wait a bit with this... (Lgb)
364 //UpdatableInset::draw(pain, font, baseline, x);
366 // otherwise a segfault could occur
367 // in some XDrawRectangles (i.e. matrix) (Matthias)
368 if (mathcursor && mathcursor->GetPar() == par) {
369 if (mathcursor->Selection()) {
373 mathcursor->SelGetArea(&xp, &yp, n);
374 pain.fillPolygon(xp, yp, n, LColor::selection);
376 mathcursor->draw(pain, int(x), baseline);
378 par->draw(pain, int(x), baseline);
380 x += float(width(bv, font));
382 if (is_numbered(par->GetType())) {
383 LyXFont wfont = WhichFont(LM_TC_BF, par->size);
384 wfont.setLatex(LyXFont::OFF);
386 if (is_singlely_numbered(par->GetType())) {
389 str = string("(") + label + ")";
392 pain.text(int(x + 20), baseline, str, wfont);
394 MathMatrixInset * mt =
395 static_cast<MathMatrixInset*>(par);
397 MathedRowSt const * crow = mt->getRowSt();
399 y = baseline + crow->getBaseline();
400 if (crow->isNumbered()) {
402 if (!crow->getLabel().empty())
403 str = string("(") + crow->getLabel() + ")";
406 pain.text(int(x + 20), y, str, wfont);
408 crow = crow->getNext();
412 cursor_visible = false;
416 string const InsetFormula::EditMessage() const
418 return _("Math editor mode");
422 void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
424 mathcursor = new MathedCursor(par);
425 if (!bv->lockInset(this))
426 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
428 bv->updateInset(this, false);
431 mathcursor->SetPos(x, y);
437 void InsetFormula::InsetUnlock(BufferView * bv)
440 if (mathcursor->InMacroMode()) {
441 mathcursor->MacroModeClose();
447 bv->updateInset(this, false);
451 // Now a symbol can be inserted only if the inset is locked
452 void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
454 if (s.empty() || !mathcursor) return;
455 mathcursor->Interpret(s);
460 void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const
462 mathcursor->GetPos(x, y);
468 void InsetFormula::ToggleInsetCursor(BufferView * bv)
475 mathcursor->GetPos(x, y);
478 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
479 int asc = lyxfont::maxAscent(font);
480 int desc = lyxfont::maxDescent(font);
483 bv->hideLockedInsetCursor();
485 bv->showLockedInsetCursor(x, y, asc, desc);
486 cursor_visible = !cursor_visible;
490 void InsetFormula::ShowInsetCursor(BufferView * bv, bool)
492 if (!cursor_visible) {
496 mathcursor->GetPos(x, y);
499 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
500 int asc = lyxfont::maxAscent(font);
501 int desc = lyxfont::maxDescent(font);
502 bv->fitLockedInsetCursor(x, y, asc, desc);
504 ToggleInsetCursor(bv);
509 void InsetFormula::HideInsetCursor(BufferView * bv)
512 ToggleInsetCursor(bv);
516 void InsetFormula::ToggleInsetSelection(BufferView * bv)
524 //mathcursor->SelGetArea(n);
525 // XFillPolygon(fl_get_display(), pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin);
529 bv->updateInset(this, false);
534 void InsetFormula::display(bool dspf)
536 if (dspf != disp_flag) {
538 par->SetType(LM_OT_PAR);
539 par->SetStyle(LM_ST_DISPLAY);
541 if (is_multiline(par->GetType())) {
542 MathParInset * p = new MathParInset(par);
546 mathcursor->SetPar(par);
548 par->SetType(LM_OT_MIN);
549 par->SetStyle(LM_ST_TEXT);
550 if (!label.empty()) {
559 vector<string> const InsetFormula::getLabelList() const
561 //#warning This is dirty, I know. Ill clean it at 0.11
562 // Correction, the only way to clean this is with a new kernel: 0.13.
564 vector<string> label_list;
566 if (is_multi_numbered(par->GetType())) {
567 MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
568 MathedRowSt const * crow = mt->getRowSt();
570 if (!crow->getLabel().empty())
571 label_list.push_back(crow->getLabel());
572 crow = crow->getNext();
574 } else if (!label.empty())
575 label_list.push_back(label);
581 void InsetFormula::UpdateLocal(BufferView * bv)
583 par->Metrics(); // To inform lyx kernel the exact size
584 // (there were problems with arrays).
585 bv->updateInset(this, true);
589 void InsetFormula::InsetButtonRelease(BufferView * bv,
590 int x, int y, int /*button*/)
596 mathcursor->SetPos(x, y);
601 bv->updateInset(this, false);
607 void InsetFormula::InsetButtonPress(BufferView * bv,
608 int x, int y, int /*button*/)
611 sel_x = x; sel_y = y;
612 if (mathcursor && mathcursor->Selection()) {
613 mathcursor->SelClear();
614 bv->updateInset(this, false);
619 void InsetFormula::InsetMotionNotify(BufferView * bv,
620 int x, int y, int /*button*/)
622 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
625 mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo);
626 mathcursor->SelStart();
628 mathcursor->GetPos(sel_x, sel_y);
629 } else if (sel_flag) {
633 mathcursor->SetPos(x, y);
635 mathcursor->GetPos(x, y);
636 if (sel_x!= x || sel_y!= y)
637 bv->updateInset(this, false);
638 sel_x = x; sel_y = y;
643 void InsetFormula::InsetKeyPress(XKeyEvent *)
645 lyxerr[Debug::MATHED] << "Used InsetFormula::InsetKeyPress." << endl;
649 // Special Mathed functions
650 bool InsetFormula::SetNumber(bool numbf)
653 short type = par->GetType();
654 bool oldf = is_numbered(type);
655 if (numbf && !oldf) ++type;
656 if (!numbf && oldf) --type;
664 UpdatableInset::RESULT
665 InsetFormula::LocalDispatch(BufferView * bv,
666 int action, string const & arg)
668 // extern char *dispatch_result;
669 MathedTextCodes varcode = LM_TC_MIN;
670 bool was_macro = mathcursor->InMacroMode();
672 bool space_on = false;
673 bool was_selection = mathcursor->Selection();
674 RESULT result = DISPATCHED;
675 static MathSpaceInset * sp= 0;
679 if (mathcursor->getLastCode() == LM_TC_TEX) {
684 // --- Cursor Movements ---------------------------------------------
685 case LFUN_RIGHTSEL: sel = true;
688 result = DISPATCH_RESULT(mathcursor->Right(sel));
689 if (!sel && (result == DISPATCHED))
690 result = DISPATCHED_NOUPDATE;
693 case LFUN_LEFTSEL: sel = true;
696 result = DISPATCH_RESULT(mathcursor->Left(sel));
697 if (!sel && (result == DISPATCHED))
698 result = DISPATCHED_NOUPDATE;
701 case LFUN_UPSEL: sel = true;
703 result = DISPATCH_RESULT(mathcursor->Up(sel));
704 if (!sel && (result == DISPATCHED))
705 result = DISPATCHED_NOUPDATE;
708 case LFUN_DOWNSEL: sel = true;
710 result = DISPATCH_RESULT(mathcursor->Down(sel));
711 if (!sel && (result == DISPATCHED))
712 result = DISPATCHED_NOUPDATE;
716 result = DISPATCHED_NOUPDATE;
720 result = DISPATCHED_NOUPDATE;
722 case LFUN_DELETE_LINE_FORWARD:
723 bv->lockedInsetStoreUndo(Undo::DELETE);
724 mathcursor->DelLine();
729 bv->lockedInsetStoreUndo(Undo::INSERT);
730 byte c = arg.empty() ? '1' : arg[0];
731 mathcursor->Insert(c, LM_TC_CR);
732 if (!label.empty()) {
733 mathcursor->setLabel(label);
736 par = mathcursor->GetPar();
741 bv->lockedInsetStoreUndo(Undo::INSERT);
742 mathcursor->Insert(0, LM_TC_TAB);
746 bv->lockedInsetStoreUndo(Undo::INSERT);
747 mathcursor->Insert('T', LM_TC_TAB);
751 if (!mathcursor->Left())
754 if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
755 bv->updateInset(this, true);
760 bv->lockedInsetStoreUndo(Undo::DELETE);
761 mathcursor->Delete();
762 bv->updateInset(this, true);
765 // sprintf(dispatch_buffer, "%d %d",);
766 // dispatch_result = dispatch_buffer;
774 istringstream ist(arg.c_str());
777 mathcursor->SetPos(x1 + x, y1 + y);
781 /* cursor selection ---------------------------- */
785 mathcursor->MacroModeClose();
786 bv->lockedInsetStoreUndo(Undo::INSERT);
787 mathcursor->SelPaste(); UpdateLocal(bv); break;
789 bv->lockedInsetStoreUndo(Undo::DELETE);
790 mathcursor->SelCut(); UpdateLocal(bv); break;
791 case LFUN_COPY: mathcursor->SelCopy(); break;
794 case LFUN_WORDRIGHTSEL:
795 case LFUN_WORDLEFTSEL:
798 // --- accented characters ------------------------------
800 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
801 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
802 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
803 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
804 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
805 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
806 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
807 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
808 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
809 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
814 if (!greek_kb_flag) {
816 bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
823 case LFUN_GREEK_TOGGLE:
825 greek_kb_flag = (greek_kb_flag) ? 0 : 2;
827 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
829 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
834 case LFUN_BOLD: mathcursor->toggleLastCode(LM_TC_BF); break;
835 case LFUN_SANS: mathcursor->toggleLastCode(LM_TC_SF); break;
836 case LFUN_EMPH: mathcursor->toggleLastCode(LM_TC_CAL); break;
837 case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
838 case LFUN_CODE: mathcursor->toggleLastCode(LM_TC_TT); break;
839 case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR); break;
842 // varcode = LM_TC_TEX;
843 mathcursor->setLastCode(LM_TC_TEX);
844 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
848 case LFUN_MATH_NUMBER:
850 bv->lockedInsetStoreUndo(Undo::INSERT);
852 short type = par->GetType();
853 if (is_numbered(type)) {
855 if (!label.empty()) {
858 bv->owner()->getMiniBuffer()->Set(_("No number"));
861 bv->owner()->getMiniBuffer()->Set(_("Number"));
869 case LFUN_MATH_NONUMBER:
871 if (is_multi_numbered(par->GetType())) {
872 // MathMatrixInset *mt = (MathMatrixInset*)par;
874 // mt->SetNumbered(!mt->IsNumbered());
876 #warning This is a terrible hack! We should find a better solution.
877 while (mathcursor->getLabel() == MathedXIter::error_label) {
878 if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
881 mathcursor->setNumbered();
887 case LFUN_MATH_LIMITS:
889 bv->lockedInsetStoreUndo(Undo::INSERT);
890 if (mathcursor->Limits())
896 latexkeys * l = in_word_set (arg);
897 int sz = (l) ? l->id: -1;
898 mathcursor->SetSize(sz);
903 case LFUN_INSERT_MATH:
905 bv->lockedInsetStoreUndo(Undo::INSERT);
906 InsertSymbol(bv, arg);
910 case LFUN_INSERT_MATRIX:
912 bv->lockedInsetStoreUndo(Undo::INSERT);
914 char s[80], arg2[80];
915 // This is just so that too long args won't ooze out of s.
916 strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
917 k = sscanf(arg2, "%d %d %s", &m, &n, s);
926 MathMatrixInset * p = new MathMatrixInset(m, n);
927 if (mathcursor && p) {
928 if (k > 2 && int(strlen(s)) > m)
929 p->SetAlign(s[0], &s[1]);
930 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
936 case LFUN_MATH_DELIM:
938 bv->lockedInsetStoreUndo(Undo::INSERT);
939 char lf[40], rg[40], arg2[40];
940 int ilf = '(', irg = '.';
942 string vdelim("(){}[]./|");
946 ::strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
947 int n = sscanf(arg2, "%s %s", lf, rg);
948 lf[39] = '\0'; rg[39] = '\0';
955 l = in_word_set(lf, strlen(lf));
956 // Long words will cause l == 0; so check.
959 if (vdelim.find(lf[0]) != string::npos)
967 l = in_word_set(rg, strlen(rg));
970 if (vdelim.find(rg[0]) != string::npos)
975 MathDelimInset * p = new MathDelimInset(ilf, irg);
976 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
981 case LFUN_PROTECTEDSPACE:
983 bv->lockedInsetStoreUndo(Undo::INSERT);
984 sp = new MathSpaceInset(1);
985 mathcursor->Insert(sp);
991 case LFUN_INSERT_LABEL:
993 bv->lockedInsetStoreUndo(Undo::INSERT);
994 if (par->GetType() < LM_OT_PAR)
997 string old_label = is_multiline(par->GetType())
998 ? mathcursor->getLabel() : label;
1000 #warning This is a terrible hack! We should find a better solution.
1001 /// This is needed becuase in some positions mathcursor->cursor->crow
1002 /// is equal to 0, and therefore the label cannot be inserted.
1003 /// So we move the cursor left until mathcursor->cursor->crow != 0.
1004 while (old_label == MathedXIter::error_label) {
1005 if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
1007 old_label = mathcursor->getLabel();
1010 string new_label = arg;
1011 if (new_label.empty()) {
1012 string default_label = (lyxrc.label_init_length >= 0) ? "eq:" : "";
1013 pair<bool, string> res = old_label.empty()
1014 ? askForText(_("Enter new label to insert:"), default_label)
1015 : askForText(_("Enter label:"), old_label);
1018 new_label = frontStrip(strip(res.second));
1021 if (new_label == old_label)
1022 break; // Nothing to do
1024 if (!new_label.empty())
1027 if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
1030 if (is_multi_numbered(par->GetType()))
1031 mathcursor->setLabel(new_label);
1032 // MathMatrixInset *mt = (MathMatrixInset*)par;
1033 // mt->SetLabel(new_label);
1040 case LFUN_MATH_DISPLAY:
1041 bv->lockedInsetStoreUndo(Undo::EDIT);
1042 display(!disp_flag);
1046 // Invalid actions under math mode
1047 case LFUN_MATH_MODE:
1049 if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
1050 bv->owner()->getMiniBuffer()->Set(_("math text mode"));
1051 varcode = LM_TC_TEXTRM;
1053 varcode = LM_TC_VAR;
1055 mathcursor->setLastCode(varcode);
1059 bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
1062 //------- dummy actions
1063 case LFUN_EXEC_COMMAND:
1064 bv->owner()->getMiniBuffer()->PrepareForCommand();
1068 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
1069 unsigned char c = arg[0];
1070 bv->lockedInsetStoreUndo(Undo::INSERT);
1072 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
1074 mathcursor->setAccent(0);
1076 if (c == 0) { // Dead key, do nothing
1077 //lyxerr << "deadkey" << endl;
1081 if (mathcursor->getLastCode() == LM_TC_TEX) {
1082 mathcursor->MacroModeOpen();
1083 mathcursor->clearLastCode();
1084 varcode = LM_TC_MIN;
1087 short f = (mathcursor->getLastCode()) ?
1088 mathcursor->getLastCode() :
1089 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1090 varcode = MathIsAlphaFont(f) ?
1091 static_cast<MathedTextCodes>(f) :
1095 // lyxerr << "Varcode << vardoce;
1096 MathedTextCodes char_code = varcode;
1097 if (greek_kb_flag) {
1099 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
1100 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
1101 'Y', 0, 0, 0, 0 , 'Z' };
1102 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
1103 char_code = LM_TC_RM;
1106 char_code = LM_TC_SYMB;
1108 mathcursor->Insert(c, char_code);
1109 if (greek_kb_flag && char_code == LM_TC_RM )
1110 mathcursor->setLastCode(LM_TC_VAR);
1111 varcode = LM_TC_MIN;
1112 if (greek_kb_flag<2) greek_kb_flag = 0;
1114 if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
1115 mathcursor->Insert(c, LM_TC_TEX);
1117 mathcursor->Insert('}', LM_TC_TEX);
1120 mathcursor->clearLastCode();
1121 // varcode = LM_TC_MIN;
1123 if (c == '_' && varcode == LM_TC_TEX) {
1124 mathcursor->Insert(c, LM_TC_SPECIAL);
1125 mathcursor->clearLastCode();
1126 // varcode = LM_TC_MIN;
1128 if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
1129 mathcursor->MacroModeOpen();
1130 mathcursor->clearLastCode();
1131 mathcursor->Insert(c, LM_TC_MIN);
1134 if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c))
1135 mathcursor->Insert(c, LM_TC_CONST);
1137 if (strchr("+/-*<>=", c))
1138 mathcursor->Insert(c, LM_TC_BOP);
1140 if (strchr(latex_special_chars, c) && c!= '_')
1141 mathcursor->Insert(c, LM_TC_SPECIAL);
1143 if (c == '_' || c == '^') {
1147 mathcursor->Interpret (s);
1151 short f = (mathcursor->getLastCode()) ?
1152 mathcursor->getLastCode() :
1153 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1154 varcode = MathIsAlphaFont(f) ?
1155 static_cast<MathedTextCodes>(f) :
1158 if (varcode == LM_TC_TEXTRM) {
1159 mathcursor->Insert(c, LM_TC_TEXTRM);
1162 mathcursor->MacroModeClose();
1165 int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
1169 if (!mathcursor->Pop() && mathcursor->IsEnd())
1173 if (c == '\'' || c == '@') {
1174 mathcursor->Insert (c, LM_TC_VAR);
1178 mathcursor->MacroModeClose();
1179 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
1180 mathcursor->setLastCode(LM_TC_TEX);
1183 } else if (action == LFUN_MATH_PANEL) {
1184 result = UNDISPATCHED;
1186 // lyxerr << "Closed by action " << action << endl;
1190 if (was_macro != mathcursor->InMacroMode()
1192 && action != LFUN_BACKSPACE)
1194 if (sp && !space_on) sp = 0;
1195 if (mathcursor->Selection() || was_selection)
1196 ToggleInsetSelection(bv);
1198 if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE) ||
1199 (result == UNDISPATCHED))
1200 ShowInsetCursor(bv);
1202 bv->unlockInset(this);
1210 void mathedValidate(LaTeXFeatures & features, MathParInset * par)
1212 MathedIter it(par->GetData());
1214 while (it.OK() && !(features.binom && features.boldsymbol)) {
1216 if (it.IsActive()) {
1217 MathParInset * p = it.GetActiveInset();
1218 if (!features.binom && p->GetType() == LM_OT_MACRO &&
1219 p->GetName() == "binom") {
1220 features.binom = true;
1222 for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
1223 p->setArgumentIdx(i);
1224 mathedValidate(features, p);
1228 MathedInset* p = it.GetInset();
1229 if (!features.boldsymbol &&
1230 p->GetName() == "boldsymbol") {
1231 features.boldsymbol = true;