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_casesinset.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_splitinset.h"
72 #include "math_sqrtinset.h"
73 #include "math_support.h"
74 #include "math_xyarrowinset.h"
79 #include "support/lstrings.h"
95 bool stared(string const & s)
97 string::size_type const n = s.size();
98 return n && s[n - 1] == '*';
102 void add(MathArray & ar, char c, MathTextCodes code)
104 ar.push_back(MathAtom(new MathCharInset(c, code)));
108 // These are TeX's catcodes
110 catEscape, // 0 backslash
120 catSpace, // 10 space
121 catLetter, // 11 a-zA-Z
122 catOther, // 12 none of the above
125 catInvalid // 15 <delete>
128 CatCode theCatcode[256];
131 inline CatCode catcode(unsigned char c)
133 return theCatcode[c];
138 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing process
139 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
140 FLAG_END = 1 << 3, // next \\end ends the parsing process
141 FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process
142 FLAG_BOX = 1 << 5, // we are in a box
143 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
144 FLAG_BLOCK = 1 << 7, // next block ends the parsing process
145 FLAG_BLOCK2 = 1 << 8, // next block2 ends the parsing process
146 FLAG_LEAVE = 1 << 9 // leave the loop at the end
152 fill(theCatcode, theCatcode + 256, catOther);
153 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
154 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
156 theCatcode['\\'] = catEscape;
157 theCatcode['{'] = catBegin;
158 theCatcode['}'] = catEnd;
159 theCatcode['$'] = catMath;
160 theCatcode['&'] = catAlign;
161 theCatcode['\n'] = catNewline;
162 theCatcode['#'] = catParameter;
163 theCatcode['^'] = catSuper;
164 theCatcode['_'] = catSub;
165 theCatcode['
\7f'] = catIgnore;
166 theCatcode[' '] = catSpace;
167 theCatcode['\t'] = catSpace;
168 theCatcode['\r'] = catSpace;
169 theCatcode['~'] = catActive;
170 theCatcode['%'] = catComment;
176 // Helper class for parsing
182 Token() : cs_(), char_(0), cat_(catIgnore) {}
184 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
186 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
189 string const & cs() const { return cs_; }
191 CatCode cat() const { return cat_; }
193 char character() const { return char_; }
195 string asString() const;
208 bool Token::isCR() const
210 return cs_ == "\\" || cs_ == "cr" || cs_ == "crcr";
213 string Token::asString() const
215 return cs_.size() ? cs_ : string(1, char_);
218 // Angus' compiler says these are not needed
219 //bool operator==(Token const & s, Token const & t)
221 // return s.character() == t.character()
222 // && s.cat() == t.cat() && s.cs() == t.cs();
225 //bool operator!=(Token const & s, Token const & t)
230 ostream & operator<<(ostream & os, Token const & t)
233 os << "\\" << t.cs();
235 os << "[" << t.character() << "," << t.cat() << "]";
244 Parser(LyXLex & lex);
246 Parser(istream & is);
249 bool parse_macro(string & name);
251 bool parse_normal(MathAtom &);
253 void parse_into(MathArray & array, unsigned flags, MathTextCodes = LM_TC_MIN);
255 int lineno() const { return lineno_; }
261 void parse_into1(MathArray & array, unsigned flags, MathTextCodes);
263 string getArg(char lf, char rf);
267 void error(string const & msg);
269 bool parse_lines(MathAtom & t, bool numbered, bool outmost);
270 /// parses {... & ... \\ ... & ... }
271 bool parse_lines2(MathAtom & t);
272 /// dump contents to screen
277 void tokenize(istream & is);
279 void tokenize(string const & s);
281 void skipSpaceTokens(istream & is, char c);
283 void push_back(Token const & t);
287 Token const & prevToken() const;
289 Token const & nextToken() const;
291 Token const & getToken();
292 /// skips spaces if any
294 /// skips opening brace
296 /// skips closing brace
298 /// counts a sequence of hlines
301 void lex(string const & s);
308 std::vector<Token> tokens_;
320 Parser::Parser(LyXLex & lexer)
321 : lineno_(lexer.getLineNo()), pos_(0), curr_num_(false)
323 tokenize(lexer.getStream());
328 Parser::Parser(istream & is)
329 : lineno_(0), pos_(0), curr_num_(false)
335 void Parser::push_back(Token const & t)
337 tokens_.push_back(t);
341 void Parser::pop_back()
347 Token const & Parser::prevToken() const
349 static const Token dummy;
350 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
354 Token const & Parser::nextToken() const
356 static const Token dummy;
357 return good() ? tokens_[pos_] : dummy;
361 Token const & Parser::getToken()
363 static const Token dummy;
364 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
365 return good() ? tokens_[pos_++] : dummy;
369 void Parser::skipSpaces()
371 while (nextToken().cat() == catSpace)
376 void Parser::skipBegin()
378 if (nextToken().cat() == catBegin)
381 lyxerr << "'{' expected\n";
385 void Parser::skipEnd()
387 if (nextToken().cat() == catEnd)
390 lyxerr << "'}' expected\n";
394 int Parser::readHLines()
398 while (nextToken().cs() == "hline") {
407 void Parser::putback()
413 bool Parser::good() const
415 return pos_ < tokens_.size();
419 char Parser::getChar()
422 lyxerr << "The input stream is not well..." << endl;
423 return tokens_[pos_++].character();
427 string Parser::getArg(char lf, char rg)
437 while ((c = getChar()) != rg && good())
444 void Parser::tokenize(istream & is)
446 // eat everything up to the next \end_inset or end of stream
447 // and store it in s for further tokenization
452 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
453 s = s.substr(0, s.size() - 10);
463 void Parser::skipSpaceTokens(istream & is, char c)
465 // skip trailing spaces
466 while (catcode(c) == catSpace || catcode(c) == catNewline)
469 //lyxerr << "putting back: " << c << "\n";
474 void Parser::tokenize(string const & buffer)
476 static bool init_done = false;
483 istringstream is(buffer.c_str(), ios::in | ios::binary);
487 lyxerr << "reading c: " << c << "\n";
489 switch (catcode(c)) {
493 if (catcode(c) == catNewline)
494 ; //push_back(Token("par"));
496 push_back(Token(' ', catSpace));
503 while (is.get(c) && catcode(c) != catNewline)
512 error("unexpected end of input");
515 if (catcode(c) == catLetter) {
517 while (is.get(c) && catcode(c) == catLetter)
519 skipSpaceTokens(is, c);
528 push_back(Token(c, catcode(c)));
530 skipSpaceTokens(is, c);
535 lyxerr << "ignoring a char: " << int(c) << "\n";
540 push_back(Token(c, catcode(c)));
548 void Parser::dump() const
550 lyxerr << "\nTokens: ";
551 for (unsigned i = 0; i < tokens_.size(); ++i)
552 lyxerr << tokens_[i];
557 void Parser::error(string const & msg)
559 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
566 bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
568 MathGridInset * p = t->asGridInset();
571 lyxerr << "error in Parser::parse_lines() 1\n";
575 // save global variables
576 bool const saved_num = curr_num_;
577 string const saved_label = curr_label_;
579 // read initial hlines
580 p->rowinfo(0).lines_ = readHLines();
582 for (int row = 0; true; ++row) {
583 // reset global variables
584 curr_num_ = numbered;
588 for (MathInset::col_type col = 0; col < p->ncols(); ++col) {
589 //lyxerr << "reading cell " << row << " " << col << "\n";
590 //lyxerr << "ncols: " << p->ncols() << "\n";
592 MathArray & ar = p->cell(col + row * p->ncols());
593 parse_into(ar, FLAG_BLOCK);
594 // remove 'unnecessary' braces:
595 if (ar.size() == 1 && ar.back()->asBraceInset())
596 ar = ar.back()->asBraceInset()->cell(0);
597 //lyxerr << "ar: " << ar << "\n";
599 // break if cell is not followed by an ampersand
600 if (nextToken().cat() != catAlign) {
601 //lyxerr << "less cells read than normal in row/col: "
602 // << row << " " << col << "\n";
606 // skip the ampersand
611 MathHullInset * m = t->asHullInset();
613 lyxerr << "error in Parser::parse_lines() 2\n";
616 m->numbered(row, curr_num_);
617 m->label(row, curr_label_);
618 if (curr_skip_.size()) {
619 m->vcrskip(LyXLength(curr_skip_), row);
625 if (nextToken().isCR()) {
629 // try to read a length
632 // read hlines for next row
633 p->rowinfo(row + 1).lines_ = readHLines();
636 // we are finished if the next token is an 'end'
637 if (nextToken().cs() == "end") {
638 // skip the end-token
642 // leave the 'read a line'-loop
646 // otherwise, we have to start a new row
650 // restore "global" variables
651 curr_num_ = saved_num;
652 curr_label_ = saved_label;
658 bool Parser::parse_lines2(MathAtom & t)
660 MathGridInset * p = t->asGridInset();
662 lyxerr << "error in Parser::parse_lines() 1\n";
668 for (int row = 0; true; ++row) {
670 for (MathInset::col_type col = 0; true; ++col) {
671 //lyxerr << "reading cell " << row << " " << col << " " << p->ncols() << "\n";
673 if (col >= p->ncols()) {
674 //lyxerr << "adding col " << col << "\n";
675 p->addCol(p->ncols());
678 parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK2);
679 //lyxerr << "read cell: " << p->cell(col + row * p->ncols()) << "\n";
681 // break if cell is not followed by an ampersand
682 if (nextToken().cat() != catAlign) {
683 //lyxerr << "less cells read than normal in row/col: " << row << " " << col << "\n";
687 // skip the ampersand
692 if (nextToken().isCR()) {
697 // we are finished if the next token is an '}'
698 if (nextToken().cat() == catEnd) {
699 // skip the end-token
701 // leave the 'read a line'-loop
705 // otherwise, we have to start a new row
714 bool Parser::parse_macro(string & name)
719 if (getToken().cs() != "newcommand") {
720 lyxerr << "\\newcommand expected\n";
724 if (getToken().cat() != catBegin) {
725 lyxerr << "'{' in \\newcommand expected (1)\n";
729 name = getToken().cs();
731 if (getToken().cat() != catEnd) {
732 lyxerr << "'}' expected\n";
736 string arg = getArg('[', ']');
737 int narg = arg.empty() ? 0 : atoi(arg.c_str());
739 if (getToken().cat() != catBegin) {
740 lyxerr << "'{' in \\newcommand expected (2)\n";
745 parse_into(ar, FLAG_BRACE_LAST);
747 // we cannot handle recursive stuff at all
749 test.push_back(createMathInset(name));
750 if (ar.contains(test)) {
751 lyxerr << "we cannot handle recursive macros at all.\n";
755 MathMacroTable::create(name, narg, ar);
760 bool Parser::parse_normal(MathAtom & matrix)
763 Token const & t = getToken();
766 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
767 parse_into(matrix->cell(0), 0);
771 if (t.cat() == catMath) {
772 Token const & n = getToken();
773 if (n.cat() == catMath) {
774 // TeX's $$...$$ syntax for displayed math
775 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
776 MathHullInset * p = matrix->asHullInset();
777 parse_into(p->cell(0), 0);
778 p->numbered(0, curr_num_);
779 p->label(0, curr_label_);
781 // simple $...$ stuff
783 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
784 parse_into(matrix->cell(0), 0);
789 if (!t.cs().size()) {
790 lyxerr << "start of math expected, got '" << t << "'\n";
794 string const & cs = t.cs();
799 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
800 MathHullInset * p = matrix->asHullInset();
801 parse_into(p->cell(0), 0);
802 p->numbered(0, curr_num_);
803 p->label(0, curr_label_);
808 lyxerr << "'begin' of un-simple math expected, got '" << cs << "'\n";
812 string const name = getArg('{', '}');
814 if (name == "math") {
815 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
816 parse_into(matrix->cell(0), 0);
820 if (name == "equation" || name == "equation*" || name == "displaymath") {
821 curr_num_ = (name == "equation");
823 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
824 MathHullInset * p = matrix->asHullInset();
825 parse_into(p->cell(0), FLAG_END);
826 p->numbered(0, curr_num_);
827 p->label(0, curr_label_);
831 if (name == "eqnarray" || name == "eqnarray*") {
832 matrix = MathAtom(new MathHullInset(LM_OT_EQNARRAY));
833 return parse_lines(matrix, !stared(name), true);
836 if (name == "align" || name == "align*") {
837 matrix = MathAtom(new MathHullInset(LM_OT_ALIGN));
838 return parse_lines(matrix, !stared(name), true);
841 if (name == "alignat" || name == "alignat*") {
842 int nc = 2 * atoi(getArg('{', '}').c_str());
843 matrix = MathAtom(new MathHullInset(LM_OT_ALIGNAT, nc));
844 return parse_lines(matrix, !stared(name), true);
847 if (name == "xalignat" || name == "xalignat*") {
848 int nc = 2 * atoi(getArg('{', '}').c_str());
849 matrix = MathAtom(new MathHullInset(LM_OT_XALIGNAT, nc));
850 return parse_lines(matrix, !stared(name), true);
853 if (name == "xxalignat") {
854 int nc = 2 * atoi(getArg('{', '}').c_str());
855 matrix = MathAtom(new MathHullInset(LM_OT_XXALIGNAT, nc));
856 return parse_lines(matrix, !stared(name), true);
859 if (name == "multline" || name == "multline*") {
860 matrix = MathAtom(new MathHullInset(LM_OT_MULTLINE));
861 return parse_lines(matrix, !stared(name), true);
864 if (name == "gather" || name == "gather*") {
865 matrix = MathAtom(new MathHullInset(LM_OT_GATHER));
866 return parse_lines(matrix, !stared(name), true);
869 lyxerr[Debug::MATHED] << "1: unknown math environment: " << name << "\n";
870 lyxerr << "1: unknown math environment: " << name << "\n";
875 void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
877 parse_into1(array, flags, code);
878 // remove 'unnecessary' braces:
879 if (array.size() == 1 && array.back()->asBraceInset()) {
880 lyxerr << "extra braces removed\n";
881 array = array.back()->asBraceInset()->cell(0);
886 void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
892 Token const & t = getToken();
894 //lyxerr << "t: " << t << " flags: " << flags << "\n";
895 //array.dump(lyxerr);
898 if (flags & FLAG_ITEM) {
900 if (t.cat() == catBegin) {
901 // skip the brace and collect everything to the next matching
903 flags |= FLAG_BRACE_LAST;
906 // handle only this single token, leave the loop if done
911 if (flags & FLAG_BLOCK) {
912 if (t.cat() == catAlign || t.isCR() || t.cs() == "end") {
918 if (flags & FLAG_BLOCK2) {
919 if (t.cat() == catAlign || t.isCR() || t.cs() == "end"
920 || t.cat() == catEnd) {
929 if (t.cat() == catMath) {
930 if (flags & FLAG_BOX) {
931 // we are inside an mbox, so opening new math is allowed
932 array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
933 parse_into(array.back()->cell(0), 0);
935 // otherwise this is the end of the formula
940 else if (t.cat() == catLetter)
941 add(array, t.character(), code);
943 else if (t.cat() == catSpace && code == LM_TC_TEXTRM)
944 add(array, t.character(), code);
946 else if (t.cat() == catParameter) {
947 Token const & n = getToken();
948 array.push_back(MathAtom(new MathMacroArgument(n.character()-'0', code)));
951 else if (t.cat() == catBegin) {
953 parse_into(ar, FLAG_BRACE_LAST);
954 #ifndef WITH_WARNINGS
955 #warning this might be wrong in general!
957 // ignore braces around simple items
958 if ((ar.size() == 1 && !ar.front()->needsBraces()
959 || (ar.size() == 2 && !ar.front()->needsBraces()
960 && ar.back()->asScriptInset()))
961 || (ar.size() == 0 && array.size() == 0))
965 array.push_back(MathAtom(new MathBraceInset));
966 array.back()->cell(0).swap(ar);
970 else if (t.cat() == catEnd) {
971 if (flags & FLAG_BRACE_LAST)
973 lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
974 //lyxerr << "found '}' unexpectedly\n";
975 add(array, '}', LM_TC_TEX);
978 else if (t.cat() == catAlign) {
979 lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
980 //lyxerr << "found tab unexpectedly\n";
981 add(array, '&', LM_TC_TEX);
984 else if (t.cat() == catSuper || t.cat() == catSub) {
985 bool up = (t.cat() == catSuper);
986 MathScriptInset * p = 0;
988 p = array.back()->asScriptInset();
989 if (!p || p->has(up)) {
990 array.push_back(MathAtom(new MathScriptInset(up)));
991 p = array.back()->asScriptInset();
994 parse_into(p->cell(up), FLAG_ITEM);
999 else if (t.character() == ']' && (flags & FLAG_BRACK_END))
1002 else if (t.cat() == catOther)
1003 add(array, t.character(), code);
1006 // control sequences
1008 else if (t.cs() == "protect")
1009 // ignore \\protect, will be re-added during output
1012 else if (t.cs() == "end")
1015 else if (t.cs() == ")")
1018 else if (t.cs() == "]")
1021 else if (t.cs() == "\\") {
1022 curr_skip_ = getArg('[', ']');
1023 //lyxerr << "found newline unexpectedly, array: '" << array << "'\n";
1024 lyxerr << "found newline unexpectedly\n";
1025 array.push_back(createMathInset("\\"));
1028 else if (t.cs() == "limits")
1031 else if (t.cs() == "nolimits")
1034 else if (t.cs() == "nonumber")
1037 else if (t.cs() == "number")
1040 else if (t.cs() == "sqrt") {
1043 array.push_back(MathAtom(new MathRootInset));
1044 parse_into(array.back()->cell(0), FLAG_BRACK_END);
1045 parse_into(array.back()->cell(1), FLAG_ITEM);
1048 array.push_back(MathAtom(new MathSqrtInset));
1049 parse_into(array.back()->cell(0), FLAG_ITEM);
1053 else if (t.cs() == "left") {
1054 string l = getToken().asString();
1056 parse_into(ar, FLAG_RIGHT);
1057 string r = getToken().asString();
1058 MathAtom dl(new MathDelimInset(l, r));
1060 array.push_back(dl);
1063 else if (t.cs() == "right") {
1064 if (!(flags & FLAG_RIGHT)) {
1065 //lyxerr << "got so far: '" << array << "'\n";
1066 error("Unmatched right delimiter");
1071 else if (t.cs() == "begin") {
1072 string const name = getArg('{', '}');
1073 if (name == "array") {
1074 string const valign = getArg('[', ']') + 'c';
1075 string const halign = getArg('{', '}');
1076 array.push_back(MathAtom(new MathArrayInset(valign[0], halign)));
1077 parse_lines(array.back(), false, false);
1078 } else if (name == "split") {
1079 array.push_back(MathAtom(new MathSplitInset(1)));
1080 parse_lines(array.back(), false, false);
1081 } else if (name == "cases") {
1082 array.push_back(MathAtom(new MathCasesInset));
1083 parse_lines(array.back(), false, false);
1085 lyxerr << "unknow math inset begin '" << name << "'\n";
1088 else if (t.cs() == "kern") {
1089 #ifdef WITH_WARNINGS
1094 Token const & t = getToken();
1100 if (isValidLength(s))
1103 array.push_back(MathAtom(new MathKernInset(s)));
1106 else if (t.cs() == "label") {
1107 curr_label_ = getArg('{', '}');
1110 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1111 MathAtom p = createMathInset(t.cs());
1112 array.swap(p->cell(0));
1113 parse_into(p->cell(1), flags, code);
1118 else if (t.cs() == "xymatrix") {
1119 array.push_back(createMathInset(t.cs()));
1120 parse_lines2(array.back());
1125 else if (1 && t.cs() == "ar") {
1126 MathXYArrowInset * p = new MathXYArrowInset;
1128 // try to read target
1131 parse_into(p->cell(0), FLAG_BRACK_END);
1132 //lyxerr << "read target: " << p->cell(0) << "\n";
1137 // try to read label
1138 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1139 p->up_ = nextToken().cat() == catSuper;
1141 parse_into(p->cell(1), FLAG_ITEM);
1142 //lyxerr << "read label: " << p->cell(1) << "\n";
1145 array.push_back(MathAtom(p));
1146 //lyxerr << "read array: " << array << "\n";
1149 else if (t.cs() == "mbox") {
1150 array.push_back(createMathInset(t.cs()));
1151 // slurp in the argument of mbox
1153 MathBoxInset * p = array.back()->asBoxInset();
1159 else if (t.cs().size()) {
1160 latexkeys const * l = in_word_set(t.cs());
1162 if (l->token == LM_TK_FONT) {
1163 //lyxerr << "starting font\n";
1164 //CatCode catSpaceSave = theCatcode[' '];
1165 //if (l->id == LM_TC_TEXTRM) {
1166 // // temporarily change catcode
1167 // theCatcode[' '] = catLetter;
1171 parse_into(ar, FLAG_ITEM, static_cast<MathTextCodes>(l->id));
1172 array.push_back(ar);
1174 // undo catcode changes
1175 ////theCatcode[' '] = catSpaceSave;
1176 //lyxerr << "ending font\n";
1179 else if (l->token == LM_TK_OLDFONT) {
1180 code = static_cast<MathTextCodes>(l->id);
1183 else if (l->token == LM_TK_BOX) {
1184 MathAtom p = createMathInset(t.cs());
1185 parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
1189 else if (l->token == LM_TK_STY) {
1190 MathAtom p = createMathInset(t.cs());
1191 parse_into(p->cell(0), flags, code);
1197 MathAtom p = createMathInset(t.cs());
1198 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1199 parse_into(p->cell(i), FLAG_ITEM);
1205 MathAtom p = createMathInset(t.cs());
1206 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1207 parse_into(p->cell(i), FLAG_ITEM);
1213 if (flags & FLAG_LEAVE) {
1214 flags &= ~FLAG_LEAVE;
1220 lyxerr << " Math Panic, expect problems!\n";
1221 // Search for the end command.
1225 } while (good() && t.cs() != "end");
1231 } // anonymous namespace
1234 void mathed_parse_cell(MathArray & ar, string const & str)
1236 istringstream is(str.c_str());
1237 mathed_parse_cell(ar, is);
1241 void mathed_parse_cell(MathArray & ar, istream & is)
1243 Parser(is).parse_into(ar, 0);
1248 bool mathed_parse_macro(string & name, string const & str)
1250 istringstream is(str.c_str());
1252 return parser.parse_macro(name);
1255 bool mathed_parse_macro(string & name, istream & is)
1258 return parser.parse_macro(name);
1261 bool mathed_parse_macro(string & name, LyXLex & lex)
1264 return parser.parse_macro(name);
1269 bool mathed_parse_normal(MathAtom & t, string const & str)
1271 istringstream is(str.c_str());
1273 return parser.parse_normal(t);
1276 bool mathed_parse_normal(MathAtom & t, istream & is)
1279 return parser.parse_normal(t);
1282 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1285 return parser.parse_normal(t);