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_charinset.h"
57 #include "math_deliminset.h"
58 #include "math_factory.h"
59 #include "math_funcinset.h"
60 #include "math_kerninset.h"
61 #include "math_macro.h"
62 #include "math_macrotable.h"
63 #include "math_macrotemplate.h"
64 #include "math_hullinset.h"
65 #include "math_rootinset.h"
66 #include "math_sizeinset.h"
67 #include "math_sqrtinset.h"
68 #include "math_scriptinset.h"
69 #include "math_specialcharinset.h"
70 #include "math_sqrtinset.h"
71 #include "math_support.h"
72 #include "math_xyarrowinset.h"
77 #include "support/lstrings.h"
93 bool stared(string const & s)
95 string::size_type const n = s.size();
96 return n && s[n - 1] == '*';
100 void add(MathArray & ar, char c, MathTextCodes code)
102 ar.push_back(MathAtom(new MathCharInset(c, code)));
106 // These are TeX's catcodes
108 catEscape, // 0 backslash
118 catSpace, // 10 space
119 catLetter, // 11 a-zA-Z
120 catOther, // 12 none of the above
123 catInvalid // 15 <delete>
126 CatCode theCatcode[256];
129 inline CatCode catcode(unsigned char c)
131 return theCatcode[c];
136 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing process
137 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
138 FLAG_END = 1 << 3, // next \\end ends the parsing process
139 FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process
140 FLAG_BOX = 1 << 5, // we are in a box
141 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
142 FLAG_BLOCK = 1 << 7, // next block ends the parsing process
143 FLAG_BLOCK2 = 1 << 8, // next block2 ends the parsing process
144 FLAG_LEAVE = 1 << 9 // leave the loop at the end
150 fill(theCatcode, theCatcode + 256, catOther);
151 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
152 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
154 theCatcode['\\'] = catEscape;
155 theCatcode['{'] = catBegin;
156 theCatcode['}'] = catEnd;
157 theCatcode['$'] = catMath;
158 theCatcode['&'] = catAlign;
159 theCatcode['\n'] = catNewline;
160 theCatcode['#'] = catParameter;
161 theCatcode['^'] = catSuper;
162 theCatcode['_'] = catSub;
163 theCatcode['
\7f'] = catIgnore;
164 theCatcode[' '] = catSpace;
165 theCatcode['\t'] = catSpace;
166 theCatcode['\r'] = catSpace;
167 theCatcode['~'] = catActive;
168 theCatcode['%'] = catComment;
174 // Helper class for parsing
180 Token() : cs_(), char_(0), cat_(catIgnore) {}
182 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
184 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
187 string const & cs() const { return cs_; }
189 CatCode cat() const { return cat_; }
191 char character() const { return char_; }
193 string asString() const;
206 bool Token::isCR() const
208 return cs_ == "\\" || cs_ == "cr" || cs_ == "crcr";
211 string Token::asString() const
213 return cs_.size() ? cs_ : string(1, char_);
216 // Angus' compiler says these are not needed
217 //bool operator==(Token const & s, Token const & t)
219 // return s.character() == t.character()
220 // && s.cat() == t.cat() && s.cs() == t.cs();
223 //bool operator!=(Token const & s, Token const & t)
228 ostream & operator<<(ostream & os, Token const & t)
231 os << "\\" << t.cs();
233 os << "[" << t.character() << "," << t.cat() << "]";
242 Parser(LyXLex & lex);
244 Parser(istream & is);
247 bool parse_macro(string & name);
249 bool parse_normal(MathAtom &);
251 void parse_into(MathArray & array, unsigned flags, MathTextCodes = LM_TC_MIN);
253 int lineno() const { return lineno_; }
259 void parse_into1(MathArray & array, unsigned flags, MathTextCodes);
261 string getArg(char lf, char rf);
265 void error(string const & msg);
267 bool parse_lines(MathAtom & t, bool numbered, bool outmost);
268 /// parses {... & ... \\ ... & ... }
269 bool parse_lines2(MathAtom & t, bool braced);
270 /// dump contents to screen
275 void tokenize(istream & is);
277 void tokenize(string const & s);
279 void skipSpaceTokens(istream & is, char c);
281 void push_back(Token const & t);
285 Token const & prevToken() const;
287 Token const & nextToken() const;
289 Token const & getToken();
290 /// skips spaces if any
292 /// skips opening brace
294 /// skips closing brace
296 /// counts a sequence of hlines
299 void lex(string const & s);
306 std::vector<Token> tokens_;
318 Parser::Parser(LyXLex & lexer)
319 : lineno_(lexer.getLineNo()), pos_(0), curr_num_(false)
321 tokenize(lexer.getStream());
326 Parser::Parser(istream & is)
327 : lineno_(0), pos_(0), curr_num_(false)
333 void Parser::push_back(Token const & t)
335 tokens_.push_back(t);
339 void Parser::pop_back()
345 Token const & Parser::prevToken() const
347 static const Token dummy;
348 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
352 Token const & Parser::nextToken() const
354 static const Token dummy;
355 return good() ? tokens_[pos_] : dummy;
359 Token const & Parser::getToken()
361 static const Token dummy;
362 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
363 return good() ? tokens_[pos_++] : dummy;
367 void Parser::skipSpaces()
369 while (nextToken().cat() == catSpace)
374 void Parser::skipBegin()
376 if (nextToken().cat() == catBegin)
379 lyxerr << "'{' expected\n";
383 void Parser::skipEnd()
385 if (nextToken().cat() == catEnd)
388 lyxerr << "'}' expected\n";
392 int Parser::readHLines()
396 while (nextToken().cs() == "hline") {
405 void Parser::putback()
411 bool Parser::good() const
413 return pos_ < tokens_.size();
417 char Parser::getChar()
420 lyxerr << "The input stream is not well..." << endl;
421 return tokens_[pos_++].character();
425 string Parser::getArg(char lf, char rg)
435 while ((c = getChar()) != rg && good())
442 void Parser::tokenize(istream & is)
444 // eat everything up to the next \end_inset or end of stream
445 // and store it in s for further tokenization
450 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
451 s = s.substr(0, s.size() - 10);
461 void Parser::skipSpaceTokens(istream & is, char c)
463 // skip trailing spaces
464 while (catcode(c) == catSpace || catcode(c) == catNewline)
467 //lyxerr << "putting back: " << c << "\n";
472 void Parser::tokenize(string const & buffer)
474 static bool init_done = false;
481 istringstream is(buffer.c_str(), ios::in | ios::binary);
485 //lyxerr << "reading c: " << c << "\n";
487 switch (catcode(c)) {
491 if (catcode(c) == catNewline)
492 ; //push_back(Token("par"));
494 push_back(Token(' ', catSpace));
501 while (is.get(c) && catcode(c) != catNewline)
510 error("unexpected end of input");
513 if (catcode(c) == catLetter) {
515 while (is.get(c) && catcode(c) == catLetter)
517 skipSpaceTokens(is, c);
526 push_back(Token(c, catcode(c)));
528 skipSpaceTokens(is, c);
533 lyxerr << "ignoring a char: " << int(c) << "\n";
538 push_back(Token(c, catcode(c)));
546 void Parser::dump() const
548 lyxerr << "\nTokens: ";
549 for (unsigned i = 0; i < tokens_.size(); ++i)
550 lyxerr << tokens_[i];
555 void Parser::error(string const & msg)
557 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
564 bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
566 MathGridInset * p = t->asGridInset();
569 lyxerr << "error in Parser::parse_lines() 1\n";
573 // save global variables
574 bool const saved_num = curr_num_;
575 string const saved_label = curr_label_;
577 // read initial hlines
578 p->rowinfo(0).lines_ = readHLines();
580 for (int row = 0; true; ++row) {
581 // reset global variables
582 curr_num_ = numbered;
586 for (MathInset::col_type col = 0; col < p->ncols(); ++col) {
587 //lyxerr << "reading cell " << row << " " << col << "\n";
588 //lyxerr << "ncols: " << p->ncols() << "\n";
590 MathArray & ar = p->cell(col + row * p->ncols());
591 parse_into(ar, FLAG_BLOCK);
592 // remove 'unnecessary' braces:
593 if (ar.size() == 1 && ar.back()->asBraceInset())
594 ar = ar.back()->asBraceInset()->cell(0);
595 //lyxerr << "ar: " << ar << "\n";
597 // break if cell is not followed by an ampersand
598 if (nextToken().cat() != catAlign) {
599 //lyxerr << "less cells read than normal in row/col: "
600 // << row << " " << col << "\n";
604 // skip the ampersand
609 MathHullInset * m = t->asHullInset();
611 lyxerr << "error in Parser::parse_lines() 2\n";
614 m->numbered(row, curr_num_);
615 m->label(row, curr_label_);
616 if (curr_skip_.size()) {
617 m->vcrskip(LyXLength(curr_skip_), row);
623 if (nextToken().isCR()) {
627 // try to read a length
630 // read hlines for next row
631 p->rowinfo(row + 1).lines_ = readHLines();
634 // we are finished if the next token is an 'end'
635 if (nextToken().cs() == "end") {
636 // skip the end-token
640 // leave the 'read a line'-loop
644 // otherwise, we have to start a new row
648 // restore "global" variables
649 curr_num_ = saved_num;
650 curr_label_ = saved_label;
656 bool Parser::parse_lines2(MathAtom & t, bool braced)
658 MathGridInset * p = t->asGridInset();
660 lyxerr << "error in Parser::parse_lines() 1\n";
664 for (int row = 0; true; ++row) {
666 for (MathInset::col_type col = 0; true; ++col) {
667 //lyxerr << "reading cell " << row << " " << col << " " << p->ncols() << "\n";
669 if (col >= p->ncols()) {
670 //lyxerr << "adding col " << col << "\n";
671 p->addCol(p->ncols());
674 parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK2);
675 //lyxerr << "read cell: " << p->cell(col + row * p->ncols()) << "\n";
677 // break if cell is not followed by an ampersand
678 if (nextToken().cat() != catAlign) {
679 //lyxerr << "less cells read than normal in row/col: " << row << " " << col << "\n";
683 // skip the ampersand
688 if (nextToken().isCR()) {
693 // we are finished if the next token is the one we expected
694 // skip the end-token
695 // leave the 'read a line'-loop
697 if (nextToken().cat() == catEnd) {
702 if (nextToken().cs() == "end") {
709 // otherwise, we have to start a new row
718 bool Parser::parse_macro(string & name)
723 if (getToken().cs() != "newcommand") {
724 lyxerr << "\\newcommand expected\n";
728 if (getToken().cat() != catBegin) {
729 lyxerr << "'{' in \\newcommand expected (1)\n";
733 name = getToken().cs();
735 if (getToken().cat() != catEnd) {
736 lyxerr << "'}' expected\n";
740 string arg = getArg('[', ']');
741 int narg = arg.empty() ? 0 : atoi(arg.c_str());
743 if (getToken().cat() != catBegin) {
744 lyxerr << "'{' in \\newcommand expected (2)\n";
749 parse_into(ar, FLAG_BRACE_LAST);
751 // we cannot handle recursive stuff at all
753 test.push_back(createMathInset(name));
754 if (ar.contains(test)) {
755 lyxerr << "we cannot handle recursive macros at all.\n";
759 MathMacroTable::create(name, narg, ar);
764 bool Parser::parse_normal(MathAtom & matrix)
767 Token const & t = getToken();
770 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
771 parse_into(matrix->cell(0), 0);
775 if (t.cat() == catMath) {
776 Token const & n = getToken();
777 if (n.cat() == catMath) {
778 // TeX's $$...$$ syntax for displayed math
779 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
780 MathHullInset * p = matrix->asHullInset();
781 parse_into(p->cell(0), 0);
782 p->numbered(0, curr_num_);
783 p->label(0, curr_label_);
785 // simple $...$ stuff
787 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
788 parse_into(matrix->cell(0), 0);
793 if (!t.cs().size()) {
794 lyxerr << "start of math expected, got '" << t << "'\n";
798 string const & cs = t.cs();
803 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
804 MathHullInset * p = matrix->asHullInset();
805 parse_into(p->cell(0), 0);
806 p->numbered(0, curr_num_);
807 p->label(0, curr_label_);
812 lyxerr << "'begin' of un-simple math expected, got '" << cs << "'\n";
816 string const name = getArg('{', '}');
818 if (name == "math") {
819 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
820 parse_into(matrix->cell(0), 0);
824 if (name == "equation" || name == "equation*" || name == "displaymath") {
825 curr_num_ = (name == "equation");
827 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
828 MathHullInset * p = matrix->asHullInset();
829 parse_into(p->cell(0), FLAG_END);
830 p->numbered(0, curr_num_);
831 p->label(0, curr_label_);
835 if (name == "eqnarray" || name == "eqnarray*") {
836 matrix = MathAtom(new MathHullInset(LM_OT_EQNARRAY));
837 return parse_lines(matrix, !stared(name), true);
840 if (name == "align" || name == "align*") {
841 matrix = MathAtom(new MathHullInset(LM_OT_ALIGN));
842 return parse_lines(matrix, !stared(name), true);
845 if (name == "alignat" || name == "alignat*") {
846 int nc = 2 * atoi(getArg('{', '}').c_str());
847 matrix = MathAtom(new MathHullInset(LM_OT_ALIGNAT, nc));
848 return parse_lines(matrix, !stared(name), true);
851 if (name == "xalignat" || name == "xalignat*") {
852 int nc = 2 * atoi(getArg('{', '}').c_str());
853 matrix = MathAtom(new MathHullInset(LM_OT_XALIGNAT, nc));
854 return parse_lines(matrix, !stared(name), true);
857 if (name == "xxalignat") {
858 int nc = 2 * atoi(getArg('{', '}').c_str());
859 matrix = MathAtom(new MathHullInset(LM_OT_XXALIGNAT, nc));
860 return parse_lines(matrix, !stared(name), true);
863 if (name == "multline" || name == "multline*") {
864 matrix = MathAtom(new MathHullInset(LM_OT_MULTLINE));
865 return parse_lines(matrix, !stared(name), true);
868 if (name == "gather" || name == "gather*") {
869 matrix = MathAtom(new MathHullInset(LM_OT_GATHER));
870 return parse_lines(matrix, !stared(name), true);
873 lyxerr[Debug::MATHED] << "1: unknown math environment: " << name << "\n";
874 lyxerr << "1: unknown math environment: " << name << "\n";
879 void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
881 parse_into1(array, flags, code);
882 // remove 'unnecessary' braces:
883 if (array.size() == 1 && array.back()->asBraceInset()) {
884 lyxerr << "extra braces removed\n";
885 array = array.back()->asBraceInset()->cell(0);
890 void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
896 Token const & t = getToken();
898 //lyxerr << "t: " << t << " flags: " << flags << "\n";
899 //array.dump(lyxerr);
902 if (flags & FLAG_ITEM) {
904 if (t.cat() == catBegin) {
905 // skip the brace and collect everything to the next matching
907 flags |= FLAG_BRACE_LAST;
910 // handle only this single token, leave the loop if done
915 if (flags & FLAG_BLOCK) {
916 if (t.cat() == catAlign || t.isCR() || t.cs() == "end") {
922 if (flags & FLAG_BLOCK2) {
923 if (t.cat() == catAlign || t.isCR() || t.cs() == "end"
924 || t.cat() == catEnd) {
933 if (t.cat() == catMath) {
934 if (flags & FLAG_BOX) {
935 // we are inside an mbox, so opening new math is allowed
936 array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
937 parse_into(array.back()->cell(0), 0);
939 // otherwise this is the end of the formula
944 else if (t.cat() == catLetter)
945 add(array, t.character(), code);
947 else if (t.cat() == catSpace && code == LM_TC_TEXTRM)
948 add(array, t.character(), code);
950 else if (t.cat() == catParameter) {
951 Token const & n = getToken();
952 array.push_back(MathAtom(new MathMacroArgument(n.character()-'0', code)));
955 else if (t.cat() == catBegin) {
957 parse_into(ar, FLAG_BRACE_LAST);
958 #ifndef WITH_WARNINGS
959 #warning this might be wrong in general!
961 // ignore braces around simple items
962 if ((ar.size() == 1 && !ar.front()->needsBraces()
963 || (ar.size() == 2 && !ar.front()->needsBraces()
964 && ar.back()->asScriptInset()))
965 || (ar.size() == 0 && array.size() == 0))
969 array.push_back(MathAtom(new MathBraceInset));
970 array.back()->cell(0).swap(ar);
974 else if (t.cat() == catEnd) {
975 if (flags & FLAG_BRACE_LAST)
977 lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
978 //lyxerr << "found '}' unexpectedly\n";
979 add(array, '}', LM_TC_TEX);
982 else if (t.cat() == catAlign) {
983 lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
984 //lyxerr << "found tab unexpectedly\n";
985 add(array, '&', LM_TC_TEX);
988 else if (t.cat() == catSuper || t.cat() == catSub) {
989 bool up = (t.cat() == catSuper);
990 MathScriptInset * p = 0;
992 p = array.back()->asScriptInset();
993 if (!p || p->has(up)) {
994 array.push_back(MathAtom(new MathScriptInset(up)));
995 p = array.back()->asScriptInset();
998 parse_into(p->cell(up), FLAG_ITEM);
1003 else if (t.character() == ']' && (flags & FLAG_BRACK_END))
1006 else if (t.cat() == catOther)
1007 add(array, t.character(), code);
1010 // control sequences
1012 else if (t.cs() == "protect")
1013 // ignore \\protect, will be re-added during output
1016 else if (t.cs() == "end")
1019 else if (t.cs() == ")")
1022 else if (t.cs() == "]")
1025 else if (t.cs() == "\\") {
1026 curr_skip_ = getArg('[', ']');
1027 //lyxerr << "found newline unexpectedly, array: '" << array << "'\n";
1028 lyxerr << "found newline unexpectedly\n";
1029 array.push_back(createMathInset("\\"));
1032 else if (t.cs() == "limits")
1035 else if (t.cs() == "nolimits")
1038 else if (t.cs() == "nonumber")
1041 else if (t.cs() == "number")
1044 else if (t.cs() == "sqrt") {
1047 array.push_back(MathAtom(new MathRootInset));
1048 parse_into(array.back()->cell(0), FLAG_BRACK_END);
1049 parse_into(array.back()->cell(1), FLAG_ITEM);
1052 array.push_back(MathAtom(new MathSqrtInset));
1053 parse_into(array.back()->cell(0), FLAG_ITEM);
1057 else if (t.cs() == "left") {
1058 string l = getToken().asString();
1060 parse_into(ar, FLAG_RIGHT);
1061 string r = getToken().asString();
1062 MathAtom dl(new MathDelimInset(l, r));
1064 array.push_back(dl);
1067 else if (t.cs() == "right") {
1068 if (!(flags & FLAG_RIGHT)) {
1069 //lyxerr << "got so far: '" << array << "'\n";
1070 error("Unmatched right delimiter");
1075 else if (t.cs() == "begin") {
1076 string const name = getArg('{', '}');
1077 if (name == "array") {
1078 string const valign = getArg('[', ']') + 'c';
1079 string const halign = getArg('{', '}');
1080 array.push_back(MathAtom(new MathArrayInset(valign[0], halign)));
1081 parse_lines(array.back(), false, false);
1082 } else if (name == "split" || name == "cases") {
1083 array.push_back(createMathInset(name));
1084 parse_lines(array.back(), false, false);
1085 } else if (name == "pmatrix" || name == "bmatrix" ||
1086 name == "vmatrix" || name == "Vmatrix") {
1087 array.push_back(createMathInset(name));
1088 parse_lines2(array.back(), false);
1090 lyxerr << "unknow math inset begin '" << name << "'\n";
1093 else if (t.cs() == "kern") {
1094 #ifdef WITH_WARNINGS
1099 Token const & t = getToken();
1105 if (isValidLength(s))
1108 array.push_back(MathAtom(new MathKernInset(s)));
1111 else if (t.cs() == "label") {
1112 curr_label_ = getArg('{', '}');
1115 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1116 MathAtom p = createMathInset(t.cs());
1117 array.swap(p->cell(0));
1118 parse_into(p->cell(1), flags, code);
1123 else if (t.cs() == "xymatrix") {
1124 array.push_back(createMathInset(t.cs()));
1126 parse_lines2(array.back(), true);
1131 else if (1 && t.cs() == "ar") {
1132 MathXYArrowInset * p = new MathXYArrowInset;
1134 // try to read target
1137 parse_into(p->cell(0), FLAG_BRACK_END);
1138 //lyxerr << "read target: " << p->cell(0) << "\n";
1143 // try to read label
1144 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1145 p->up_ = nextToken().cat() == catSuper;
1147 parse_into(p->cell(1), FLAG_ITEM);
1148 //lyxerr << "read label: " << p->cell(1) << "\n";
1151 array.push_back(MathAtom(p));
1152 //lyxerr << "read array: " << array << "\n";
1155 else if (t.cs() == "mbox") {
1156 array.push_back(createMathInset(t.cs()));
1157 // slurp in the argument of mbox
1159 MathBoxInset * p = array.back()->asBoxInset();
1165 else if (t.cs().size()) {
1166 latexkeys const * l = in_word_set(t.cs());
1168 if (l->token == LM_TK_FONT) {
1169 //lyxerr << "starting font\n";
1170 //CatCode catSpaceSave = theCatcode[' '];
1171 //if (l->id == LM_TC_TEXTRM) {
1172 // // temporarily change catcode
1173 // theCatcode[' '] = catLetter;
1177 parse_into(ar, FLAG_ITEM, static_cast<MathTextCodes>(l->id));
1178 array.push_back(ar);
1180 // undo catcode changes
1181 ////theCatcode[' '] = catSpaceSave;
1182 //lyxerr << "ending font\n";
1185 else if (l->token == LM_TK_OLDFONT) {
1186 code = static_cast<MathTextCodes>(l->id);
1189 else if (l->token == LM_TK_BOX) {
1190 MathAtom p = createMathInset(t.cs());
1191 parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
1195 else if (l->token == LM_TK_STY) {
1196 MathAtom p = createMathInset(t.cs());
1197 parse_into(p->cell(0), flags, code);
1203 MathAtom p = createMathInset(t.cs());
1204 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1205 parse_into(p->cell(i), FLAG_ITEM);
1211 MathAtom p = createMathInset(t.cs());
1212 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1213 parse_into(p->cell(i), FLAG_ITEM);
1219 if (flags & FLAG_LEAVE) {
1220 flags &= ~FLAG_LEAVE;
1226 lyxerr << " Math Panic, expect problems!\n";
1227 // Search for the end command.
1231 } while (good() && t.cs() != "end");
1237 } // anonymous namespace
1240 void mathed_parse_cell(MathArray & ar, string const & str)
1242 istringstream is(str.c_str());
1243 mathed_parse_cell(ar, is);
1247 void mathed_parse_cell(MathArray & ar, istream & is)
1249 Parser(is).parse_into(ar, 0);
1254 bool mathed_parse_macro(string & name, string const & str)
1256 istringstream is(str.c_str());
1258 return parser.parse_macro(name);
1261 bool mathed_parse_macro(string & name, istream & is)
1264 return parser.parse_macro(name);
1267 bool mathed_parse_macro(string & name, LyXLex & lex)
1270 return parser.parse_macro(name);
1275 bool mathed_parse_normal(MathAtom & t, string const & str)
1277 istringstream is(str.c_str());
1279 return parser.parse_normal(t);
1282 bool mathed_parse_normal(MathAtom & t, istream & is)
1285 return parser.parse_normal(t);
1288 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1291 return parser.parse_normal(t);