2 \author André Pönitz (2001)
7 If someone desperately needs partial "structures" (such as a few
8 cells of an array inset or similar) (s)he could uses the
9 following hack as starting point to write some macros:
14 \def\makeamptab{\catcode`\&=4\relax}
15 \def\makeampletter{\catcode`\&=11\relax}
16 \def\b{\makeampletter\expandafter\makeamptab\bi}
36 #include "math_parser.h"
37 #include "math_inset.h"
38 #include "math_arrayinset.h"
39 #include "math_braceinset.h"
40 #include "math_boxinset.h"
41 #include "math_charinset.h"
42 #include "math_commentinset.h"
43 #include "math_deliminset.h"
44 #include "math_envinset.h"
45 #include "math_extern.h"
46 #include "math_factory.h"
47 #include "math_kerninset.h"
48 #include "math_macro.h"
49 #include "math_macrotemplate.h"
50 #include "math_hullinset.h"
51 #include "math_parboxinset.h"
52 #include "math_parinset.h"
53 #include "math_rootinset.h"
54 #include "math_scriptinset.h"
55 #include "math_sizeinset.h"
56 #include "math_sqrtinset.h"
57 #include "math_stringinset.h"
58 #include "math_support.h"
59 #include "math_xyarrowinset.h"
61 //#include "insets/insetref.h"
62 #include "ref_inset.h"
66 #include "support/LAssert.h"
67 #include "support/lstrings.h"
86 MathInset::mode_type asMode(MathInset::mode_type oldmode, string const & str)
88 if (str == "mathmode")
89 return MathInset::MATH_MODE;
90 if (str == "textmode" || str == "forcetext")
91 return MathInset::TEXT_MODE;
96 bool stared(string const & s)
98 string::size_type const n = s.size();
99 return n && s[n - 1] == '*';
103 // These are TeX's catcodes
105 catEscape, // 0 backslash
115 catSpace, // 10 space
116 catLetter, // 11 a-zA-Z
117 catOther, // 12 none of the above
120 catInvalid // 15 <delete>
123 CatCode theCatcode[256];
126 inline CatCode catcode(unsigned char c)
128 return theCatcode[c];
133 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
134 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
135 FLAG_END = 1 << 3, // next \\end ends the parsing process
136 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
137 FLAG_TEXTMODE = 1 << 5, // we are in a box
138 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
139 FLAG_LEAVE = 1 << 7, // leave the loop at the end
140 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
141 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
142 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
143 FLAG_OPTION = 1 << 11, // read [...] style option
144 FLAG_BRACED = 1 << 12 // read {...} style argument
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'] = catNewline;
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 { return cs_.size() ? cs_ : string(1, char_); }
204 ostream & operator<<(ostream & os, Token const & t)
207 os << '\\' << t.cs();
209 os << '[' << t.character() << ',' << t.cat() << ']';
218 typedef MathInset::mode_type mode_type;
221 Parser(LyXLex & lex);
223 Parser(istream & is);
226 bool parse(MathAtom & at);
228 void parse(MathArray & array, unsigned flags, mode_type mode);
230 void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
233 MathArray parse(unsigned flags, mode_type mode);
235 int lineno() const { return lineno_; }
241 void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
242 /// get arg delimited by 'left' and 'right'
243 string getArg(char left, char right);
247 void error(string const & msg);
248 /// dump contents to screen
251 void tokenize(istream & is);
253 void tokenize(string const & s);
255 void skipSpaceTokens(istream & is, char c);
257 void push_back(Token const & t);
261 Token const & prevToken() const;
263 Token const & nextToken() const;
265 Token const & getToken();
266 /// skips spaces if any
269 void lex(string const & s);
273 string parse_verbatim_item();
275 string parse_verbatim_option();
280 vector<Token> tokens_;
286 Parser::Parser(LyXLex & lexer)
287 : lineno_(lexer.getLineNo()), pos_(0)
289 tokenize(lexer.getStream());
294 Parser::Parser(istream & is)
295 : lineno_(0), pos_(0)
301 void Parser::push_back(Token const & t)
303 tokens_.push_back(t);
307 void Parser::pop_back()
313 Token const & Parser::prevToken() const
315 static const Token dummy;
316 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
320 Token const & Parser::nextToken() const
322 static const Token dummy;
323 return good() ? tokens_[pos_] : dummy;
327 Token const & Parser::getToken()
329 static const Token dummy;
330 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
331 return good() ? tokens_[pos_++] : dummy;
335 void Parser::skipSpaces()
337 while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
342 void Parser::putback()
348 bool Parser::good() const
350 return pos_ < tokens_.size();
354 char Parser::getChar()
357 error("The input stream is not well...");
358 return tokens_[pos_++].character();
362 string Parser::getArg(char left, char right)
372 while ((c = getChar()) != right && good())
379 void Parser::skipSpaceTokens(istream & is, char c)
381 // skip trailing spaces
382 while (catcode(c) == catSpace || catcode(c) == catNewline)
385 //lyxerr << "putting back: " << c << "\n";
390 void Parser::tokenize(istream & is)
392 // eat everything up to the next \end_inset or end of stream
393 // and store it in s for further tokenization
398 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
399 s = s.substr(0, s.size() - 10);
403 // Remove the space after \end_inset
404 if (is.get(c) && c != ' ')
412 void Parser::tokenize(string const & buffer)
414 static bool init_done = false;
421 istringstream is(buffer.c_str(), ios::in | ios::binary);
425 //lyxerr << "reading c: " << c << "\n";
427 switch (catcode(c)) {
431 if (catcode(c) == catNewline)
432 ; //push_back(Token("par"));
434 push_back(Token('\n', catNewline));
442 while (is.get(c) && catcode(c) != catNewline)
452 error("unexpected end of input");
455 if (catcode(c) == catLetter) {
457 while (is.get(c) && catcode(c) == catLetter)
459 skipSpaceTokens(is, c);
468 push_back(Token(c, catcode(c)));
470 skipSpaceTokens(is, c);
475 lyxerr << "ignoring a char: " << int(c) << "\n";
480 push_back(Token(c, catcode(c)));
490 void Parser::dump() const
492 lyxerr << "\nTokens: ";
493 for (unsigned i = 0; i < tokens_.size(); ++i) {
496 lyxerr << tokens_[i];
498 lyxerr << " pos: " << pos_ << "\n";
502 void Parser::error(string const & msg)
504 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
510 bool Parser::parse(MathAtom & at)
514 parse(ar, false, MathInset::UNDECIDED_MODE);
515 if (ar.size() != 1 || ar.front()->getType() == "none") {
516 lyxerr << "unusual contents found: " << ar << endl;
517 at = MathAtom(new MathParInset(ar));
518 //if (at->nargs() > 0)
519 // at.nucleus()->cell(0) = ar;
521 // lyxerr << "unusual contents found: " << ar << endl;
529 string Parser::parse_verbatim_option()
532 if (nextToken().character() == '[') {
533 Token t = getToken();
534 for (Token t = getToken(); t.character() != ']' && good(); t = getToken()) {
535 if (t.cat() == catBegin) {
537 res += '{' + parse_verbatim_item() + '}';
546 string Parser::parse_verbatim_item()
549 if (nextToken().cat() == catBegin) {
550 Token t = getToken();
551 for (Token t = getToken(); t.cat() != catEnd && good(); t = getToken()) {
552 if (t.cat() == catBegin) {
554 res += '{' + parse_verbatim_item() + '}';
564 MathArray Parser::parse(unsigned flags, mode_type mode)
567 parse(ar, flags, mode);
572 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
574 MathGridInset grid(1, 1);
575 parse1(grid, flags, mode, false);
576 array = grid.cell(0);
580 void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
583 parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
587 void Parser::parse1(MathGridInset & grid, unsigned flags,
588 mode_type mode, bool numbered)
591 MathGridInset::row_type cellrow = 0;
592 MathGridInset::col_type cellcol = 0;
593 MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
595 if (grid.asHullInset())
596 grid.asHullInset()->numbered(cellrow, numbered);
599 //lyxerr << "grid: " << grid << endl;
602 Token const & t = getToken();
605 lyxerr << "t: " << t << " flags: " << flags << "\n";
610 if (flags & FLAG_ITEM) {
611 if (t.cat() == catSpace)
615 if (t.cat() == catBegin) {
616 // skip the brace and collect everything to the next matching
618 flags |= FLAG_BRACE_LAST;
622 // handle only this single token, leave the loop if done
627 if (flags & FLAG_BRACED) {
628 if (t.cat() == catSpace)
631 if (t.cat() != catBegin) {
632 error("opening brace expected");
636 // skip the brace and collect everything to the next matching
638 flags = FLAG_BRACE_LAST;
642 if (flags & FLAG_OPTION) {
643 if (t.cat() == catOther && t.character() == '[') {
645 parse(ar, FLAG_BRACK_LAST, mode);
648 // no option found, put back token and we are done
657 if (t.cat() == catMath) {
658 if (mode != MathInset::MATH_MODE) {
659 // we are inside some text mode thingy, so opening new math is allowed
660 Token const & n = getToken();
661 if (n.cat() == catMath) {
662 // TeX's $$...$$ syntax for displayed math
663 cell->push_back(MathAtom(new MathHullInset("equation")));
664 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
665 getToken(); // skip the second '$' token
667 // simple $...$ stuff
669 cell->push_back(MathAtom(new MathHullInset("simple")));
670 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
674 else if (flags & FLAG_SIMPLE) {
675 // this is the end of the formula
680 error("something strange in the parser\n");
685 else if (t.cat() == catLetter)
686 cell->push_back(MathAtom(new MathCharInset(t.character())));
688 else if (t.cat() == catSpace && mode != MathInset::MATH_MODE) {
689 if (cell->empty() || cell->back()->getChar() != ' ')
690 cell->push_back(MathAtom(new MathCharInset(t.character())));
693 else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
694 cell->push_back(MathAtom(new MathCharInset(t.character())));
696 else if (t.cat() == catParameter) {
697 Token const & n = getToken();
698 cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
701 else if (t.cat() == catActive)
702 cell->push_back(MathAtom(new MathCharInset(t.character())));
704 else if (t.cat() == catBegin) {
706 parse(ar, FLAG_BRACE_LAST, mode);
707 // do not create a BraceInset if they were written by LyX
708 // this helps to keep the annoyance of "a choose b" to a minimum
709 if (ar.size() == 1 && ar[0]->extraBraces())
712 cell->push_back(MathAtom(new MathBraceInset(ar)));
715 else if (t.cat() == catEnd) {
716 if (flags & FLAG_BRACE_LAST)
718 error("found '}' unexpectedly");
720 //add(cell, '}', LM_TC_TEX);
723 else if (t.cat() == catAlign) {
725 //lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
726 if (cellcol == grid.ncols()) {
727 //lyxerr << "adding column " << cellcol << "\n";
728 grid.addCol(cellcol - 1);
730 cell = &grid.cell(grid.index(cellrow, cellcol));
733 else if (t.cat() == catSuper || t.cat() == catSub) {
734 bool up = (t.cat() == catSuper);
735 // we need no new script inset if the last thing was a scriptinset,
736 // which has that script already not the same script already
738 cell->push_back(MathAtom(new MathScriptInset(up)));
739 else if (cell->back()->asScriptInset() &&
740 !cell->back()->asScriptInset()->has(up))
741 cell->back().nucleus()->asScriptInset()->ensure(up);
742 else if (cell->back()->asScriptInset())
743 cell->push_back(MathAtom(new MathScriptInset(up)));
745 cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
746 MathScriptInset * p = cell->back().nucleus()->asScriptInset();
747 // special handling of {}-bases
748 // is this always correct?
749 // It appears that this is wrong (Dekel)
750 //if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
751 // p->nuc().back()->extraBraces())
752 // p->nuc() = p->nuc().back()->asNestInset()->cell(0);
753 parse(p->cell(up), FLAG_ITEM, mode);
760 else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
761 //lyxerr << "finished reading option\n";
765 else if (t.cat() == catOther)
766 cell->push_back(MathAtom(new MathCharInset(t.character())));
768 else if (t.cat() == catComment) {
771 Token const & t = getToken();
772 if (t.cat() == catNewline)
776 cell->push_back(MathAtom(new MathCommentInset(s)));
784 else if (t.cs() == "lyxlock") {
786 cell->back().nucleus()->lock(true);
789 else if (t.cs() == "def" || t.cs() == "newcommand") {
792 if (t.cs() == "def") {
794 name = getToken().cs();
798 while (good() && nextToken().cat() != catBegin) {
799 pars += getToken().cs();
803 //lyxerr << "read \\def parameter list '" << pars << "'\n";
805 } else { // t.cs() == "newcommand"
807 if (getToken().cat() != catBegin) {
808 error("'{' in \\newcommand expected (1) \n");
812 name = getToken().cs();
814 if (getToken().cat() != catEnd) {
815 error("'}' in \\newcommand expected\n");
819 string arg = getArg('[', ']');
821 nargs = atoi(arg.c_str());
826 parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
828 // we cannot handle recursive stuff at all
830 //test.push_back(createMathInset(name));
831 //if (ar1.contains(test)) {
832 // error("we cannot handle recursive macros at all.\n");
836 // is a version for display attached?
839 if (nextToken().cat() == catBegin) {
840 parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
843 cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
846 else if (t.cs() == "(") {
847 cell->push_back(MathAtom(new MathHullInset("simple")));
848 parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
851 else if (t.cs() == "[") {
852 cell->push_back(MathAtom(new MathHullInset("equation")));
853 parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
856 else if (t.cs() == "protect")
857 // ignore \\protect, will hopefully be re-added during output
860 else if (t.cs() == "end") {
861 if (flags & FLAG_END) {
862 // eat environment name
863 //string const name =
865 // FIXME: check that we ended the correct environment
868 error("found 'end' unexpectedly");
871 else if (t.cs() == ")") {
872 if (flags & FLAG_SIMPLE2)
874 error("found '\\)' unexpectedly");
877 else if (t.cs() == "]") {
878 if (flags & FLAG_EQUATION)
880 error("found '\\]' unexpectedly");
883 else if (t.cs() == "\\") {
884 grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
887 if (cellrow == grid.nrows())
888 grid.addRow(cellrow - 1);
889 if (grid.asHullInset())
890 grid.asHullInset()->numbered(cellrow, numbered);
891 cell = &grid.cell(grid.index(cellrow, cellcol));
895 else if (t.cs() == "multicolumn") {
896 // extract column count and insert dummy cells
898 parse(count, FLAG_ITEM, mode);
900 if (!extractNumber(count, cols)) {
901 lyxerr << " can't extract number of cells from " << count << "\n";
903 // resize the table if necessary
904 for (int i = 0; i < cols; ++i) {
906 if (cellcol == grid.ncols()) {
907 //lyxerr << "adding column " << cellcol << "\n";
908 grid.addCol(cellcol - 1);
910 cell = &grid.cell(grid.index(cellrow, cellcol));
911 // mark this as dummy
912 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
914 // the last cell is the real thng, not a dummy
915 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
917 // read special alignment
919 parse(align, FLAG_ITEM, mode);
920 //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
922 // parse the remaining contents into the "real" cell
923 parse(*cell, FLAG_ITEM, mode);
927 else if (t.cs() == "limits")
930 else if (t.cs() == "nolimits")
933 else if (t.cs() == "nonumber") {
934 if (grid.asHullInset())
935 grid.asHullInset()->numbered(cellrow, false);
938 else if (t.cs() == "number") {
939 if (grid.asHullInset())
940 grid.asHullInset()->numbered(cellrow, true);
943 else if (t.cs() == "hline") {
944 grid.rowinfo(cellrow).lines_ ++;
947 else if (t.cs() == "sqrt") {
949 parse(ar, FLAG_OPTION, mode);
951 cell->push_back(MathAtom(new MathRootInset));
952 cell->back().nucleus()->cell(0) = ar;
953 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
955 cell->push_back(MathAtom(new MathSqrtInset));
956 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
960 else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
961 cell->push_back(createMathInset(t.cs()));
962 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
963 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
966 else if (t.cs() == "ref" || t.cs() == "prettyref" ||
967 t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
968 cell->push_back(MathAtom(new RefInset(t.cs())));
969 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
970 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
973 else if (t.cs() == "left") {
974 string l = getToken().asString();
976 parse(ar, FLAG_RIGHT, mode);
977 string r = getToken().asString();
978 cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
981 else if (t.cs() == "right") {
982 if (flags & FLAG_RIGHT)
984 //lyxerr << "got so far: '" << cell << "'\n";
985 error("Unmatched right delimiter");
989 else if (t.cs() == "begin") {
990 string const name = getArg('{', '}');
992 if (name == "array" || name == "subarray") {
993 string const valign = parse_verbatim_option() + 'c';
994 string const halign = parse_verbatim_item();
995 cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
996 parse2(cell->back(), FLAG_END, mode, false);
999 else if (name == "split" || name == "cases" ||
1000 name == "gathered" || name == "aligned") {
1001 cell->push_back(createMathInset(name));
1002 parse2(cell->back(), FLAG_END, mode, false);
1005 else if (name == "math") {
1006 cell->push_back(MathAtom(new MathHullInset("simple")));
1007 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
1010 else if (name == "equation" || name == "equation*"
1011 || name == "displaymath") {
1012 cell->push_back(MathAtom(new MathHullInset("equation")));
1013 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
1016 else if (name == "eqnarray" || name == "eqnarray*") {
1017 cell->push_back(MathAtom(new MathHullInset("eqnarray")));
1018 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1021 else if (name == "align" || name == "align*") {
1022 cell->push_back(MathAtom(new MathHullInset("align")));
1023 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1026 else if (name == "flalign" || name == "flalign*") {
1027 cell->push_back(MathAtom(new MathHullInset("flalign")));
1028 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1031 else if (name == "alignat" || name == "alignat*") {
1032 // ignore this for a while
1034 cell->push_back(MathAtom(new MathHullInset("alignat")));
1035 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1038 else if (name == "xalignat" || name == "xalignat*") {
1039 // ignore this for a while
1041 cell->push_back(MathAtom(new MathHullInset("xalignat")));
1042 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1045 else if (name == "xxalignat") {
1046 // ignore this for a while
1048 cell->push_back(MathAtom(new MathHullInset("xxalignat")));
1049 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1052 else if (name == "multline" || name == "multline*") {
1053 cell->push_back(MathAtom(new MathHullInset("multline")));
1054 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1057 else if (name == "gather" || name == "gather*") {
1058 cell->push_back(MathAtom(new MathHullInset("gather")));
1059 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1062 else if (latexkeys const * l = in_word_set(name)) {
1063 if (l->inset == "matrix") {
1064 cell->push_back(createMathInset(name));
1065 parse2(cell->back(), FLAG_END, mode, false);
1070 // lyxerr << "unknow math inset begin '" << name << "'\n";
1071 // create generic environment inset
1072 cell->push_back(MathAtom(new MathEnvInset(name)));
1073 parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
1077 else if (t.cs() == "kern") {
1078 #ifdef WITH_WARNINGS
1083 Token const & t = getToken();
1089 if (isValidLength(s))
1092 cell->push_back(MathAtom(new MathKernInset(s)));
1095 else if (t.cs() == "label") {
1096 string label = parse_verbatim_item();
1097 if (grid.asHullInset()) {
1098 grid.asHullInset()->label(cellrow, label);
1100 cell->push_back(createMathInset(t.cs()));
1101 cell->push_back(MathAtom(new MathBraceInset(asArray(label))));
1105 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1106 MathAtom at = createMathInset(t.cs());
1107 at.nucleus()->cell(0) = *cell;
1109 parse(at.nucleus()->cell(1), flags, mode);
1110 cell->push_back(at);
1114 else if (t.cs() == "substack") {
1115 cell->push_back(createMathInset(t.cs()));
1116 parse2(cell->back(), FLAG_ITEM, mode, false);
1119 else if (t.cs() == "xymatrix") {
1120 cell->push_back(createMathInset(t.cs()));
1121 parse2(cell->back(), FLAG_ITEM, mode, false);
1124 else if (t.cs() == "framebox") {
1125 cell->push_back(createMathInset(t.cs()));
1126 parse(cell->back().nucleus()->cell(0), FLAG_OPTION, mode);
1127 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
1131 else if (t.cs() == "infer") {
1133 parse(ar, FLAG_OPTION, mode);
1134 cell->push_back(createMathInset(t.cs()));
1135 parse2(cell->back(), FLAG_ITEM, mode, false);
1139 else if (1 && t.cs() == "ar") {
1140 MathXYArrowInset * p = new MathXYArrowInset;
1141 // try to read target
1142 parse(p->cell(0), FLAG_OTPTION, mode);
1143 // try to read label
1144 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1145 p->up_ = nextToken().cat() == catSuper;
1147 parse(p->cell(1), FLAG_ITEM, mode);
1148 //lyxerr << "read label: " << p->cell(1) << "\n";
1151 cell->push_back(MathAtom(p));
1152 //lyxerr << "read cell: " << cell << "\n";
1156 else if (t.cs().size()) {
1157 latexkeys const * l = in_word_set(t.cs());
1159 if (l->inset == "font") {
1160 cell->push_back(createMathInset(t.cs()));
1161 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(mode, l->extra));
1164 else if (l->inset == "oldfont") {
1165 cell->push_back(createMathInset(t.cs()));
1166 parse(cell->back().nucleus()->cell(0), flags, asMode(mode, l->extra));
1170 else if (l->inset == "style") {
1171 cell->push_back(createMathInset(t.cs()));
1172 parse(cell->back().nucleus()->cell(0), flags, mode);
1176 else if (l->inset == "parbox") {
1177 // read optional positioning and width
1178 string pos = parse_verbatim_option();
1179 string width = parse_verbatim_item();
1180 cell->push_back(createMathInset(t.cs()));
1181 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
1182 cell->back().nucleus()->asParboxInset()->setPosition(pos);
1183 cell->back().nucleus()->asParboxInset()->setWidth(width);
1187 MathAtom at = createMathInset(t.cs());
1188 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1189 parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(mode, l->extra));
1190 cell->push_back(at);
1195 MathAtom at = createMathInset(t.cs());
1196 MathInset::mode_type m = mode;
1197 if (m == MathInset::UNDECIDED_MODE)
1198 m = at->currentMode();
1199 MathInset::idx_type start = 0;
1200 // this fails on \bigg[...\bigg]
1202 //parse(opt, FLAG_OPTION, MathInset::VERBATIM_MODE);
1205 // at.nucleus()->cell(0) = opt;
1207 for (MathInset::idx_type i = start; i < at->nargs(); ++i)
1208 parse(at.nucleus()->cell(i), FLAG_ITEM, m);
1209 cell->push_back(at);
1214 if (flags & FLAG_LEAVE) {
1215 flags &= ~FLAG_LEAVE;
1223 } // anonymous namespace
1226 void mathed_parse_cell(MathArray & ar, string const & str)
1228 istringstream is(str.c_str());
1229 mathed_parse_cell(ar, is);
1233 void mathed_parse_cell(MathArray & ar, istream & is)
1235 Parser(is).parse(ar, 0, MathInset::MATH_MODE);
1239 bool mathed_parse_normal(MathAtom & t, string const & str)
1241 istringstream is(str.c_str());
1242 return Parser(is).parse(t);
1246 bool mathed_parse_normal(MathAtom & t, istream & is)
1248 return Parser(is).parse(t);
1252 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1254 return Parser(lex).parse(t);
1258 void mathed_parse_normal(MathGridInset & grid, string const & str)
1260 istringstream is(str.c_str());
1261 Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);