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 #pragma implementation
39 #include "math_parser.h"
40 #include "math_inset.h"
41 #include "math_arrayinset.h"
42 #include "math_braceinset.h"
43 #include "math_boxinset.h"
44 #include "math_charinset.h"
45 #include "math_commentinset.h"
46 #include "math_deliminset.h"
47 #include "math_envinset.h"
48 #include "math_extern.h"
49 #include "math_factory.h"
50 #include "math_kerninset.h"
51 #include "math_macro.h"
52 #include "math_macrotemplate.h"
53 #include "math_hullinset.h"
54 #include "math_parboxinset.h"
55 #include "math_parinset.h"
56 #include "math_rootinset.h"
57 #include "math_scriptinset.h"
58 #include "math_sizeinset.h"
59 #include "math_sqrtinset.h"
60 #include "math_stringinset.h"
61 #include "math_support.h"
62 #include "math_xyarrowinset.h"
64 //#include "insets/insetref.h"
65 #include "ref_inset.h"
69 #include "support/LAssert.h"
70 #include "support/lstrings.h"
89 MathInset::mode_type asMode(string const & str)
91 if (str == "mathmode")
92 return MathInset::MATH_MODE;
93 if (str == "textmode" || str == "forcetext")
94 return MathInset::TEXT_MODE;
95 if (str == "verbatimmode")
96 return MathInset::VERBATIM_MODE;
97 return MathInset::UNDECIDED_MODE;
101 bool stared(string const & s)
103 string::size_type const n = s.size();
104 return n && s[n - 1] == '*';
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
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_LAST = 1 << 4, // next closing bracket ends the parsing
142 FLAG_TEXTMODE = 1 << 5, // we are in a box
143 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
144 FLAG_LEAVE = 1 << 7, // leave the loop at the end
145 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
146 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
147 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
148 FLAG_OPTION = 1 << 11, // read [...] style option
149 FLAG_BRACED = 1 << 12 // read {...} style argument
155 fill(theCatcode, theCatcode + 256, catOther);
156 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
157 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
159 theCatcode['\\'] = catEscape;
160 theCatcode['{'] = catBegin;
161 theCatcode['}'] = catEnd;
162 theCatcode['$'] = catMath;
163 theCatcode['&'] = catAlign;
164 theCatcode['\n'] = catNewline;
165 theCatcode['#'] = catParameter;
166 theCatcode['^'] = catSuper;
167 theCatcode['_'] = catSub;
168 theCatcode['
\7f'] = catIgnore;
169 theCatcode[' '] = catSpace;
170 theCatcode['\t'] = catSpace;
171 theCatcode['\r'] = catNewline;
172 theCatcode['~'] = catActive;
173 theCatcode['%'] = catComment;
179 // Helper class for parsing
185 Token() : cs_(), char_(0), cat_(catIgnore) {}
187 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
189 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
192 string const & cs() const { return cs_; }
194 CatCode cat() const { return cat_; }
196 char character() const { return char_; }
198 string asString() const { return cs_.size() ? cs_ : string(1, char_); }
209 ostream & operator<<(ostream & os, Token const & t)
212 os << "\\" << t.cs();
214 os << "[" << t.character() << "," << t.cat() << "]";
223 typedef MathInset::mode_type mode_type;
226 Parser(LyXLex & lex);
228 Parser(istream & is);
231 bool parse(MathAtom & at);
233 void parse(MathArray & array, unsigned flags, mode_type mode);
235 void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
238 MathArray parse(unsigned flags, mode_type mode);
240 int lineno() const { return lineno_; }
246 void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
247 /// get arg delimited by 'left' and 'right'
248 string getArg(char left, char right);
252 void error(string const & msg);
253 /// dump contents to screen
256 void tokenize(istream & is);
258 void tokenize(string const & s);
260 void skipSpaceTokens(istream & is, char c);
262 void push_back(Token const & t);
266 Token const & prevToken() const;
268 Token const & nextToken() const;
270 Token const & getToken();
271 /// skips spaces if any
274 void lex(string const & s);
281 vector<Token> tokens_;
287 Parser::Parser(LyXLex & lexer)
288 : lineno_(lexer.getLineNo()), pos_(0)
290 tokenize(lexer.getStream());
295 Parser::Parser(istream & is)
296 : lineno_(0), pos_(0)
302 void Parser::push_back(Token const & t)
304 tokens_.push_back(t);
308 void Parser::pop_back()
314 Token const & Parser::prevToken() const
316 static const Token dummy;
317 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
321 Token const & Parser::nextToken() const
323 static const Token dummy;
324 return good() ? tokens_[pos_] : dummy;
328 Token const & Parser::getToken()
330 static const Token dummy;
331 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
332 return good() ? tokens_[pos_++] : dummy;
336 void Parser::skipSpaces()
338 while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
343 void Parser::putback()
349 bool Parser::good() const
351 return pos_ < tokens_.size();
355 char Parser::getChar()
358 error("The input stream is not well...");
359 return tokens_[pos_++].character();
363 string Parser::getArg(char left, char right)
373 while ((c = getChar()) != right && good())
380 void Parser::skipSpaceTokens(istream & is, char c)
382 // skip trailing spaces
383 while (catcode(c) == catSpace || catcode(c) == catNewline)
386 //lyxerr << "putting back: " << c << "\n";
391 void Parser::tokenize(istream & is)
393 // eat everything up to the next \end_inset or end of stream
394 // and store it in s for further tokenization
399 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
400 s = s.substr(0, s.size() - 10);
410 void Parser::tokenize(string const & buffer)
412 static bool init_done = false;
419 istringstream is(buffer.c_str(), ios::in | ios::binary);
423 //lyxerr << "reading c: " << c << "\n";
425 switch (catcode(c)) {
429 if (catcode(c) == catNewline)
430 ; //push_back(Token("par"));
432 push_back(Token('\n', catNewline));
440 while (is.get(c) && catcode(c) != catNewline)
450 error("unexpected end of input");
453 if (catcode(c) == catLetter) {
455 while (is.get(c) && catcode(c) == catLetter)
457 skipSpaceTokens(is, c);
466 push_back(Token(c, catcode(c)));
468 skipSpaceTokens(is, c);
473 lyxerr << "ignoring a char: " << int(c) << "\n";
478 push_back(Token(c, catcode(c)));
488 void Parser::dump() const
490 lyxerr << "\nTokens: ";
491 for (unsigned i = 0; i < tokens_.size(); ++i) {
494 lyxerr << tokens_[i];
496 lyxerr << " pos: " << pos_ << "\n";
500 void Parser::error(string const & msg)
502 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
508 bool Parser::parse(MathAtom & at)
512 parse(ar, false, MathInset::UNDECIDED_MODE);
513 if (ar.size() != 1 || ar.front()->getType() == "none") {
514 lyxerr << "unusual contents found: " << ar << endl;
515 at = MathAtom(new MathParInset(ar));
516 //if (at->nargs() > 0)
517 // at.nucleus()->cell(0) = ar;
519 // lyxerr << "unusual contents found: " << ar << endl;
527 MathArray Parser::parse(unsigned flags, mode_type mode)
530 parse(ar, flags, mode);
535 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
537 MathGridInset grid(1, 1);
538 parse1(grid, flags, mode, false);
539 array = grid.cell(0);
543 void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
546 parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
550 void Parser::parse1(MathGridInset & grid, unsigned flags,
551 mode_type mode, bool numbered)
554 MathGridInset::row_type cellrow = 0;
555 MathGridInset::col_type cellcol = 0;
556 MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
558 if (grid.asHullInset())
559 grid.asHullInset()->numbered(cellrow, numbered);
562 //lyxerr << "grid: " << grid << endl;
565 Token const & t = getToken();
568 lyxerr << "t: " << t << " flags: " << flags << "\n";
573 if (flags & FLAG_ITEM) {
574 if (t.cat() == catSpace)
578 if (t.cat() == catBegin) {
579 // skip the brace and collect everything to the next matching
581 flags |= FLAG_BRACE_LAST;
585 // handle only this single token, leave the loop if done
590 if (flags & FLAG_BRACED) {
591 if (t.cat() == catSpace)
594 if (t.cat() != catBegin) {
595 error("opening brace expected");
599 // skip the brace and collect everything to the next matching
601 flags = FLAG_BRACE_LAST;
605 if (flags & FLAG_OPTION) {
606 if (t.cat() == catOther && t.character() == '[') {
608 parse(ar, FLAG_BRACK_LAST, mode);
611 // no option found, put back token and we are done
620 if (t.cat() == catMath) {
621 if (mode != MathInset::MATH_MODE) {
622 // we are inside some text mode thingy, so opening new math is allowed
623 Token const & n = getToken();
624 if (n.cat() == catMath) {
625 // TeX's $$...$$ syntax for displayed math
626 cell->push_back(MathAtom(new MathHullInset("equation")));
627 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
628 getToken(); // skip the second '$' token
630 // simple $...$ stuff
632 cell->push_back(MathAtom(new MathHullInset("simple")));
633 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
637 else if (flags & FLAG_SIMPLE) {
638 // this is the end of the formula
643 error("something strange in the parser\n");
648 else if (t.cat() == catLetter)
649 cell->push_back(MathAtom(new MathCharInset(t.character())));
651 else if (t.cat() == catSpace && mode != MathInset::MATH_MODE) {
652 if (cell->empty() || cell->back()->getChar() != ' ')
653 cell->push_back(MathAtom(new MathCharInset(t.character())));
656 else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
657 cell->push_back(MathAtom(new MathCharInset(t.character())));
659 else if (t.cat() == catParameter) {
660 Token const & n = getToken();
661 cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
664 else if (t.cat() == catActive)
665 cell->push_back(MathAtom(new MathCharInset(t.character())));
667 else if (t.cat() == catBegin) {
669 parse(ar, FLAG_BRACE_LAST, mode);
670 // do not create a BraceInset if they were written by LyX
671 // this helps to keep the annoyance of "a choose b" to a minimum
672 if (ar.size() == 1 && ar[0]->extraBraces())
675 cell->push_back(MathAtom(new MathBraceInset(ar)));
678 else if (t.cat() == catEnd) {
679 if (flags & FLAG_BRACE_LAST)
681 error("found '}' unexpectedly");
683 //add(cell, '}', LM_TC_TEX);
686 else if (t.cat() == catAlign) {
688 //lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
689 if (cellcol == grid.ncols()) {
690 lyxerr << "adding column " << cellcol << "\n";
691 grid.addCol(cellcol - 1);
693 cell = &grid.cell(grid.index(cellrow, cellcol));
696 else if (t.cat() == catSuper || t.cat() == catSub) {
697 if (mode == MathInset::VERBATIM_MODE)
698 cell->push_back(MathAtom(new MathStringInset(t.asString())));
700 bool up = (t.cat() == catSuper);
701 // we need no new script inset if the last thing was a scriptinset,
702 // which has that script already not the same script already
704 cell->push_back(MathAtom(new MathScriptInset(up)));
705 else if (cell->back()->asScriptInset() &&
706 !cell->back()->asScriptInset()->has(up))
707 cell->back().nucleus()->asScriptInset()->ensure(up);
708 else if (cell->back()->asScriptInset())
709 cell->push_back(MathAtom(new MathScriptInset(up)));
711 cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
712 MathScriptInset * p = cell->back().nucleus()->asScriptInset();
713 parse(p->cell(up), FLAG_ITEM, mode);
716 // special handling of {}-bases
717 // is this always correct?
718 if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
719 p->nuc().back()->extraBraces())
720 p->nuc() = p->nuc().back()->asNestInset()->cell(0);
724 else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
725 lyxerr << "finished reading option\n";
729 else if (t.cat() == catOther)
730 cell->push_back(MathAtom(new MathCharInset(t.character())));
732 else if (t.cat() == catComment) {
735 Token const & t = getToken();
736 if (t.cat() == catNewline)
740 cell->push_back(MathAtom(new MathCommentInset(s)));
748 else if (t.cs() == "lyxlock") {
750 cell->back().nucleus()->lock(true);
753 else if (t.cs() == "def" || t.cs() == "newcommand") {
756 if (t.cs() == "def") {
758 name = getToken().cs();
762 while (good() && nextToken().cat() != catBegin) {
763 pars += getToken().cs();
767 //lyxerr << "read \\def parameter list '" << pars << "'\n";
769 } else { // t.cs() == "newcommand"
771 if (getToken().cat() != catBegin) {
772 error("'{' in \\newcommand expected (1) \n");
776 name = getToken().cs();
778 if (getToken().cat() != catEnd) {
779 error("'}' in \\newcommand expected\n");
783 string arg = getArg('[', ']');
785 nargs = atoi(arg.c_str());
790 parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
792 // we cannot handle recursive stuff at all
794 //test.push_back(createMathInset(name));
795 //if (ar1.contains(test)) {
796 // error("we cannot handle recursive macros at all.\n");
800 // is a version for display attached?
803 if (nextToken().cat() == catBegin) {
804 parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
807 cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
810 else if (t.cs() == "(") {
811 cell->push_back(MathAtom(new MathHullInset("simple")));
812 parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
815 else if (t.cs() == "[") {
816 cell->push_back(MathAtom(new MathHullInset("equation")));
817 parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
820 else if (t.cs() == "protect")
821 // ignore \\protect, will hopefully be re-added during output
824 else if (t.cs() == "end") {
825 if (flags & FLAG_END) {
826 // eat environment name
827 //string const name =
829 // FIXME: check that we ended the correct environment
832 error("found 'end' unexpectedly");
835 else if (t.cs() == ")") {
836 if (flags & FLAG_SIMPLE2)
838 error("found '\\)' unexpectedly");
841 else if (t.cs() == "]") {
842 if (flags & FLAG_EQUATION)
844 error("found '\\]' unexpectedly");
847 else if (t.cs() == "\\") {
848 grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
851 if (cellrow == grid.nrows())
852 grid.addRow(cellrow - 1);
853 if (grid.asHullInset())
854 grid.asHullInset()->numbered(cellrow, numbered);
855 cell = &grid.cell(grid.index(cellrow, cellcol));
859 else if (t.cs() == "multicolumn") {
860 // extract column count and insert dummy cells
862 parse(count, FLAG_ITEM, mode);
864 if (!extractNumber(count, cols)) {
865 lyxerr << " can't extract number of cells from " << count << "\n";
867 // resize the table if necessary
868 for (int i = 0; i < cols; ++i) {
870 if (cellcol == grid.ncols()) {
871 lyxerr << "adding column " << cellcol << "\n";
872 grid.addCol(cellcol - 1);
874 cell = &grid.cell(grid.index(cellrow, cellcol));
875 // mark this as dummy
876 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
878 // the last cell is the real thng, not a dummy
879 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
881 // read special alignment
883 parse(align, FLAG_ITEM, mode);
884 //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
886 // parse the remaining contents into the "real" cell
887 parse(*cell, FLAG_ITEM, mode);
891 else if (t.cs() == "limits")
894 else if (t.cs() == "nolimits")
897 else if (t.cs() == "nonumber") {
898 if (grid.asHullInset())
899 grid.asHullInset()->numbered(cellrow, false);
902 else if (t.cs() == "number") {
903 if (grid.asHullInset())
904 grid.asHullInset()->numbered(cellrow, true);
907 else if (t.cs() == "hline") {
908 if (grid.asHullInset())
909 grid.asHullInset()->rowinfo(cellrow + 1);
912 else if (t.cs() == "sqrt") {
914 parse(ar, FLAG_OPTION, mode);
916 cell->push_back(MathAtom(new MathRootInset));
917 cell->back().nucleus()->cell(0) = ar;
918 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
920 cell->push_back(MathAtom(new MathSqrtInset));
921 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
925 else if (t.cs() == "ref") {
926 cell->push_back(MathAtom(new RefInset));
927 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
928 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
931 else if (t.cs() == "left") {
932 string l = getToken().asString();
934 parse(ar, FLAG_RIGHT, mode);
935 string r = getToken().asString();
936 cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
939 else if (t.cs() == "right") {
940 if (flags & FLAG_RIGHT)
942 //lyxerr << "got so far: '" << cell << "'\n";
943 error("Unmatched right delimiter");
947 else if (t.cs() == "begin") {
948 string const name = getArg('{', '}');
950 if (name == "array" || name == "subarray") {
951 string const valign =
952 asString(parse(FLAG_OPTION, MathInset::VERBATIM_MODE)) + 'c';
953 string const halign =
954 asString(parse(FLAG_ITEM, MathInset::VERBATIM_MODE));
955 cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
956 parse2(cell->back(), FLAG_END, mode, false);
959 else if (name == "split" || name == "cases" ||
960 name == "gathered" || name == "aligned") {
961 cell->push_back(createMathInset(name));
962 parse2(cell->back(), FLAG_END, mode, false);
965 else if (name == "math") {
966 cell->push_back(MathAtom(new MathHullInset("simple")));
967 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
970 else if (name == "equation" || name == "equation*"
971 || name == "displaymath") {
972 cell->push_back(MathAtom(new MathHullInset("equation")));
973 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
976 else if (name == "eqnarray" || name == "eqnarray*") {
977 cell->push_back(MathAtom(new MathHullInset("eqnarray")));
978 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
981 else if (name == "align" || name == "align*") {
982 cell->push_back(MathAtom(new MathHullInset("align")));
983 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
986 else if (name == "alignat" || name == "alignat*") {
987 // ignore this for a while
989 cell->push_back(MathAtom(new MathHullInset("alignat")));
990 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
993 else if (name == "xalignat" || name == "xalignat*") {
994 // ignore this for a while
996 cell->push_back(MathAtom(new MathHullInset("xalignat")));
997 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1000 else if (name == "xxalignat") {
1001 // ignore this for a while
1003 cell->push_back(MathAtom(new MathHullInset("xxalignat")));
1004 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1007 else if (name == "multline" || name == "multline*") {
1008 cell->push_back(MathAtom(new MathHullInset("multline")));
1009 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1012 else if (name == "gather" || name == "gather*") {
1013 cell->push_back(MathAtom(new MathHullInset("gather")));
1014 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1017 else if (latexkeys const * l = in_word_set(name)) {
1018 if (l->inset == "matrix") {
1019 cell->push_back(createMathInset(name));
1020 parse2(cell->back(), FLAG_END, mode, false);
1025 // lyxerr << "unknow math inset begin '" << name << "'\n";
1026 // create generic environment inset
1027 cell->push_back(MathAtom(new MathEnvInset(name)));
1028 parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
1032 else if (t.cs() == "kern") {
1033 #ifdef WITH_WARNINGS
1038 Token const & t = getToken();
1044 if (isValidLength(s))
1047 cell->push_back(MathAtom(new MathKernInset(s)));
1050 else if (t.cs() == "label") {
1051 MathArray ar = parse(FLAG_ITEM, MathInset::VERBATIM_MODE);
1052 if (grid.asHullInset()) {
1053 grid.asHullInset()->label(cellrow, asString(ar));
1055 cell->push_back(createMathInset(t.cs()));
1056 cell->push_back(MathAtom(new MathBraceInset(ar)));
1060 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1061 MathAtom at = createMathInset(t.cs());
1062 at.nucleus()->cell(0) = *cell;
1064 parse(at.nucleus()->cell(1), flags, mode);
1065 cell->push_back(at);
1069 else if (t.cs() == "substack") {
1070 cell->push_back(createMathInset(t.cs()));
1071 parse2(cell->back(), FLAG_ITEM, mode, false);
1074 else if (t.cs() == "xymatrix") {
1075 cell->push_back(createMathInset(t.cs()));
1076 parse2(cell->back(), FLAG_ITEM, mode, false);
1081 else if (1 && t.cs() == "ar") {
1082 MathXYArrowInset * p = new MathXYArrowInset;
1083 // try to read target
1084 parse(p->cell(0), FLAG_OTPTION, mode);
1085 // try to read label
1086 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1087 p->up_ = nextToken().cat() == catSuper;
1089 parse(p->cell(1), FLAG_ITEM, mode);
1090 //lyxerr << "read label: " << p->cell(1) << "\n";
1093 cell->push_back(MathAtom(p));
1094 //lyxerr << "read cell: " << cell << "\n";
1098 else if (t.cs().size()) {
1099 latexkeys const * l = in_word_set(t.cs());
1101 if (l->inset == "font") {
1102 cell->push_back(createMathInset(t.cs()));
1103 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
1106 else if (l->inset == "oldfont") {
1107 cell->push_back(createMathInset(t.cs()));
1108 parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
1112 else if (l->inset == "style") {
1113 cell->push_back(createMathInset(t.cs()));
1114 parse(cell->back().nucleus()->cell(0), flags, mode);
1118 else if (l->inset == "parbox") {
1119 // read optional positioning and width
1120 MathArray pos, width;
1121 parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
1123 parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
1124 cell->push_back(createMathInset(t.cs()));
1125 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
1126 cell->back().nucleus()->asParboxInset()->setPosition(asString(pos));
1127 cell->back().nucleus()->asParboxInset()->setWidth(asString(width));
1131 MathAtom at = createMathInset(t.cs());
1132 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1133 parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
1134 cell->push_back(at);
1139 MathAtom at = createMathInset(t.cs());
1140 MathInset::mode_type m = mode;
1141 if (m == MathInset::UNDECIDED_MODE)
1142 m = at->currentMode();
1143 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1144 parse(at.nucleus()->cell(i), FLAG_ITEM, m);
1145 cell->push_back(at);
1150 if (flags & FLAG_LEAVE) {
1151 flags &= ~FLAG_LEAVE;
1159 } // anonymous namespace
1162 void mathed_parse_cell(MathArray & ar, string const & str)
1164 istringstream is(str.c_str());
1165 mathed_parse_cell(ar, is);
1169 void mathed_parse_cell(MathArray & ar, istream & is)
1171 Parser(is).parse(ar, 0, MathInset::MATH_MODE);
1175 bool mathed_parse_normal(MathAtom & t, string const & str)
1177 istringstream is(str.c_str());
1178 return Parser(is).parse(t);
1182 bool mathed_parse_normal(MathAtom & t, istream & is)
1184 return Parser(is).parse(t);
1188 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1190 return Parser(lex).parse(t);
1194 void mathed_parse_normal(MathGridInset & grid, string const & str)
1196 istringstream is(str.c_str());
1197 Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);