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_deliminset.h"
46 #include "math_envinset.h"
47 #include "math_extern.h"
48 #include "math_factory.h"
49 #include "math_kerninset.h"
50 #include "math_macro.h"
51 #include "math_macrotemplate.h"
52 #include "math_hullinset.h"
53 #include "math_parboxinset.h"
54 #include "math_parinset.h"
55 #include "math_rootinset.h"
56 #include "math_scriptinset.h"
57 #include "math_sizeinset.h"
58 #include "math_sqrtinset.h"
59 #include "math_stringinset.h"
60 #include "math_support.h"
61 #include "math_xyarrowinset.h"
63 //#include "insets/insetref.h"
64 #include "ref_inset.h"
68 #include "support/LAssert.h"
69 #include "support/lstrings.h"
88 MathInset::mode_type asMode(string const & str)
90 if (str == "mathmode")
91 return MathInset::MATH_MODE;
92 if (str == "textmode" || str == "forcetext")
93 return MathInset::TEXT_MODE;
94 if (str == "verbatimmode")
95 return MathInset::VERBATIM_MODE;
96 return MathInset::UNDECIDED_MODE;
100 bool stared(string const & s)
102 string::size_type const n = s.size();
103 return n && s[n - 1] == '*';
107 // These are TeX's catcodes
109 catEscape, // 0 backslash
119 catSpace, // 10 space
120 catLetter, // 11 a-zA-Z
121 catOther, // 12 none of the above
124 catInvalid // 15 <delete>
127 CatCode theCatcode[256];
130 inline CatCode catcode(unsigned char c)
132 return theCatcode[c];
137 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
138 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
139 FLAG_END = 1 << 3, // next \\end ends the parsing process
140 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
141 FLAG_TEXTMODE = 1 << 5, // we are in a box
142 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
143 FLAG_LEAVE = 1 << 7, // leave the loop at the end
144 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
145 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
146 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
147 FLAG_OPTION = 1 << 11, // read [...] style option
148 FLAG_BRACED = 1 << 12 // read {...} style argument
154 fill(theCatcode, theCatcode + 256, catOther);
155 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
156 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
158 theCatcode['\\'] = catEscape;
159 theCatcode['{'] = catBegin;
160 theCatcode['}'] = catEnd;
161 theCatcode['$'] = catMath;
162 theCatcode['&'] = catAlign;
163 theCatcode['\n'] = catNewline;
164 theCatcode['#'] = catParameter;
165 theCatcode['^'] = catSuper;
166 theCatcode['_'] = catSub;
167 theCatcode['
\7f'] = catIgnore;
168 theCatcode[' '] = catSpace;
169 theCatcode['\t'] = catSpace;
170 theCatcode['\r'] = catNewline;
171 theCatcode['~'] = catActive;
172 theCatcode['%'] = catComment;
178 // Helper class for parsing
184 Token() : cs_(), char_(0), cat_(catIgnore) {}
186 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
188 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
191 string const & cs() const { return cs_; }
193 CatCode cat() const { return cat_; }
195 char character() const { return char_; }
197 string asString() const { return cs_.size() ? cs_ : string(1, char_); }
208 ostream & operator<<(ostream & os, Token const & t)
211 os << "\\" << t.cs();
213 os << "[" << t.character() << "," << t.cat() << "]";
222 typedef MathInset::mode_type mode_type;
225 Parser(LyXLex & lex);
227 Parser(istream & is);
230 bool parse(MathAtom & at);
232 void parse(MathArray & array, unsigned flags, mode_type mode);
234 MathArray parse(unsigned flags, mode_type mode);
236 int lineno() const { return lineno_; }
242 void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
245 void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
246 /// get arg delimited by 'left' and 'right'
247 string getArg(char left, char right);
251 void error(string const & msg);
252 /// dump contents to screen
255 void tokenize(istream & is);
257 void tokenize(string const & s);
259 void skipSpaceTokens(istream & is, char c);
261 void push_back(Token const & t);
265 Token const & prevToken() const;
267 Token const & nextToken() const;
269 Token const & getToken();
270 /// skips spaces if any
273 void lex(string const & s);
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);
409 void Parser::tokenize(string const & buffer)
411 static bool init_done = false;
418 istringstream is(buffer.c_str(), ios::in | ios::binary);
422 //lyxerr << "reading c: " << c << "\n";
424 switch (catcode(c)) {
428 if (catcode(c) == catNewline)
429 ; //push_back(Token("par"));
431 push_back(Token('\n', catNewline));
438 while (is.get(c) && catcode(c) != catNewline)
447 error("unexpected end of input");
450 if (catcode(c) == catLetter) {
452 while (is.get(c) && catcode(c) == catLetter)
454 skipSpaceTokens(is, c);
463 push_back(Token(c, catcode(c)));
465 skipSpaceTokens(is, c);
470 lyxerr << "ignoring a char: " << int(c) << "\n";
475 push_back(Token(c, catcode(c)));
485 void Parser::dump() const
487 lyxerr << "\nTokens: ";
488 for (unsigned i = 0; i < tokens_.size(); ++i) {
491 lyxerr << tokens_[i];
493 lyxerr << " pos: " << pos_ << "\n";
497 void Parser::error(string const & msg)
499 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
505 bool Parser::parse(MathAtom & at)
509 parse(ar, false, MathInset::UNDECIDED_MODE);
510 if (ar.size() != 1 || ar.front()->getType() == "none") {
511 lyxerr << "unusual contents found: " << ar << endl;
512 at = MathAtom(new MathParInset);
514 at.nucleus()->cell(0) = ar;
516 lyxerr << "unusual contents found: " << ar << endl;
524 MathArray Parser::parse(unsigned flags, mode_type mode)
527 parse(ar, flags, mode);
532 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
534 MathGridInset grid(1, 1);
535 parse1(grid, flags, mode, false);
536 array = grid.cell(0);
540 void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
543 parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
547 void Parser::parse1(MathGridInset & grid, unsigned flags,
548 mode_type mode, bool numbered)
551 MathGridInset::row_type cellrow = 0;
552 MathGridInset::col_type cellcol = 0;
553 MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
555 if (grid.asHullInset())
556 grid.asHullInset()->numbered(cellrow, numbered);
559 //lyxerr << "grid: " << grid << endl;
562 Token const & t = getToken();
565 lyxerr << "t: " << t << " flags: " << flags << "\n";
570 if (flags & FLAG_ITEM) {
571 if (t.cat() == catSpace)
575 if (t.cat() == catBegin) {
576 // skip the brace and collect everything to the next matching
578 flags |= FLAG_BRACE_LAST;
582 // handle only this single token, leave the loop if done
587 if (flags & FLAG_BRACED) {
588 if (t.cat() == catSpace)
591 if (t.cat() != catBegin) {
592 error("opening brace expected");
596 // skip the brace and collect everything to the next matching
598 flags = FLAG_BRACE_LAST;
602 if (flags & FLAG_OPTION) {
603 if (t.cat() == catOther && t.character() == '[') {
605 parse(ar, FLAG_BRACK_LAST, mode);
608 // no option found, put back token and we are done
617 if (t.cat() == catMath) {
618 if (mode != MathInset::MATH_MODE) {
619 // we are inside some text mode thingy, so opening new math is allowed
620 Token const & n = getToken();
621 if (n.cat() == catMath) {
622 // TeX's $$...$$ syntax for displayed math
623 cell->push_back(MathAtom(new MathHullInset("equation")));
624 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
625 getToken(); // skip the second '$' token
627 // simple $...$ stuff
629 cell->push_back(MathAtom(new MathHullInset("simple")));
630 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
634 else if (flags & FLAG_SIMPLE) {
635 // this is the end of the formula
640 error("something strange in the parser\n");
645 else if (t.cat() == catLetter)
646 cell->push_back(MathAtom(new MathCharInset(t.character())));
648 else if (t.cat() == catSpace && mode != MathInset::MATH_MODE)
649 cell->push_back(MathAtom(new MathCharInset(t.character())));
651 else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
652 cell->push_back(MathAtom(new MathCharInset(t.character())));
654 else if (t.cat() == catParameter) {
655 Token const & n = getToken();
656 cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
659 else if (t.cat() == catActive)
660 cell->push_back(MathAtom(new MathCharInset(t.character())));
662 else if (t.cat() == catBegin) {
664 parse(ar, FLAG_BRACE_LAST, mode);
665 // do not create a BraceInset if they were written by LyX
666 // this helps to keep the annoyance of "a choose b" to a minimum
667 if (ar.size() == 1 && ar[0]->extraBraces())
670 cell->push_back(MathAtom(new MathBraceInset(ar)));
673 else if (t.cat() == catEnd) {
674 if (flags & FLAG_BRACE_LAST)
676 error("found '}' unexpectedly");
678 //add(cell, '}', LM_TC_TEX);
681 else if (t.cat() == catAlign) {
683 //lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
684 if (cellcol == grid.ncols()) {
685 lyxerr << "adding column " << cellcol << "\n";
686 grid.addCol(cellcol - 1);
688 cell = &grid.cell(grid.index(cellrow, cellcol));
691 else if (t.cat() == catSuper || t.cat() == catSub) {
692 if (mode == MathInset::VERBATIM_MODE)
693 cell->push_back(MathAtom(new MathStringInset(t.asString())));
695 bool up = (t.cat() == catSuper);
696 // we need no new script inset if the last thing was a scriptinset,
697 // which has that script already not the same script already
699 cell->push_back(MathAtom(new MathScriptInset(up)));
700 else if (cell->back()->asScriptInset() &&
701 !cell->back()->asScriptInset()->has(up))
702 cell->back().nucleus()->asScriptInset()->ensure(up);
703 else if (cell->back()->asScriptInset())
704 cell->push_back(MathAtom(new MathScriptInset(up)));
706 cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
707 MathScriptInset * p = cell->back().nucleus()->asScriptInset();
708 parse(p->cell(up), FLAG_ITEM, mode);
711 // special handling of {}-bases
712 // is this always correct?
713 if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
714 p->nuc().back()->extraBraces())
715 p->nuc() = p->nuc().back()->asNestInset()->cell(0);
719 else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
720 lyxerr << "finished reading option\n";
724 else if (t.cat() == catOther)
725 cell->push_back(MathAtom(new MathCharInset(t.character())));
731 else if (t.cs() == "lyxlock") {
733 cell->back().nucleus()->lock(true);
736 else if (t.cs() == "def" || t.cs() == "newcommand") {
739 if (t.cs() == "def") {
741 name = getToken().cs();
745 while (good() && nextToken().cat() != catBegin) {
746 pars += getToken().cs();
750 //lyxerr << "read \\def parameter list '" << pars << "'\n";
752 } else { // t.cs() == "newcommand"
754 if (getToken().cat() != catBegin) {
755 error("'{' in \\newcommand expected (1) \n");
759 name = getToken().cs();
761 if (getToken().cat() != catEnd) {
762 error("'}' in \\newcommand expected\n");
766 string arg = getArg('[', ']');
768 nargs = atoi(arg.c_str());
773 parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
775 // we cannot handle recursive stuff at all
777 //test.push_back(createMathInset(name));
778 //if (ar1.contains(test)) {
779 // error("we cannot handle recursive macros at all.\n");
783 // is a version for display attached?
786 if (nextToken().cat() == catBegin) {
787 parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
790 cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
793 else if (t.cs() == "(") {
794 cell->push_back(MathAtom(new MathHullInset("simple")));
795 parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
798 else if (t.cs() == "[") {
799 cell->push_back(MathAtom(new MathHullInset("equation")));
800 parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
803 else if (t.cs() == "protect")
804 // ignore \\protect, will hopefully be re-added during output
807 else if (t.cs() == "end") {
808 if (flags & FLAG_END) {
809 // eat environment name
810 //string const name =
812 // FIXME: check that we ended the correct environment
815 error("found 'end' unexpectedly");
818 else if (t.cs() == ")") {
819 if (flags & FLAG_SIMPLE2)
821 error("found '\\)' unexpectedly");
824 else if (t.cs() == "]") {
825 if (flags & FLAG_EQUATION)
827 error("found '\\]' unexpectedly");
830 else if (t.cs() == "\\") {
831 grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
834 if (cellrow == grid.nrows())
835 grid.addRow(cellrow - 1);
836 if (grid.asHullInset())
837 grid.asHullInset()->numbered(cellrow, numbered);
838 cell = &grid.cell(grid.index(cellrow, cellcol));
842 else if (t.cs() == "multicolumn") {
843 // extract column count and insert dummy cells
845 parse(count, FLAG_ITEM, mode);
847 if (!extractNumber(count, cols)) {
848 lyxerr << " can't extract number of cells from " << count << "\n";
850 // resize the table if necessary
851 for (int i = 0; i < cols; ++i) {
853 if (cellcol == grid.ncols()) {
854 lyxerr << "adding column " << cellcol << "\n";
855 grid.addCol(cellcol - 1);
857 cell = &grid.cell(grid.index(cellrow, cellcol));
858 // mark this as dummy
859 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
861 // the last cell is the real thng, not a dummy
862 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
864 // read special alignment
866 parse(align, FLAG_ITEM, mode);
867 //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
869 // parse the remaining contents into the "real" cell
870 parse(*cell, FLAG_ITEM, mode);
874 else if (t.cs() == "limits")
877 else if (t.cs() == "nolimits")
880 else if (t.cs() == "nonumber") {
881 if (grid.asHullInset())
882 grid.asHullInset()->numbered(cellrow, false);
885 else if (t.cs() == "number") {
886 if (grid.asHullInset())
887 grid.asHullInset()->numbered(cellrow, true);
890 else if (t.cs() == "hline") {
891 if (grid.asHullInset())
892 grid.asHullInset()->rowinfo(cellrow + 1);
895 else if (t.cs() == "sqrt") {
897 parse(ar, FLAG_OPTION, mode);
899 cell->push_back(MathAtom(new MathRootInset));
900 cell->back().nucleus()->cell(0) = ar;
901 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
903 cell->push_back(MathAtom(new MathSqrtInset));
904 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
908 else if (t.cs() == "ref") {
909 cell->push_back(MathAtom(new RefInset));
910 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
911 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
914 else if (t.cs() == "left") {
915 string l = getToken().asString();
917 parse(ar, FLAG_RIGHT, mode);
918 string r = getToken().asString();
919 cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
922 else if (t.cs() == "right") {
923 if (flags & FLAG_RIGHT)
925 //lyxerr << "got so far: '" << cell << "'\n";
926 error("Unmatched right delimiter");
930 else if (t.cs() == "begin") {
931 string const name = getArg('{', '}');
933 if (name == "array" || name == "subarray") {
934 string const valign =
935 asString(parse(FLAG_OPTION, MathInset::VERBATIM_MODE)) + 'c';
936 string const halign =
937 asString(parse(FLAG_ITEM, MathInset::VERBATIM_MODE));
938 cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
939 parse2(cell->back(), FLAG_END, mode, false);
942 else if (name == "split" || name == "cases" ||
943 name == "gathered" || name == "aligned") {
944 cell->push_back(createMathInset(name));
945 parse2(cell->back(), FLAG_END, mode, false);
948 else if (name == "math") {
949 cell->push_back(MathAtom(new MathHullInset("simple")));
950 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
953 else if (name == "equation" || name == "equation*"
954 || name == "displaymath") {
955 cell->push_back(MathAtom(new MathHullInset("equation")));
956 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
959 else if (name == "eqnarray" || name == "eqnarray*") {
960 cell->push_back(MathAtom(new MathHullInset("eqnarray")));
961 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
964 else if (name == "align" || name == "align*") {
965 cell->push_back(MathAtom(new MathHullInset("align")));
966 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
969 else if (name == "alignat" || name == "alignat*") {
970 // ignore this for a while
972 cell->push_back(MathAtom(new MathHullInset("alignat")));
973 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
976 else if (name == "xalignat" || name == "xalignat*") {
977 // ignore this for a while
979 cell->push_back(MathAtom(new MathHullInset("xalignat")));
980 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
983 else if (name == "xxalignat") {
984 // ignore this for a while
986 cell->push_back(MathAtom(new MathHullInset("xxalignat")));
987 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
990 else if (name == "multline" || name == "multline*") {
991 cell->push_back(MathAtom(new MathHullInset("multline")));
992 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
995 else if (name == "gather" || name == "gather*") {
996 cell->push_back(MathAtom(new MathHullInset("gather")));
997 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1000 else if (latexkeys const * l = in_word_set(name)) {
1001 if (l->inset == "matrix") {
1002 cell->push_back(createMathInset(name));
1003 parse2(cell->back(), FLAG_END, mode, false);
1008 // lyxerr << "unknow math inset begin '" << name << "'\n";
1009 // create generic environment inset
1010 cell->push_back(MathAtom(new MathEnvInset(name)));
1011 parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
1015 else if (t.cs() == "kern") {
1016 #ifdef WITH_WARNINGS
1021 Token const & t = getToken();
1027 if (isValidLength(s))
1030 cell->push_back(MathAtom(new MathKernInset(s)));
1033 else if (t.cs() == "label") {
1034 MathArray ar = parse(FLAG_ITEM, MathInset::VERBATIM_MODE);
1035 if (grid.asHullInset()) {
1036 grid.asHullInset()->label(cellrow, asString(ar));
1038 cell->push_back(createMathInset(t.cs()));
1039 cell->push_back(MathAtom(new MathBraceInset(ar)));
1043 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1044 MathAtom at = createMathInset(t.cs());
1045 at.nucleus()->cell(0) = *cell;
1047 parse(at.nucleus()->cell(1), flags, mode);
1048 cell->push_back(at);
1052 else if (t.cs() == "substack") {
1053 cell->push_back(createMathInset(t.cs()));
1054 parse2(cell->back(), FLAG_ITEM, mode, false);
1057 else if (t.cs() == "xymatrix") {
1058 cell->push_back(createMathInset(t.cs()));
1059 parse2(cell->back(), FLAG_ITEM, mode, false);
1064 else if (1 && t.cs() == "ar") {
1065 MathXYArrowInset * p = new MathXYArrowInset;
1066 // try to read target
1067 parse(p->cell(0), FLAG_OTPTION, mode);
1068 // try to read label
1069 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1070 p->up_ = nextToken().cat() == catSuper;
1072 parse(p->cell(1), FLAG_ITEM, mode);
1073 //lyxerr << "read label: " << p->cell(1) << "\n";
1076 cell->push_back(MathAtom(p));
1077 //lyxerr << "read cell: " << cell << "\n";
1081 else if (t.cs().size()) {
1082 latexkeys const * l = in_word_set(t.cs());
1084 if (l->inset == "font") {
1085 cell->push_back(createMathInset(t.cs()));
1086 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
1089 else if (l->inset == "oldfont") {
1090 cell->push_back(createMathInset(t.cs()));
1091 parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
1095 else if (l->inset == "style") {
1096 cell->push_back(createMathInset(t.cs()));
1097 parse(cell->back().nucleus()->cell(0), flags, mode);
1101 else if (l->inset == "parbox") {
1102 // read optional positioning and width
1103 MathArray pos, width;
1104 parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
1106 parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
1107 cell->push_back(createMathInset(t.cs()));
1108 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
1109 cell->back().nucleus()->asParboxInset()->setPosition(asString(pos));
1110 cell->back().nucleus()->asParboxInset()->setWidth(asString(width));
1114 MathAtom at = createMathInset(t.cs());
1115 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1116 parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
1117 cell->push_back(at);
1122 MathAtom at = createMathInset(t.cs());
1123 MathInset::mode_type m = mode;
1124 if (m == MathInset::UNDECIDED_MODE)
1125 m = at->currentMode();
1126 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1127 parse(at.nucleus()->cell(i), FLAG_ITEM, m);
1128 cell->push_back(at);
1133 if (flags & FLAG_LEAVE) {
1134 flags &= ~FLAG_LEAVE;
1142 } // anonymous namespace
1145 void mathed_parse_cell(MathArray & ar, string const & str)
1147 istringstream is(str.c_str());
1148 mathed_parse_cell(ar, is);
1152 void mathed_parse_cell(MathArray & ar, istream & is)
1154 Parser(is).parse(ar, 0, MathInset::MATH_MODE);
1158 bool mathed_parse_normal(MathAtom & t, string const & str)
1160 istringstream is(str.c_str());
1161 return Parser(is).parse(t);
1165 bool mathed_parse_normal(MathAtom & t, istream & is)
1167 return Parser(is).parse(t);
1171 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1173 return Parser(lex).parse(t);