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: (c) 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.
22 #pragma implementation "formula.h"
26 #include "commandtags.h"
27 #include "math_cursor.h"
28 #include "math_parser.h"
31 #include "minibuffer.h"
32 #include "BufferView.h"
35 #include "LaTeXFeatures.h"
37 #include "lyx_gui_misc.h"
38 #include "support/LOstream.h"
42 extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
44 extern char * mathed_label;
46 extern BufferView * current_view;
47 extern char const * latex_special_chars;
49 short greek_kb_flag = 0;
51 LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_fonts (Lgb)
53 static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
56 static int sel_x, sel_y;
58 MathedCursor * InsetFormula::mathcursor = 0;
61 int MathedInset::df_asc;
62 int MathedInset::df_des;
63 int MathedInset::df_width;
66 inline bool IsMacro(short token, int id)
68 return (token != LM_TK_FRAC && token != LM_TK_SQRT &&
69 !((token == LM_TK_SYM || token == LM_TC_BSYM) && id < 255));
74 void mathedValidate(LaTeXFeatures & features, MathParInset * par);
77 LyXFont WhichFont(short type, int size)
107 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
117 f.setSize(lfont_size);
121 if (type == LM_TC_BSYM) {
131 case LM_ST_SCRIPTSCRIPT:
136 lyxerr << "Mathed Error: wrong font size: " << size << endl;
140 if (type != LM_TC_TEXTRM)
141 f.setColor(LColor::math);
146 void mathed_init_fonts() //removed 'static' because DEC cxx does not
148 // Probably because this func is declared as a friend in math_defs.h
152 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
154 for (int i = 0 ; i < 8 ; ++i){
155 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
157 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
159 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
161 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
162 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
164 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
166 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
167 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
169 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
171 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
173 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
175 LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
176 MathedInset::df_asc = f.maxAscent();
177 MathedInset::df_des = f.maxDescent();
178 MathedInset::df_width = f.width('I');
182 LyXFont mathed_get_font(short type, int size)
184 LyXFont f = WhichFont(type, size);
185 if (type == LM_TC_TEX) {
186 f.setLatex(LyXFont::ON);
192 int mathed_string_width(short type, int size, byte const * s, int ls)
194 LyXFont f = WhichFont(type, size);
197 if (MathIsBinary(type)) {
199 for (int i = 0; i < ls && i < 75; ++i) {
208 return f.textWidth(reinterpret_cast<char const *>(s), ls);
212 int mathed_char_width(short type, int size, byte c)
214 int t = (MathIsBinary(type)) ? mathed_string_width(type, size, &c, 1):
215 WhichFont(type, size).width(c);
220 int mathed_string_height(short type, int size, byte const * s,
221 int ls, int & asc, int & des)
223 LyXFont font = WhichFont(type, size);
225 for (int i = 0; i < ls; ++i) {
226 if (font.descent(s[i]) > des)
227 des = font.descent(s[i]);
228 if (font.ascent(s[i]) > asc)
229 asc = font.ascent(s[i]);
235 int mathed_char_height(short type, int size, byte c, int & asc, int & des)
237 LyXFont font = WhichFont(type, size);
239 des = font.descent(c);
240 asc = font.ascent(c);
245 // In a near future maybe we use a better fonts renderer
246 void MathedInset::drawStr(Painter & pain, short type, int size,
247 int x, int y, byte * s, int ls)
250 if (MathIsBinary(type)) {
251 for (int i = 0; i < ls; ++i) {
252 st += string(" ") + char(s[i]) + ' ';
255 st = string(reinterpret_cast<char*>(s), ls);
257 LyXFont mf = mathed_get_font(type, size);
258 pain.text(x, y, st, mf);
262 InsetFormula::InsetFormula(bool display)
264 par = new MathParInset; // this leaks
269 par->SetType(LM_OT_PAR);
270 par->SetStyle(LM_ST_DISPLAY);
275 InsetFormula::InsetFormula(MathParInset * p)
277 par = (p->GetType()>= LM_OT_MPAR) ?
278 new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
282 disp_flag = (par->GetType()>0);
287 InsetFormula::~InsetFormula()
293 Inset * InsetFormula::Clone() const
295 InsetFormula * f = new InsetFormula(par);
301 void InsetFormula::Write(ostream & os) const
308 int InsetFormula::Latex(ostream & os, signed char fragile) const
311 //#warning Alejandro, the number of lines is not returned in this case
312 // This problem will disapear at 0.13.
314 InsetFormula::Latex(output, fragile);
320 int InsetFormula::Latex(string & file, signed char fragile) const
323 //#warning Alejandro, the number of lines is not returned in this case
324 // This problem will disapear at 0.13.
328 mathed_write(par, file, &ret, fragile, label.c_str());
333 int InsetFormula::Linuxdoc(string &/*file*/) const
339 int InsetFormula::DocBook(string &/*file*/) const
345 // Check if uses AMS macros
346 void InsetFormula::Validate(LaTeXFeatures & features) const
348 // Validation only necesary if not using an AMS Style
349 if (!features.amsstyle)
350 mathedValidate(features, par);
354 void InsetFormula::Read(LyXLex & lex)
356 istream & is = lex.getStream();
358 mathed_parser_file(is, lex.GetLineNo());
360 // Silly hack to read labels.
362 mathed_parse(0, 0, &par);
364 disp_flag = (par->GetType() > 0);
366 // Update line number
367 lex.setLineNo(mathed_parser_lineno());
370 label = mathed_label;
380 int InsetFormula::ascent(Painter &, LyXFont const &) const
382 return par->Ascent() + ((disp_flag) ? 8 : 1);
386 int InsetFormula::descent(Painter &, LyXFont const &) const
388 return par->Descent() + ((disp_flag) ? 8 : 1);
392 int InsetFormula::width(Painter &, LyXFont const & f) const
394 lfont_size = f.size();
396 return par->Width(); //+2;
400 void InsetFormula::draw(Painter & pain, LyXFont const &,
401 int baseline, float & x) const
403 LyXFont font = mathed_get_font(LM_TC_TEXTRM, LM_ST_TEXT);
405 lfont_size = font.size();
406 /// Let's try to wait a bit with this... (Lgb)
407 //UpdatableInset::draw(pain, font, baseline, x);
409 // otherwise a segfault could occur
410 // in some XDrawRectangles (i.e. matrix) (Matthias)
411 if (mathcursor && mathcursor->GetPar() == par) {
412 if (mathcursor->Selection()) {
416 mathcursor->SelGetArea(&xp, &yp, n);
417 pain.fillPolygon(xp, yp, n, LColor::selection);
419 mathcursor->draw(pain, int(x), baseline);
421 par->draw(pain, int(x), baseline);
423 x += float(width(pain, font));
425 if (par->GetType() == LM_OT_PARN || par->GetType() == LM_OT_MPARN) {
426 LyXFont font = WhichFont(LM_TC_BF, par->size);
427 font.setLatex(LyXFont::OFF);
429 if (par->GetType() == LM_OT_PARN) {
432 str = string("(") + label + ")";
435 pain.text(int(x + 20), baseline, str, font);
436 } else if (par->GetType() == LM_OT_MPARN) {
437 MathMatrixInset * mt =
438 static_cast<MathMatrixInset*>(par);
440 MathedRowSt const * crow = mt->getRowSt();
442 y = baseline + crow->getBaseline();
443 if (crow->isNumbered()) {
445 if (crow->getLabel())
446 str = string("(") + crow->getLabel() + ")";
449 pain.text(int(x + 20), y, str, font);
451 crow = crow->getNext();
455 cursor_visible = false;
459 void InsetFormula::Edit(int x, int y)
461 mathcursor = new MathedCursor(par);
462 current_view->lockInset(this);
464 UpdateInset(current_view, this, false);
467 mathcursor->SetPos(x, y);
473 void InsetFormula::InsetUnlock()
476 if (mathcursor->InMacroMode()) {
477 mathcursor->MacroModeClose();
483 UpdateInset(current_view, this, false);
487 // Now a symbol can be inserted only if the inset is locked
488 void InsetFormula::InsertSymbol(char const * s)
490 if (!s || !mathcursor) return;
491 mathcursor->Interpret(s);
496 void InsetFormula::GetCursorPos(int& x, int& y) const
498 mathcursor->GetPos(x, y);
503 void InsetFormula::ToggleInsetCursor()
509 mathcursor->GetPos(x, y);
512 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
513 int asc = font.maxAscent();
514 int desc = font.maxDescent();
517 current_view->hideLockedInsetCursor();
519 current_view->showLockedInsetCursor(x, y, asc, desc);
520 cursor_visible = !cursor_visible;
524 void InsetFormula::ShowInsetCursor()
526 if (!cursor_visible) {
529 mathcursor->GetPos(x, y);
532 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
533 asc = font.maxAscent();
534 desc = font.maxDescent();
535 current_view->fitLockedInsetCursor(x, y, asc, desc);
542 void InsetFormula::HideInsetCursor()
549 void InsetFormula::ToggleInsetSelection()
557 //mathcursor->SelGetArea(n);
558 // XFillPolygon(fl_display, pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin);
562 UpdateInset(current_view, this, false);
567 void InsetFormula::display(bool dspf)
569 if (dspf != disp_flag) {
571 par->SetType(LM_OT_PAR);
572 par->SetStyle(LM_ST_DISPLAY);
574 if (par->GetType() >= LM_OT_MPAR) {
575 MathParInset * p = new MathParInset(par);
579 mathcursor->SetPar(par);
581 par->SetType(LM_OT_MIN);
582 par->SetStyle(LM_ST_TEXT);
583 if (!label.empty() && par->GetType() != LM_OT_MPARN) {
592 int InsetFormula::GetNumberOfLabels() const
594 // This is dirty, I know. I'll clean it at 0.13
595 if (par->GetType() == LM_OT_MPARN) {
596 MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
598 MathedRowSt const * crow = mt->getRowSt();
600 if (crow->getLabel()) ++nl;
601 crow = crow->getNext();
612 string InsetFormula::getLabel(int il) const
614 //#warning This is dirty, I know. Ill clean it at 0.11
615 // Correction, the only way to clean this is with a new kernel: 0.13.
616 if (par->GetType() == LM_OT_MPARN) {
618 MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
620 MathedRowSt const * crow = mt->getRowSt();
622 if (crow->getLabel()) {
624 lab = crow->getLabel();
629 crow = crow->getNext();
637 void InsetFormula::UpdateLocal()
639 par->Metrics(); // To inform lyx kernel the exact size
640 // (there were problems with arrays).
641 UpdateInset(current_view, this);
645 void InsetFormula::InsetButtonRelease(int x, int y, int /*button*/)
650 mathcursor->SetPos(x, y);
655 UpdateInset(current_view, this, false);
660 void InsetFormula::InsetButtonPress(int x, int y, int /*button*/)
663 sel_x = x; sel_y = y;
664 if (mathcursor->Selection()) {
665 mathcursor->SelClear();
666 UpdateInset(current_view, this, false);
671 void InsetFormula::InsetMotionNotify(int x, int y, int /*button*/)
673 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
676 mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo);
677 mathcursor->SelStart();
679 mathcursor->GetPos(sel_x, sel_y);
685 mathcursor->SetPos(x, y);
687 mathcursor->GetPos(x, y);
688 if (sel_x!= x || sel_y!= y)
689 UpdateInset(current_view, this, false);
690 sel_x = x; sel_y = y;
695 void InsetFormula::InsetKeyPress(XKeyEvent *)
697 lyxerr[Debug::MATHED] << "Used InsetFormula::InsetKeyPress." << endl;
701 // Special Mathed functions
702 bool InsetFormula::SetNumber(bool numbf)
705 short type = par->GetType();
706 bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
707 if (numbf && !oldf) ++type;
708 if (!numbf && oldf) --type;
716 bool InsetFormula::LocalDispatch(int action, char const * arg)
718 // extern char *dispatch_result;
719 MathedTextCodes varcode = LM_TC_MIN;
720 bool was_macro = mathcursor->InMacroMode();
722 bool space_on = false;
723 bool was_selection = mathcursor->Selection();
725 static MathSpaceInset * sp= 0;
729 if (mathcursor->getLastCode() == LM_TC_TEX) {
734 // --- Cursor Movements ---------------------------------------------
735 case LFUN_RIGHTSEL: sel = true;
738 result = mathcursor->Right(sel);
741 case LFUN_LEFTSEL: sel = true;
744 result = mathcursor->Left(sel);
747 case LFUN_UPSEL: sel = true;
749 result = mathcursor->Up(sel);
752 case LFUN_DOWNSEL: sel = true;
754 result = mathcursor->Down(sel);
762 case LFUN_DELETE_LINE_FORWARD:
763 //current_view->lockedInsetStoreUndo(Undo::INSERT);
764 current_view->lockedInsetStoreUndo(Undo::DELETE);
765 mathcursor->DelLine();
769 current_view->lockedInsetStoreUndo(Undo::INSERT);
770 mathcursor->Insert(' ', LM_TC_CR);
771 par = mathcursor->GetPar();
775 current_view->lockedInsetStoreUndo(Undo::INSERT);
776 mathcursor->Insert(0, LM_TC_TAB);
780 current_view->lockedInsetStoreUndo(Undo::INSERT);
781 mathcursor->Insert('T', LM_TC_TAB);
785 if (!mathcursor->Left())
788 if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
789 UpdateInset(current_view, this);
794 //current_view->lockedInsetStoreUndo(Undo::INSERT);
795 current_view->lockedInsetStoreUndo(Undo::DELETE);
796 mathcursor->Delete();
797 UpdateInset(current_view, this);
800 // sprintf(dispatch_buffer, "%d %d",);
801 // dispatch_result = dispatch_buffer;
806 sscanf(arg, "%d %d", &x, &y);
808 mathcursor->SetPos(x1+x, y1+y);
812 /* cursor selection ---------------------------- */
816 mathcursor->MacroModeClose();
817 current_view->lockedInsetStoreUndo(Undo::INSERT);
818 mathcursor->SelPaste(); UpdateLocal(); break;
820 current_view->lockedInsetStoreUndo(Undo::DELETE);
821 mathcursor->SelCut(); UpdateLocal(); break;
822 case LFUN_COPY: mathcursor->SelCopy(); break;
825 case LFUN_WORDRIGHTSEL:
826 case LFUN_WORDLEFTSEL:
829 // --- accented characters ------------------------------
831 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
832 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
833 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
834 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
835 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
836 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
837 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
838 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
839 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
840 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
845 if (!greek_kb_flag) {
847 current_view->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
854 case LFUN_GREEK_TOGGLE:
856 greek_kb_flag = (greek_kb_flag) ? 0 : 2;
858 current_view->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
860 current_view->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
865 case LFUN_BOLD: mathcursor->setLastCode(LM_TC_BF); break;
866 case LFUN_SANS: mathcursor->setLastCode( LM_TC_SF); break;
867 case LFUN_EMPH: mathcursor->setLastCode(LM_TC_CAL); break;
868 case LFUN_ROMAN: mathcursor->setLastCode(LM_TC_RM); break;
869 case LFUN_CODE: mathcursor->setLastCode(LM_TC_TT); break;
870 case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR ) ; break;
873 // varcode = LM_TC_TEX;
874 mathcursor->setLastCode(LM_TC_TEX);
875 current_view->owner()->getMiniBuffer()->Set(_("TeX mode"));
879 case LFUN_MATH_NUMBER:
881 current_view->lockedInsetStoreUndo(Undo::INSERT);
883 short type = par->GetType();
884 bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
887 if (!label.empty()) {
890 current_view->owner()->getMiniBuffer()->Set(_("No number"));
893 current_view->owner()->getMiniBuffer()->Set(_("Number"));
901 case LFUN_MATH_NONUMBER:
903 if (par->GetType() == LM_OT_MPARN) {
904 // MathMatrixInset *mt = (MathMatrixInset*)par;
906 // mt->SetNumbered(!mt->IsNumbered());
908 mathcursor->setNumbered();
914 case LFUN_MATH_LIMITS:
916 current_view->lockedInsetStoreUndo(Undo::INSERT);
917 if (mathcursor->Limits())
923 latexkeys * l = in_word_set (arg, strlen(arg));
924 int sz = (l) ? l->id: -1;
925 mathcursor->SetSize(sz);
930 case LFUN_INSERT_MATH:
932 current_view->lockedInsetStoreUndo(Undo::INSERT);
937 case LFUN_INSERT_MATRIX:
939 current_view->lockedInsetStoreUndo(Undo::INSERT);
941 char s[80], arg2[80];
942 // This is just so that too long args won't ooze out of s.
943 strncpy(arg2, arg, 80); arg2[79]= '\0';
944 k = sscanf(arg2, "%d %d %s", &m, &n, s);
953 MathMatrixInset * p = new MathMatrixInset(m, n);
954 if (mathcursor && p) {
955 if (k > 2 && int(strlen(s)) > m)
956 p->SetAlign(s[0], &s[1]);
957 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
963 case LFUN_MATH_DELIM:
965 current_view->lockedInsetStoreUndo(Undo::INSERT);
966 char lf[40], rg[40], arg2[40];
967 int ilf = '(', irg = '.';
969 string vdelim("(){}[]./|");
972 strncpy(arg2, arg, 40); arg2[39]= '\0';
973 int n = sscanf(arg2, "%s %s", lf, rg);
974 lf[39] = '\0'; rg[39] = '\0';
981 l = in_word_set(lf, strlen(lf));
982 // Long words will cause l == 0; so check.
985 if (vdelim.find(lf[0]) != string::npos)
993 l = in_word_set(rg, strlen(rg));
996 if (vdelim.find(rg[0]) != string::npos)
1001 MathDelimInset * p = new MathDelimInset(ilf, irg);
1002 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
1007 case LFUN_PROTECTEDSPACE:
1009 current_view->lockedInsetStoreUndo(Undo::INSERT);
1010 sp = new MathSpaceInset(1);
1011 mathcursor->Insert(sp);
1017 case LFUN_INSERT_LABEL:
1019 current_view->lockedInsetStoreUndo(Undo::INSERT);
1020 if (par->GetType() < LM_OT_PAR) break;
1024 result = askForText(_("Enter new label to insert:"));
1029 if (!lb.empty() && lb[0] > ' ') {
1031 if (par->GetType() == LM_OT_MPARN) {
1032 mathcursor->setLabel(lb.c_str());
1033 // MathMatrixInset *mt = (MathMatrixInset*)par;
1034 // mt->SetLabel(lb);
1036 //if (label.notEmpty()) delete label;
1045 case LFUN_MATH_DISPLAY:
1046 //current_view->lockedInsetStoreUndo(Undo::INSERT);
1047 current_view->lockedInsetStoreUndo(Undo::EDIT);
1048 display(!disp_flag);
1052 // Invalid actions under math mode
1053 case LFUN_MATH_MODE:
1055 if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
1056 current_view->owner()->getMiniBuffer()->Set(_("math text mode"));
1057 varcode = LM_TC_TEXTRM;
1059 varcode = LM_TC_VAR;
1061 mathcursor->setLastCode(varcode);
1065 current_view->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
1068 //------- dummy actions
1069 case LFUN_EXEC_COMMAND:
1070 current_view->owner()->getMiniBuffer()->ExecCommand();
1074 if ((action == -1 || action == LFUN_SELFINSERT) && arg) {
1075 unsigned char c = arg[0];
1076 current_view->lockedInsetStoreUndo(Undo::INSERT);
1078 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
1080 mathcursor->setAccent(0);
1082 if (c == 0) { // Dead key, do nothing
1083 //lyxerr << "deadkey" << endl;
1087 if (mathcursor->getLastCode() == LM_TC_TEX) {
1088 mathcursor->MacroModeOpen();
1089 mathcursor->clearLastCode();
1090 varcode = LM_TC_MIN;
1093 short f = (mathcursor->getLastCode()) ?
1094 mathcursor->getLastCode() :
1095 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1096 varcode = MathIsAlphaFont(f) ?
1097 static_cast<MathedTextCodes>(f) :
1101 // lyxerr << "Varcode << vardoce;
1102 mathcursor->Insert(c, (greek_kb_flag) ? LM_TC_SYMB: varcode);
1103 varcode = LM_TC_MIN;
1104 if (greek_kb_flag<2) greek_kb_flag = 0;
1106 if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
1107 mathcursor->Insert(c, LM_TC_TEX);
1109 mathcursor->Insert('}', LM_TC_TEX);
1112 mathcursor->clearLastCode();
1113 // varcode = LM_TC_MIN;
1115 if (c == '_' && varcode == LM_TC_TEX) {
1116 mathcursor->Insert(c, LM_TC_SPECIAL);
1117 mathcursor->clearLastCode();
1118 // varcode = LM_TC_MIN;
1120 if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
1121 mathcursor->MacroModeOpen();
1122 mathcursor->clearLastCode();
1123 mathcursor->Insert(c, LM_TC_MIN);
1126 if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c))
1127 mathcursor->Insert(c, LM_TC_CONST);
1129 if (strchr("+/-*<>=", c))
1130 mathcursor->Insert(c, LM_TC_BOP);
1132 if (strchr(latex_special_chars, c) && c!= '_')
1133 mathcursor->Insert(c, LM_TC_SPECIAL);
1135 if (c == '_' || c == '^') {
1139 mathcursor->Interpret (s);
1143 short f = (mathcursor->getLastCode()) ?
1144 mathcursor->getLastCode() :
1145 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1146 varcode = MathIsAlphaFont(f) ?
1147 static_cast<MathedTextCodes>(f) :
1150 if (varcode == LM_TC_TEXTRM) {
1151 mathcursor->Insert(c, LM_TC_TEXTRM);
1154 mathcursor->MacroModeClose();
1157 int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
1161 if (!mathcursor->Pop() && mathcursor->IsEnd())
1166 mathcursor->Insert (c, LM_TC_VAR);
1170 mathcursor->MacroModeClose();
1171 current_view->owner()->getMiniBuffer()->Set(_("TeX mode"));
1172 mathcursor->setLastCode(LM_TC_TEX);
1176 // lyxerr << "Closed by action " << action << endl;
1180 if (was_macro != mathcursor->InMacroMode()
1182 && action != LFUN_BACKSPACE)
1184 if (sp && !space_on) sp = 0;
1185 if (mathcursor->Selection() || was_selection)
1186 ToggleInsetSelection();
1191 current_view->unlockInset(this);
1198 MathFuncInset::draw(Painter & pain, int x, int y)
1200 if (name && name[0] > ' ') {
1201 LyXFont font = WhichFont(LM_TC_TEXTRM, size);
1202 font.setLatex(LyXFont::ON);
1203 x += (font.textWidth("I", 1) + 3) / 4;
1204 pain.text(x, y, name, font);
1209 void MathFuncInset::Metrics()
1211 ln = (name) ? strlen(name): 0;
1212 LyXFont font = WhichFont(LM_TC_TEXTRM, size);
1213 font.setLatex(LyXFont::ON);
1214 width = font.textWidth(name, ln) + font.textWidth("I", 1)/2;
1215 mathed_string_height(LM_TC_TEXTRM, size,
1216 reinterpret_cast<unsigned char const *>(name),
1217 strlen(name), ascent, descent);
1222 void mathedValidate(LaTeXFeatures & features, MathParInset * par)
1224 MathedIter it(par->GetData());
1226 while (it.OK() && !(features.binom && features.boldsymbol)) {
1229 MathParInset * p = it.GetActiveInset();
1230 if (!features.binom && p->GetType() == LM_OT_MACRO &&
1231 strcmp(p->GetName(), "binom") == 0) {
1232 features.binom = true;
1234 for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
1235 p->setArgumentIdx(i);
1236 mathedValidate(features, p);
1240 MathedInset* p = it.GetInset();
1241 if (!features.boldsymbol && p->GetName() &&
1242 strcmp(p->GetName(), "boldsymbol") == 0) {
1243 features.boldsymbol = true;