3 * Purpose: Parser for mathed
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Parse LaTeX2e math mode code.
8 * Dependencies: Xlib, XForms
10 * Copyright: 1996, Alejandro Aguilar Sierra
14 * You are free to use and modify this code under the terms of
15 * the GNU General Public Licence version 2 or later.
20 If someone desperately needs partial "structures" (such as a few cells of
21 an array inset or similar) (s)he could uses the following hack as starting
22 point to write some macros:
27 \def\makeamptab{\catcode`\&=4\relax}
28 \def\makeampletter{\catcode`\&=11\relax}
29 \def\b{\makeampletter\expandafter\makeamptab\bi}
49 #pragma implementation
52 #include "math_parser.h"
53 #include "math_inset.h"
54 #include "math_arrayinset.h"
55 #include "math_braceinset.h"
56 #include "math_boxinset.h"
57 #include "math_charinset.h"
58 #include "math_deliminset.h"
59 #include "math_factory.h"
60 #include "math_funcinset.h"
61 #include "math_kerninset.h"
62 #include "math_macro.h"
63 #include "math_macrotable.h"
64 #include "math_macrotemplate.h"
65 #include "math_hullinset.h"
66 #include "math_rootinset.h"
67 #include "math_sizeinset.h"
68 #include "math_sqrtinset.h"
69 #include "math_scriptinset.h"
70 #include "math_specialcharinset.h"
71 #include "math_sqrtinset.h"
72 #include "math_support.h"
73 #include "math_xyarrowinset.h"
77 #include "support/LAssert.h"
78 #include "support/lstrings.h"
96 bool stared(string const & s)
98 string::size_type const n = s.size();
99 return n && s[n - 1] == '*';
103 void add(MathArray & ar, char c, MathTextCodes code)
105 ar.push_back(MathAtom(new MathCharInset(c, code)));
109 // These are TeX's catcodes
111 catEscape, // 0 backslash
121 catSpace, // 10 space
122 catLetter, // 11 a-zA-Z
123 catOther, // 12 none of the above
126 catInvalid // 15 <delete>
129 CatCode theCatcode[256];
132 inline CatCode catcode(unsigned char c)
134 return theCatcode[c];
139 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing process
140 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
141 FLAG_END = 1 << 3, // next \\end ends the parsing process
142 FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process
143 FLAG_BOX = 1 << 5, // we are in a box
144 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
145 FLAG_BLOCK = 1 << 7, // next block ends the parsing process
146 FLAG_BLOCK2 = 1 << 8, // next block2 ends the parsing process
147 FLAG_LEAVE = 1 << 9 // leave the loop at the end
153 fill(theCatcode, theCatcode + 256, catOther);
154 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
155 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
157 theCatcode['\\'] = catEscape;
158 theCatcode['{'] = catBegin;
159 theCatcode['}'] = catEnd;
160 theCatcode['$'] = catMath;
161 theCatcode['&'] = catAlign;
162 theCatcode['\n'] = catNewline;
163 theCatcode['#'] = catParameter;
164 theCatcode['^'] = catSuper;
165 theCatcode['_'] = catSub;
166 theCatcode['
\7f'] = catIgnore;
167 theCatcode[' '] = catSpace;
168 theCatcode['\t'] = catSpace;
169 theCatcode['\r'] = catSpace;
170 theCatcode['~'] = catActive;
171 theCatcode['%'] = catComment;
177 // Helper class for parsing
183 Token() : cs_(), char_(0), cat_(catIgnore) {}
185 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
187 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
190 string const & cs() const { return cs_; }
192 CatCode cat() const { return cat_; }
194 char character() const { return char_; }
196 string asString() const;
209 bool Token::isCR() const
211 return cs_ == "\\" || cs_ == "cr" || cs_ == "crcr";
214 string Token::asString() const
216 return cs_.size() ? cs_ : string(1, char_);
219 // Angus' compiler says these are not needed
220 //bool operator==(Token const & s, Token const & t)
222 // return s.character() == t.character()
223 // && s.cat() == t.cat() && s.cs() == t.cs();
226 //bool operator!=(Token const & s, Token const & t)
231 ostream & operator<<(ostream & os, Token const & t)
234 os << "\\" << t.cs();
236 os << "[" << t.character() << "," << t.cat() << "]";
245 Parser(LyXLex & lex);
247 Parser(istream & is);
250 bool parse_macro(string & name);
252 bool parse_normal(MathAtom &);
254 void parse_into(MathArray & array, unsigned flags, MathTextCodes = LM_TC_MIN);
256 int lineno() const { return lineno_; }
262 void parse_into1(MathArray & array, unsigned flags, MathTextCodes);
264 string getArg(char lf, char rf);
268 void error(string const & msg);
270 bool parse_lines(MathAtom & t, bool numbered, bool outmost);
271 /// parses {... & ... \\ ... & ... }
272 bool parse_lines2(MathAtom & t, bool braced);
273 /// dump contents to screen
278 void tokenize(istream & is);
280 void tokenize(string const & s);
282 void skipSpaceTokens(istream & is, char c);
284 void push_back(Token const & t);
288 Token const & prevToken() const;
290 Token const & nextToken() const;
292 Token const & getToken();
293 /// skips spaces if any
295 /// skips opening brace
297 /// skips closing brace
299 /// counts a sequence of hlines
302 void lex(string const & s);
309 std::vector<Token> tokens_;
321 Parser::Parser(LyXLex & lexer)
322 : lineno_(lexer.getLineNo()), pos_(0), curr_num_(false)
324 tokenize(lexer.getStream());
329 Parser::Parser(istream & is)
330 : lineno_(0), pos_(0), curr_num_(false)
336 void Parser::push_back(Token const & t)
338 tokens_.push_back(t);
342 void Parser::pop_back()
348 Token const & Parser::prevToken() const
350 static const Token dummy;
351 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
355 Token const & Parser::nextToken() const
357 static const Token dummy;
358 return good() ? tokens_[pos_] : dummy;
362 Token const & Parser::getToken()
364 static const Token dummy;
365 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
366 return good() ? tokens_[pos_++] : dummy;
370 void Parser::skipSpaces()
372 while (nextToken().cat() == catSpace)
377 void Parser::skipBegin()
379 if (nextToken().cat() == catBegin)
382 lyxerr << "'{' expected\n";
386 void Parser::skipEnd()
388 if (nextToken().cat() == catEnd)
391 lyxerr << "'}' expected\n";
395 int Parser::readHLines()
399 while (nextToken().cs() == "hline") {
408 void Parser::putback()
414 bool Parser::good() const
416 return pos_ < tokens_.size();
420 char Parser::getChar()
423 lyxerr << "The input stream is not well..." << endl;
424 return tokens_[pos_++].character();
428 string Parser::getArg(char lf, char rg)
438 while ((c = getChar()) != rg && good())
445 void Parser::tokenize(istream & is)
447 // eat everything up to the next \end_inset or end of stream
448 // and store it in s for further tokenization
453 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
454 s = s.substr(0, s.size() - 10);
464 void Parser::skipSpaceTokens(istream & is, char c)
466 // skip trailing spaces
467 while (catcode(c) == catSpace || catcode(c) == catNewline)
470 //lyxerr << "putting back: " << c << "\n";
475 void Parser::tokenize(string const & buffer)
477 static bool init_done = false;
484 istringstream is(buffer.c_str(), ios::in | ios::binary);
488 //lyxerr << "reading c: " << c << "\n";
490 switch (catcode(c)) {
494 if (catcode(c) == catNewline)
495 ; //push_back(Token("par"));
497 push_back(Token(' ', catSpace));
504 while (is.get(c) && catcode(c) != catNewline)
513 error("unexpected end of input");
516 if (catcode(c) == catLetter) {
518 while (is.get(c) && catcode(c) == catLetter)
520 skipSpaceTokens(is, c);
529 push_back(Token(c, catcode(c)));
531 skipSpaceTokens(is, c);
536 lyxerr << "ignoring a char: " << int(c) << "\n";
541 push_back(Token(c, catcode(c)));
551 void Parser::dump() const
553 lyxerr << "\nTokens: ";
554 for (unsigned i = 0; i < tokens_.size(); ++i)
555 lyxerr << tokens_[i];
560 void Parser::error(string const & msg)
562 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
569 bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
571 MathGridInset * p = t->asGridInset();
574 lyxerr << "error in Parser::parse_lines() 1\n";
578 // save global variables
579 bool const saved_num = curr_num_;
580 string const saved_label = curr_label_;
582 // read initial hlines
583 p->rowinfo(0).lines_ = readHLines();
585 for (int row = 0; true; ++row) {
586 // reset global variables
587 curr_num_ = numbered;
591 for (MathInset::col_type col = 0; true; ++col) {
592 //lyxerr << "reading cell " << row << " " << col << " "
593 // << p->ncols() << "\n";
594 //lyxerr << "ncols: " << p->ncols() << "\n";
596 if (col >= p->ncols()) {
597 //lyxerr << "adding col " << col << "\n";
598 p->addCol(p->ncols());
601 MathArray & ar = p->cell(col + row * p->ncols());
602 parse_into(ar, FLAG_BLOCK);
603 // remove 'unnecessary' braces:
604 if (ar.size() == 1 && ar.back()->asBraceInset())
605 ar = ar.back()->asBraceInset()->cell(0);
606 //lyxerr << "ar: " << ar << "\n";
608 // break if cell is not followed by an ampersand
609 if (nextToken().cat() != catAlign) {
610 //lyxerr << "less cells read than normal in row/col: "
611 // << row << " " << col << "\n";
615 // skip the ampersand
620 MathHullInset * m = t->asHullInset();
622 lyxerr << "error in Parser::parse_lines() 2\n";
625 m->numbered(row, curr_num_);
626 m->label(row, curr_label_);
627 if (curr_skip_.size()) {
628 m->vcrskip(LyXLength(curr_skip_), row);
634 if (nextToken().isCR()) {
638 // try to read a length
641 // read hlines for next row
642 p->rowinfo(row + 1).lines_ = readHLines();
645 // we are finished if the next token is an 'end'
646 if (nextToken().cs() == "end") {
647 // skip the end-token
651 // leave the 'read a line'-loop
655 // otherwise, we have to start a new row
659 // restore "global" variables
660 curr_num_ = saved_num;
661 curr_label_ = saved_label;
667 bool Parser::parse_lines2(MathAtom & t, bool braced)
669 MathGridInset * p = t->asGridInset();
671 lyxerr << "error in Parser::parse_lines() 1\n";
675 for (int row = 0; true; ++row) {
677 for (MathInset::col_type col = 0; true; ++col) {
678 //lyxerr << "reading cell " << row << " " << col << " " << p->ncols() << "\n";
680 if (col >= p->ncols()) {
681 //lyxerr << "adding col " << col << "\n";
682 p->addCol(p->ncols());
685 parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK2);
686 //lyxerr << "read cell: " << p->cell(col + row * p->ncols()) << "\n";
688 // break if cell is not followed by an ampersand
689 if (nextToken().cat() != catAlign) {
690 //lyxerr << "less cells read than normal in row/col: " << row << " " << col << "\n";
694 // skip the ampersand
699 if (nextToken().isCR()) {
704 // we are finished if the next token is the one we expected
705 // skip the end-token
706 // leave the 'read a line'-loop
708 if (nextToken().cat() == catEnd) {
713 if (nextToken().cs() == "end") {
720 // otherwise, we have to start a new row
729 bool Parser::parse_macro(string & name)
734 if (getToken().cs() != "newcommand") {
735 lyxerr << "\\newcommand expected\n";
739 if (getToken().cat() != catBegin) {
740 lyxerr << "'{' in \\newcommand expected (1)\n";
744 name = getToken().cs();
746 if (getToken().cat() != catEnd) {
747 lyxerr << "'}' expected\n";
751 string arg = getArg('[', ']');
752 int narg = arg.empty() ? 0 : atoi(arg.c_str());
754 if (getToken().cat() != catBegin) {
755 lyxerr << "'{' in \\newcommand expected (2)\n";
760 parse_into(ar, FLAG_BRACE_LAST);
762 // we cannot handle recursive stuff at all
764 test.push_back(createMathInset(name));
765 if (ar.contains(test)) {
766 lyxerr << "we cannot handle recursive macros at all.\n";
770 MathMacroTable::create(name, narg, ar);
775 bool Parser::parse_normal(MathAtom & matrix)
778 Token const & t = getToken();
781 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
782 parse_into(matrix->cell(0), 0);
786 if (t.cat() == catMath) {
787 Token const & n = getToken();
788 if (n.cat() == catMath) {
789 // TeX's $$...$$ syntax for displayed math
790 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
791 MathHullInset * p = matrix->asHullInset();
792 parse_into(p->cell(0), 0);
793 p->numbered(0, curr_num_);
794 p->label(0, curr_label_);
796 // simple $...$ stuff
798 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
799 parse_into(matrix->cell(0), 0);
804 if (!t.cs().size()) {
805 lyxerr << "start of math expected, got '" << t << "'\n";
809 string const & cs = t.cs();
814 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
815 MathHullInset * p = matrix->asHullInset();
816 parse_into(p->cell(0), 0);
817 p->numbered(0, curr_num_);
818 p->label(0, curr_label_);
823 lyxerr << "'begin' of un-simple math expected, got '" << cs << "'\n";
827 string const name = getArg('{', '}');
829 if (name == "math") {
830 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
831 parse_into(matrix->cell(0), 0);
835 if (name == "equation" || name == "equation*" || name == "displaymath") {
836 curr_num_ = (name == "equation");
838 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
839 MathHullInset * p = matrix->asHullInset();
840 parse_into(p->cell(0), FLAG_END);
841 p->numbered(0, curr_num_);
842 p->label(0, curr_label_);
846 if (name == "eqnarray" || name == "eqnarray*") {
847 matrix = MathAtom(new MathHullInset(LM_OT_EQNARRAY));
848 return parse_lines(matrix, !stared(name), true);
851 if (name == "align" || name == "align*") {
852 matrix = MathAtom(new MathHullInset(LM_OT_ALIGN));
853 return parse_lines(matrix, !stared(name), true);
856 if (name == "alignat" || name == "alignat*") {
857 int nc = 2 * atoi(getArg('{', '}').c_str());
858 matrix = MathAtom(new MathHullInset(LM_OT_ALIGNAT, nc));
859 return parse_lines(matrix, !stared(name), true);
862 if (name == "xalignat" || name == "xalignat*") {
863 int nc = 2 * atoi(getArg('{', '}').c_str());
864 matrix = MathAtom(new MathHullInset(LM_OT_XALIGNAT, nc));
865 return parse_lines(matrix, !stared(name), true);
868 if (name == "xxalignat") {
869 int nc = 2 * atoi(getArg('{', '}').c_str());
870 matrix = MathAtom(new MathHullInset(LM_OT_XXALIGNAT, nc));
871 return parse_lines(matrix, !stared(name), true);
874 if (name == "multline" || name == "multline*") {
875 matrix = MathAtom(new MathHullInset(LM_OT_MULTLINE));
876 return parse_lines(matrix, !stared(name), true);
879 if (name == "gather" || name == "gather*") {
880 matrix = MathAtom(new MathHullInset(LM_OT_GATHER));
881 return parse_lines(matrix, !stared(name), true);
884 lyxerr[Debug::MATHED] << "1: unknown math environment: " << name << "\n";
885 lyxerr << "1: unknown math environment: " << name << "\n";
890 void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
892 parse_into1(array, flags, code);
893 // remove 'unnecessary' braces:
894 if (array.size() == 1 && array.back()->asBraceInset()) {
895 lyxerr << "extra braces removed\n";
896 array = array.back()->asBraceInset()->cell(0);
901 void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
907 Token const & t = getToken();
910 lyxerr << "t: " << t << " flags: " << flags << "\n";
915 if (flags & FLAG_ITEM) {
917 if (t.cat() == catBegin) {
918 // skip the brace and collect everything to the next matching
920 flags |= FLAG_BRACE_LAST;
923 // handle only this single token, leave the loop if done
928 if (flags & FLAG_BLOCK) {
929 if (t.cat() == catAlign || t.isCR() || t.cs() == "end") {
935 if (flags & FLAG_BLOCK2) {
936 if (t.cat() == catAlign || t.isCR() || t.cs() == "end"
937 || t.cat() == catEnd) {
946 if (t.cat() == catMath) {
947 if (flags & FLAG_BOX) {
948 // we are inside an mbox, so opening new math is allowed
949 array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
950 parse_into(array.back()->cell(0), 0);
952 // otherwise this is the end of the formula
957 else if (t.cat() == catLetter)
958 add(array, t.character(), code);
960 else if (t.cat() == catSpace && code == LM_TC_TEXTRM)
961 add(array, t.character(), code);
963 else if (t.cat() == catParameter) {
964 Token const & n = getToken();
965 array.push_back(MathAtom(new MathMacroArgument(n.character()-'0', code)));
968 else if (t.cat() == catBegin) {
970 parse_into(ar, FLAG_BRACE_LAST);
971 #ifndef WITH_WARNINGS
972 #warning this might be wrong in general!
974 // ignore braces around simple items
975 if ((ar.size() == 1 && !ar.front()->needsBraces()
976 || (ar.size() == 2 && !ar.front()->needsBraces()
977 && ar.back()->asScriptInset()))
978 || (ar.size() == 0 && array.size() == 0))
982 array.push_back(MathAtom(new MathBraceInset));
983 array.back()->cell(0).swap(ar);
987 else if (t.cat() == catEnd) {
988 if (flags & FLAG_BRACE_LAST)
990 lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
991 //lyxerr << "found '}' unexpectedly\n";
993 add(array, '}', LM_TC_TEX);
996 else if (t.cat() == catAlign) {
997 lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
998 //lyxerr << "found tab unexpectedly\n";
999 add(array, '&', LM_TC_TEX);
1002 else if (t.cat() == catSuper || t.cat() == catSub) {
1003 bool up = (t.cat() == catSuper);
1004 MathScriptInset * p = 0;
1006 p = array.back()->asScriptInset();
1007 if (!p || p->has(up)) {
1008 array.push_back(MathAtom(new MathScriptInset(up)));
1009 p = array.back()->asScriptInset();
1012 parse_into(p->cell(up), FLAG_ITEM);
1017 else if (t.character() == ']' && (flags & FLAG_BRACK_END))
1020 else if (t.cat() == catOther)
1021 add(array, t.character(), code);
1024 // control sequences
1026 else if (t.cs() == "protect")
1027 // ignore \\protect, will be re-added during output
1030 else if (t.cs() == "end")
1033 else if (t.cs() == ")")
1036 else if (t.cs() == "]")
1039 else if (t.cs() == "\\") {
1040 curr_skip_ = getArg('[', ']');
1041 //lyxerr << "found newline unexpectedly, array: '" << array << "'\n";
1042 lyxerr << "found newline unexpectedly\n";
1043 array.push_back(createMathInset("\\"));
1046 else if (t.cs() == "limits")
1049 else if (t.cs() == "nolimits")
1052 else if (t.cs() == "nonumber")
1055 else if (t.cs() == "number")
1058 else if (t.cs() == "sqrt") {
1061 array.push_back(MathAtom(new MathRootInset));
1062 parse_into(array.back()->cell(0), FLAG_BRACK_END);
1063 parse_into(array.back()->cell(1), FLAG_ITEM);
1066 array.push_back(MathAtom(new MathSqrtInset));
1067 parse_into(array.back()->cell(0), FLAG_ITEM);
1071 else if (t.cs() == "left") {
1072 string l = getToken().asString();
1074 parse_into(ar, FLAG_RIGHT);
1075 string r = getToken().asString();
1076 MathAtom dl(new MathDelimInset(l, r));
1078 array.push_back(dl);
1081 else if (t.cs() == "right") {
1082 if (!(flags & FLAG_RIGHT)) {
1083 //lyxerr << "got so far: '" << array << "'\n";
1084 error("Unmatched right delimiter");
1089 else if (t.cs() == "begin") {
1090 string const name = getArg('{', '}');
1091 if (name == "array" || name == "subarray") {
1092 string const valign = getArg('[', ']') + 'c';
1093 string const halign = getArg('{', '}');
1094 array.push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
1095 parse_lines(array.back(), false, false);
1096 } else if (name == "split" || name == "cases" ||
1097 name == "gathered" || name == "aligned") {
1098 array.push_back(createMathInset(name));
1099 parse_lines(array.back(), false, false);
1100 } else if (name == "matrix" || name == "pmatrix" || name == "bmatrix" ||
1101 name == "vmatrix" || name == "Vmatrix") {
1102 array.push_back(createMathInset(name));
1103 parse_lines2(array.back(), false);
1105 lyxerr << "unknow math inset begin '" << name << "'\n";
1108 else if (t.cs() == "kern") {
1109 #ifdef WITH_WARNINGS
1114 Token const & t = getToken();
1120 if (isValidLength(s))
1123 array.push_back(MathAtom(new MathKernInset(s)));
1126 else if (t.cs() == "label") {
1127 curr_label_ = getArg('{', '}');
1130 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1131 MathAtom p = createMathInset(t.cs());
1132 array.swap(p->cell(0));
1133 parse_into(p->cell(1), flags, code);
1138 else if (t.cs() == "substack") {
1139 array.push_back(createMathInset(t.cs()));
1141 parse_lines2(array.back(), true);
1144 else if (t.cs() == "xymatrix") {
1145 array.push_back(createMathInset(t.cs()));
1147 parse_lines2(array.back(), true);
1152 else if (1 && t.cs() == "ar") {
1153 MathXYArrowInset * p = new MathXYArrowInset;
1155 // try to read target
1158 parse_into(p->cell(0), FLAG_BRACK_END);
1159 //lyxerr << "read target: " << p->cell(0) << "\n";
1164 // try to read label
1165 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1166 p->up_ = nextToken().cat() == catSuper;
1168 parse_into(p->cell(1), FLAG_ITEM);
1169 //lyxerr << "read label: " << p->cell(1) << "\n";
1172 array.push_back(MathAtom(p));
1173 //lyxerr << "read array: " << array << "\n";
1178 else if (t.cs() == "mbox" || t.cs() == "text") {
1179 //array.push_back(createMathInset(t.cs()));
1180 array.push_back(MathAtom(new MathBoxInset(t.cs())));
1181 // slurp in the argument of mbox
1183 MathBoxInset * p = array.back()->asBoxInset();
1189 else if (t.cs().size()) {
1190 latexkeys const * l = in_word_set(t.cs());
1192 if (l->token == LM_TK_FONT) {
1193 //lyxerr << "starting font\n";
1194 //CatCode catSpaceSave = theCatcode[' '];
1195 //if (l->id == LM_TC_TEXTRM) {
1196 // // temporarily change catcode
1197 // theCatcode[' '] = catLetter;
1201 parse_into(ar, FLAG_ITEM, static_cast<MathTextCodes>(l->id));
1202 array.push_back(ar);
1204 // undo catcode changes
1205 ////theCatcode[' '] = catSpaceSave;
1206 //lyxerr << "ending font\n";
1209 else if (l->token == LM_TK_OLDFONT) {
1210 code = static_cast<MathTextCodes>(l->id);
1213 else if (l->token == LM_TK_BOX) {
1214 MathAtom p = createMathInset(t.cs());
1215 parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
1219 else if (l->token == LM_TK_STY) {
1220 MathAtom p = createMathInset(t.cs());
1221 parse_into(p->cell(0), flags, code);
1227 MathAtom p = createMathInset(t.cs());
1228 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1229 parse_into(p->cell(i), FLAG_ITEM);
1235 MathAtom p = createMathInset(t.cs());
1236 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1237 parse_into(p->cell(i), FLAG_ITEM);
1243 if (flags & FLAG_LEAVE) {
1244 flags &= ~FLAG_LEAVE;
1250 lyxerr << " Math Panic, expect problems!\n";
1251 // Search for the end command.
1255 } while (good() && t.cs() != "end");
1261 } // anonymous namespace
1264 void mathed_parse_cell(MathArray & ar, string const & str)
1266 istringstream is(str.c_str());
1267 mathed_parse_cell(ar, is);
1271 void mathed_parse_cell(MathArray & ar, istream & is)
1273 Parser(is).parse_into(ar, 0);
1278 bool mathed_parse_macro(string & name, string const & str)
1280 istringstream is(str.c_str());
1282 return parser.parse_macro(name);
1285 bool mathed_parse_macro(string & name, istream & is)
1288 return parser.parse_macro(name);
1291 bool mathed_parse_macro(string & name, LyXLex & lex)
1294 return parser.parse_macro(name);
1299 bool mathed_parse_normal(MathAtom & t, string const & str)
1301 istringstream is(str.c_str());
1303 return parser.parse_normal(t);
1306 bool mathed_parse_normal(MathAtom & t, istream & is)
1309 return parser.parse_normal(t);
1312 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1315 return parser.parse_normal(t);