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_amsarrayinset.h"
56 #include "math_braceinset.h"
57 #include "math_casesinset.h"
58 #include "math_charinset.h"
59 #include "math_deliminset.h"
60 #include "math_factory.h"
61 #include "math_funcinset.h"
62 #include "math_kerninset.h"
63 #include "math_macro.h"
64 #include "math_macrotable.h"
65 #include "math_macrotemplate.h"
66 #include "math_hullinset.h"
67 #include "math_rootinset.h"
68 #include "math_sizeinset.h"
69 #include "math_sqrtinset.h"
70 #include "math_scriptinset.h"
71 #include "math_specialcharinset.h"
72 #include "math_splitinset.h"
73 #include "math_sqrtinset.h"
74 #include "math_support.h"
75 #include "math_xyarrowinset.h"
80 #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)));
549 void Parser::dump() const
551 lyxerr << "\nTokens: ";
552 for (unsigned i = 0; i < tokens_.size(); ++i)
553 lyxerr << tokens_[i];
558 void Parser::error(string const & msg)
560 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
567 bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
569 MathGridInset * p = t->asGridInset();
572 lyxerr << "error in Parser::parse_lines() 1\n";
576 // save global variables
577 bool const saved_num = curr_num_;
578 string const saved_label = curr_label_;
580 // read initial hlines
581 p->rowinfo(0).lines_ = readHLines();
583 for (int row = 0; true; ++row) {
584 // reset global variables
585 curr_num_ = numbered;
589 for (MathInset::col_type col = 0; col < p->ncols(); ++col) {
590 //lyxerr << "reading cell " << row << " " << col << "\n";
591 //lyxerr << "ncols: " << p->ncols() << "\n";
593 MathArray & ar = p->cell(col + row * p->ncols());
594 parse_into(ar, FLAG_BLOCK);
595 // remove 'unnecessary' braces:
596 if (ar.size() == 1 && ar.back()->asBraceInset())
597 ar = ar.back()->asBraceInset()->cell(0);
598 //lyxerr << "ar: " << ar << "\n";
600 // break if cell is not followed by an ampersand
601 if (nextToken().cat() != catAlign) {
602 //lyxerr << "less cells read than normal in row/col: "
603 // << row << " " << col << "\n";
607 // skip the ampersand
612 MathHullInset * m = t->asHullInset();
614 lyxerr << "error in Parser::parse_lines() 2\n";
617 m->numbered(row, curr_num_);
618 m->label(row, curr_label_);
619 if (curr_skip_.size()) {
620 m->vcrskip(LyXLength(curr_skip_), row);
626 if (nextToken().isCR()) {
630 // try to read a length
633 // read hlines for next row
634 p->rowinfo(row + 1).lines_ = readHLines();
637 // we are finished if the next token is an 'end'
638 if (nextToken().cs() == "end") {
639 // skip the end-token
643 // leave the 'read a line'-loop
647 // otherwise, we have to start a new row
651 // restore "global" variables
652 curr_num_ = saved_num;
653 curr_label_ = saved_label;
659 bool Parser::parse_lines2(MathAtom & t, bool braced)
661 MathGridInset * p = t->asGridInset();
663 lyxerr << "error in Parser::parse_lines() 1\n";
667 for (int row = 0; true; ++row) {
669 for (MathInset::col_type col = 0; true; ++col) {
670 //lyxerr << "reading cell " << row << " " << col << " " << p->ncols() << "\n";
672 if (col >= p->ncols()) {
673 //lyxerr << "adding col " << col << "\n";
674 p->addCol(p->ncols());
677 parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK2);
678 //lyxerr << "read cell: " << p->cell(col + row * p->ncols()) << "\n";
680 // break if cell is not followed by an ampersand
681 if (nextToken().cat() != catAlign) {
682 //lyxerr << "less cells read than normal in row/col: " << row << " " << col << "\n";
686 // skip the ampersand
691 if (nextToken().isCR()) {
696 // we are finished if the next token is the one we expected
697 // skip the end-token
698 // leave the 'read a line'-loop
700 if (nextToken().cat() == catEnd) {
705 if (nextToken().cs() == "end") {
712 // otherwise, we have to start a new row
721 bool Parser::parse_macro(string & name)
726 if (getToken().cs() != "newcommand") {
727 lyxerr << "\\newcommand expected\n";
731 if (getToken().cat() != catBegin) {
732 lyxerr << "'{' in \\newcommand expected (1)\n";
736 name = getToken().cs();
738 if (getToken().cat() != catEnd) {
739 lyxerr << "'}' expected\n";
743 string arg = getArg('[', ']');
744 int narg = arg.empty() ? 0 : atoi(arg.c_str());
746 if (getToken().cat() != catBegin) {
747 lyxerr << "'{' in \\newcommand expected (2)\n";
752 parse_into(ar, FLAG_BRACE_LAST);
754 // we cannot handle recursive stuff at all
756 test.push_back(createMathInset(name));
757 if (ar.contains(test)) {
758 lyxerr << "we cannot handle recursive macros at all.\n";
762 MathMacroTable::create(name, narg, ar);
767 bool Parser::parse_normal(MathAtom & matrix)
770 Token const & t = getToken();
773 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
774 parse_into(matrix->cell(0), 0);
778 if (t.cat() == catMath) {
779 Token const & n = getToken();
780 if (n.cat() == catMath) {
781 // TeX's $$...$$ syntax for displayed math
782 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
783 MathHullInset * p = matrix->asHullInset();
784 parse_into(p->cell(0), 0);
785 p->numbered(0, curr_num_);
786 p->label(0, curr_label_);
788 // simple $...$ stuff
790 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
791 parse_into(matrix->cell(0), 0);
796 if (!t.cs().size()) {
797 lyxerr << "start of math expected, got '" << t << "'\n";
801 string const & cs = t.cs();
806 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
807 MathHullInset * p = matrix->asHullInset();
808 parse_into(p->cell(0), 0);
809 p->numbered(0, curr_num_);
810 p->label(0, curr_label_);
815 lyxerr << "'begin' of un-simple math expected, got '" << cs << "'\n";
819 string const name = getArg('{', '}');
821 if (name == "math") {
822 matrix = MathAtom(new MathHullInset(LM_OT_SIMPLE));
823 parse_into(matrix->cell(0), 0);
827 if (name == "equation" || name == "equation*" || name == "displaymath") {
828 curr_num_ = (name == "equation");
830 matrix = MathAtom(new MathHullInset(LM_OT_EQUATION));
831 MathHullInset * p = matrix->asHullInset();
832 parse_into(p->cell(0), FLAG_END);
833 p->numbered(0, curr_num_);
834 p->label(0, curr_label_);
838 if (name == "eqnarray" || name == "eqnarray*") {
839 matrix = MathAtom(new MathHullInset(LM_OT_EQNARRAY));
840 return parse_lines(matrix, !stared(name), true);
843 if (name == "align" || name == "align*") {
844 matrix = MathAtom(new MathHullInset(LM_OT_ALIGN));
845 return parse_lines(matrix, !stared(name), true);
848 if (name == "alignat" || name == "alignat*") {
849 int nc = 2 * atoi(getArg('{', '}').c_str());
850 matrix = MathAtom(new MathHullInset(LM_OT_ALIGNAT, nc));
851 return parse_lines(matrix, !stared(name), true);
854 if (name == "xalignat" || name == "xalignat*") {
855 int nc = 2 * atoi(getArg('{', '}').c_str());
856 matrix = MathAtom(new MathHullInset(LM_OT_XALIGNAT, nc));
857 return parse_lines(matrix, !stared(name), true);
860 if (name == "xxalignat") {
861 int nc = 2 * atoi(getArg('{', '}').c_str());
862 matrix = MathAtom(new MathHullInset(LM_OT_XXALIGNAT, nc));
863 return parse_lines(matrix, !stared(name), true);
866 if (name == "multline" || name == "multline*") {
867 matrix = MathAtom(new MathHullInset(LM_OT_MULTLINE));
868 return parse_lines(matrix, !stared(name), true);
871 if (name == "gather" || name == "gather*") {
872 matrix = MathAtom(new MathHullInset(LM_OT_GATHER));
873 return parse_lines(matrix, !stared(name), true);
876 lyxerr[Debug::MATHED] << "1: unknown math environment: " << name << "\n";
877 lyxerr << "1: unknown math environment: " << name << "\n";
882 void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
884 parse_into1(array, flags, code);
885 // remove 'unnecessary' braces:
886 if (array.size() == 1 && array.back()->asBraceInset()) {
887 lyxerr << "extra braces removed\n";
888 array = array.back()->asBraceInset()->cell(0);
893 void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
899 Token const & t = getToken();
901 //lyxerr << "t: " << t << " flags: " << flags << "\n";
902 //array.dump(lyxerr);
905 if (flags & FLAG_ITEM) {
907 if (t.cat() == catBegin) {
908 // skip the brace and collect everything to the next matching
910 flags |= FLAG_BRACE_LAST;
913 // handle only this single token, leave the loop if done
918 if (flags & FLAG_BLOCK) {
919 if (t.cat() == catAlign || t.isCR() || t.cs() == "end") {
925 if (flags & FLAG_BLOCK2) {
926 if (t.cat() == catAlign || t.isCR() || t.cs() == "end"
927 || t.cat() == catEnd) {
936 if (t.cat() == catMath) {
937 if (flags & FLAG_BOX) {
938 // we are inside an mbox, so opening new math is allowed
939 array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
940 parse_into(array.back()->cell(0), 0);
942 // otherwise this is the end of the formula
947 else if (t.cat() == catLetter)
948 add(array, t.character(), code);
950 else if (t.cat() == catSpace && code == LM_TC_TEXTRM)
951 add(array, t.character(), code);
953 else if (t.cat() == catParameter) {
954 Token const & n = getToken();
955 array.push_back(MathAtom(new MathMacroArgument(n.character()-'0', code)));
958 else if (t.cat() == catBegin) {
960 parse_into(ar, FLAG_BRACE_LAST);
961 #ifndef WITH_WARNINGS
962 #warning this might be wrong in general!
964 // ignore braces around simple items
965 if ((ar.size() == 1 && !ar.front()->needsBraces()
966 || (ar.size() == 2 && !ar.front()->needsBraces()
967 && ar.back()->asScriptInset()))
968 || (ar.size() == 0 && array.size() == 0))
972 array.push_back(MathAtom(new MathBraceInset));
973 array.back()->cell(0).swap(ar);
977 else if (t.cat() == catEnd) {
978 if (flags & FLAG_BRACE_LAST)
980 lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
981 //lyxerr << "found '}' unexpectedly\n";
982 add(array, '}', LM_TC_TEX);
985 else if (t.cat() == catAlign) {
986 lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
987 //lyxerr << "found tab unexpectedly\n";
988 add(array, '&', LM_TC_TEX);
991 else if (t.cat() == catSuper || t.cat() == catSub) {
992 bool up = (t.cat() == catSuper);
993 MathScriptInset * p = 0;
995 p = array.back()->asScriptInset();
996 if (!p || p->has(up)) {
997 array.push_back(MathAtom(new MathScriptInset(up)));
998 p = array.back()->asScriptInset();
1001 parse_into(p->cell(up), FLAG_ITEM);
1006 else if (t.character() == ']' && (flags & FLAG_BRACK_END))
1009 else if (t.cat() == catOther)
1010 add(array, t.character(), code);
1013 // control sequences
1015 else if (t.cs() == "protect")
1016 // ignore \\protect, will be re-added during output
1019 else if (t.cs() == "end")
1022 else if (t.cs() == ")")
1025 else if (t.cs() == "]")
1028 else if (t.cs() == "\\") {
1029 curr_skip_ = getArg('[', ']');
1030 //lyxerr << "found newline unexpectedly, array: '" << array << "'\n";
1031 lyxerr << "found newline unexpectedly\n";
1032 array.push_back(createMathInset("\\"));
1035 else if (t.cs() == "limits")
1038 else if (t.cs() == "nolimits")
1041 else if (t.cs() == "nonumber")
1044 else if (t.cs() == "number")
1047 else if (t.cs() == "sqrt") {
1050 array.push_back(MathAtom(new MathRootInset));
1051 parse_into(array.back()->cell(0), FLAG_BRACK_END);
1052 parse_into(array.back()->cell(1), FLAG_ITEM);
1055 array.push_back(MathAtom(new MathSqrtInset));
1056 parse_into(array.back()->cell(0), FLAG_ITEM);
1060 else if (t.cs() == "left") {
1061 string l = getToken().asString();
1063 parse_into(ar, FLAG_RIGHT);
1064 string r = getToken().asString();
1065 MathAtom dl(new MathDelimInset(l, r));
1067 array.push_back(dl);
1070 else if (t.cs() == "right") {
1071 if (!(flags & FLAG_RIGHT)) {
1072 //lyxerr << "got so far: '" << array << "'\n";
1073 error("Unmatched right delimiter");
1078 else if (t.cs() == "begin") {
1079 string const name = getArg('{', '}');
1080 if (name == "array") {
1081 string const valign = getArg('[', ']') + 'c';
1082 string const halign = getArg('{', '}');
1083 array.push_back(MathAtom(new MathArrayInset(valign[0], halign)));
1084 parse_lines(array.back(), false, false);
1085 } else if (name == "split") {
1086 array.push_back(MathAtom(new MathSplitInset(1)));
1087 parse_lines(array.back(), false, false);
1088 } else if (name == "cases") {
1089 array.push_back(MathAtom(new MathCasesInset));
1090 parse_lines(array.back(), false, false);
1091 } else if (name == "pmatrix" || name == "bmatrix") {
1092 array.push_back(MathAtom(new MathAMSArrayInset(name)));
1093 parse_lines2(array.back(), false);
1095 lyxerr << "unknow math inset begin '" << name << "'\n";
1098 else if (t.cs() == "kern") {
1099 #ifdef WITH_WARNINGS
1104 Token const & t = getToken();
1110 if (isValidLength(s))
1113 array.push_back(MathAtom(new MathKernInset(s)));
1116 else if (t.cs() == "label") {
1117 curr_label_ = getArg('{', '}');
1120 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1121 MathAtom p = createMathInset(t.cs());
1122 array.swap(p->cell(0));
1123 parse_into(p->cell(1), flags, code);
1128 else if (t.cs() == "xymatrix") {
1129 array.push_back(createMathInset(t.cs()));
1131 parse_lines2(array.back(), true);
1136 else if (1 && t.cs() == "ar") {
1137 MathXYArrowInset * p = new MathXYArrowInset;
1139 // try to read target
1142 parse_into(p->cell(0), FLAG_BRACK_END);
1143 //lyxerr << "read target: " << p->cell(0) << "\n";
1148 // try to read label
1149 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1150 p->up_ = nextToken().cat() == catSuper;
1152 parse_into(p->cell(1), FLAG_ITEM);
1153 //lyxerr << "read label: " << p->cell(1) << "\n";
1156 array.push_back(MathAtom(p));
1157 //lyxerr << "read array: " << array << "\n";
1160 else if (t.cs() == "mbox") {
1161 array.push_back(createMathInset(t.cs()));
1162 // slurp in the argument of mbox
1164 MathBoxInset * p = array.back()->asBoxInset();
1170 else if (t.cs().size()) {
1171 latexkeys const * l = in_word_set(t.cs());
1173 if (l->token == LM_TK_FONT) {
1174 //lyxerr << "starting font\n";
1175 //CatCode catSpaceSave = theCatcode[' '];
1176 //if (l->id == LM_TC_TEXTRM) {
1177 // // temporarily change catcode
1178 // theCatcode[' '] = catLetter;
1182 parse_into(ar, FLAG_ITEM, static_cast<MathTextCodes>(l->id));
1183 array.push_back(ar);
1185 // undo catcode changes
1186 ////theCatcode[' '] = catSpaceSave;
1187 //lyxerr << "ending font\n";
1190 else if (l->token == LM_TK_OLDFONT) {
1191 code = static_cast<MathTextCodes>(l->id);
1194 else if (l->token == LM_TK_BOX) {
1195 MathAtom p = createMathInset(t.cs());
1196 parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
1200 else if (l->token == LM_TK_STY) {
1201 MathAtom p = createMathInset(t.cs());
1202 parse_into(p->cell(0), flags, code);
1208 MathAtom p = createMathInset(t.cs());
1209 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1210 parse_into(p->cell(i), FLAG_ITEM);
1216 MathAtom p = createMathInset(t.cs());
1217 for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
1218 parse_into(p->cell(i), FLAG_ITEM);
1224 if (flags & FLAG_LEAVE) {
1225 flags &= ~FLAG_LEAVE;
1231 lyxerr << " Math Panic, expect problems!\n";
1232 // Search for the end command.
1236 } while (good() && t.cs() != "end");
1242 } // anonymous namespace
1245 void mathed_parse_cell(MathArray & ar, string const & str)
1247 istringstream is(str.c_str());
1248 mathed_parse_cell(ar, is);
1252 void mathed_parse_cell(MathArray & ar, istream & is)
1254 Parser(is).parse_into(ar, 0);
1259 bool mathed_parse_macro(string & name, string const & str)
1261 istringstream is(str.c_str());
1263 return parser.parse_macro(name);
1266 bool mathed_parse_macro(string & name, istream & is)
1269 return parser.parse_macro(name);
1272 bool mathed_parse_macro(string & name, LyXLex & lex)
1275 return parser.parse_macro(name);
1280 bool mathed_parse_normal(MathAtom & t, string const & str)
1282 istringstream is(str.c_str());
1284 return parser.parse_normal(t);
1287 bool mathed_parse_normal(MathAtom & t, istream & is)
1290 return parser.parse_normal(t);
1293 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1296 return parser.parse_normal(t);