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
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'] = catNewline;
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 { return cs_.size() ? cs_ : string(1, char_); }
207 ostream & operator<<(ostream & os, Token const & t)
210 os << "\\" << t.cs();
212 os << "[" << t.character() << "," << t.cat() << "]";
221 typedef MathInset::mode_type mode_type;
224 Parser(LyXLex & lex);
226 Parser(istream & is);
229 bool parse(MathAtom & at);
231 void parse(MathArray & array, unsigned flags, mode_type mode);
233 int lineno() const { return lineno_; }
239 void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
242 void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
243 /// get arg delimited by 'left' and 'right'
244 string getArg(char left, char right);
248 void error(string const & msg);
249 /// dump contents to screen
252 void tokenize(istream & is);
254 void tokenize(string const & s);
256 void skipSpaceTokens(istream & is, char c);
258 void push_back(Token const & t);
262 Token const & prevToken() const;
264 Token const & nextToken() const;
266 Token const & getToken();
267 /// skips spaces if any
270 void lex(string const & s);
277 vector<Token> tokens_;
283 Parser::Parser(LyXLex & lexer)
284 : lineno_(lexer.getLineNo()), pos_(0)
286 tokenize(lexer.getStream());
291 Parser::Parser(istream & is)
292 : lineno_(0), pos_(0)
298 void Parser::push_back(Token const & t)
300 tokens_.push_back(t);
304 void Parser::pop_back()
310 Token const & Parser::prevToken() const
312 static const Token dummy;
313 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
317 Token const & Parser::nextToken() const
319 static const Token dummy;
320 return good() ? tokens_[pos_] : dummy;
324 Token const & Parser::getToken()
326 static const Token dummy;
327 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
328 return good() ? tokens_[pos_++] : dummy;
332 void Parser::skipSpaces()
334 while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
339 void Parser::putback()
345 bool Parser::good() const
347 return pos_ < tokens_.size();
351 char Parser::getChar()
354 error("The input stream is not well...");
355 return tokens_[pos_++].character();
359 string Parser::getArg(char left, char right)
369 while ((c = getChar()) != right && good())
376 void Parser::skipSpaceTokens(istream & is, char c)
378 // skip trailing spaces
379 while (catcode(c) == catSpace || catcode(c) == catNewline)
382 //lyxerr << "putting back: " << c << "\n";
387 void Parser::tokenize(istream & is)
389 // eat everything up to the next \end_inset or end of stream
390 // and store it in s for further tokenization
395 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
396 s = s.substr(0, s.size() - 10);
406 void Parser::tokenize(string const & buffer)
408 static bool init_done = false;
415 istringstream is(buffer.c_str(), ios::in | ios::binary);
419 //lyxerr << "reading c: " << c << "\n";
421 switch (catcode(c)) {
425 if (catcode(c) == catNewline)
426 ; //push_back(Token("par"));
428 push_back(Token('\n', catNewline));
435 while (is.get(c) && catcode(c) != catNewline)
444 error("unexpected end of input");
447 if (catcode(c) == catLetter) {
449 while (is.get(c) && catcode(c) == catLetter)
451 skipSpaceTokens(is, c);
460 push_back(Token(c, catcode(c)));
462 skipSpaceTokens(is, c);
467 lyxerr << "ignoring a char: " << int(c) << "\n";
472 push_back(Token(c, catcode(c)));
482 void Parser::dump() const
484 lyxerr << "\nTokens: ";
485 for (unsigned i = 0; i < tokens_.size(); ++i) {
488 lyxerr << tokens_[i];
490 lyxerr << " pos: " << pos_ << "\n";
494 void Parser::error(string const & msg)
496 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
502 bool Parser::parse(MathAtom & at)
506 parse(ar, false, MathInset::UNDECIDED_MODE);
507 if (ar.size() != 1 || ar.front()->getType() == "none") {
508 lyxerr << "unusual contents found: " << ar << endl;
509 at = MathAtom(new MathParInset);
511 at.nucleus()->cell(0) = ar;
513 lyxerr << "unusual contents found: " << ar << endl;
521 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
523 MathGridInset grid(1, 1);
524 parse1(grid, flags, mode, false);
525 array = grid.cell(0);
529 void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
532 parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
536 void Parser::parse1(MathGridInset & grid, unsigned flags,
537 mode_type mode, bool numbered)
540 MathGridInset::row_type cellrow = 0;
541 MathGridInset::col_type cellcol = 0;
542 MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
544 if (grid.asHullInset())
545 grid.asHullInset()->numbered(cellrow, numbered);
548 //lyxerr << "grid: " << grid << endl;
551 Token const & t = getToken();
554 lyxerr << "t: " << t << " flags: " << flags << "\n";
559 if (flags & FLAG_ITEM) {
560 if (t.cat() == catSpace)
564 if (t.cat() == catBegin) {
565 // skip the brace and collect everything to the next matching
567 flags |= FLAG_BRACE_LAST;
571 // handle only this single token, leave the loop if done
576 if (flags & FLAG_OPTION) {
577 if (t.cat() == catOther && t.character() == '[') {
579 parse(ar, FLAG_BRACK_LAST, mode);
582 // no option found, put back token and we are done
591 if (t.cat() == catMath) {
592 if (mode != MathInset::MATH_MODE) {
593 // we are inside some text mode thingy, so opening new math is allowed
594 Token const & n = getToken();
595 if (n.cat() == catMath) {
596 // TeX's $$...$$ syntax for displayed math
597 cell->push_back(MathAtom(new MathHullInset("equation")));
598 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
599 getToken(); // skip the second '$' token
601 // simple $...$ stuff
603 cell->push_back(MathAtom(new MathHullInset("simple")));
604 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
608 else if (flags & FLAG_SIMPLE) {
609 // this is the end of the formula
614 error("something strange in the parser\n");
619 else if (t.cat() == catLetter)
620 cell->push_back(MathAtom(new MathCharInset(t.character())));
622 else if (t.cat() == catSpace && mode != MathInset::MATH_MODE)
623 cell->push_back(MathAtom(new MathCharInset(t.character())));
625 else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
626 cell->push_back(MathAtom(new MathCharInset(t.character())));
628 else if (t.cat() == catParameter) {
629 Token const & n = getToken();
630 cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
633 else if (t.cat() == catActive)
634 cell->push_back(MathAtom(new MathCharInset(t.character())));
636 else if (t.cat() == catBegin) {
638 parse(ar, FLAG_BRACE_LAST, mode);
639 // do not create a BraceInset if they were written by LyX
640 // this helps to keep the annoyance of "a choose b" to a minimum
641 if (ar.size() == 1 && ar[0]->extraBraces())
644 cell->push_back(MathAtom(new MathBraceInset(ar)));
647 else if (t.cat() == catEnd) {
648 if (flags & FLAG_BRACE_LAST)
650 error("found '}' unexpectedly");
652 //add(cell, '}', LM_TC_TEX);
655 else if (t.cat() == catAlign) {
657 //lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
658 if (cellcol == grid.ncols()) {
659 lyxerr << "adding column " << cellcol << "\n";
660 grid.addCol(cellcol - 1);
662 cell = &grid.cell(grid.index(cellrow, cellcol));
665 else if (t.cat() == catSuper || t.cat() == catSub) {
666 if (mode == MathInset::VERBATIM_MODE)
667 cell->push_back(MathAtom(new MathStringInset(t.asString())));
669 bool up = (t.cat() == catSuper);
670 // we need no new script inset if the last thing was a scriptinset,
671 // which has that script already not the same script already
673 cell->push_back(MathAtom(new MathScriptInset(up)));
674 else if (cell->back()->asScriptInset() &&
675 !cell->back()->asScriptInset()->has(up))
676 cell->back().nucleus()->asScriptInset()->ensure(up);
677 else if (cell->back()->asScriptInset())
678 cell->push_back(MathAtom(new MathScriptInset(up)));
680 cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
681 MathScriptInset * p = cell->back().nucleus()->asScriptInset();
682 parse(p->cell(up), FLAG_ITEM, mode);
685 // special handling of {}-bases
686 // is this always correct?
687 if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
688 p->nuc().back()->extraBraces())
689 p->nuc() = p->nuc().back()->asNestInset()->cell(0);
693 else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
694 lyxerr << "finished reading option\n";
698 else if (t.cat() == catOther)
699 cell->push_back(MathAtom(new MathCharInset(t.character())));
705 else if (t.cs() == "lyxlock") {
707 cell->back().nucleus()->lock(true);
710 else if (t.cs() == "def" || t.cs() == "newcommand") {
713 if (t.cs() == "def") {
715 name = getToken().cs();
719 while (good() && nextToken().cat() != catBegin) {
720 pars += getToken().cs();
724 //lyxerr << "read \\def parameter list '" << pars << "'\n";
726 } else { // t.cs() == "newcommand"
728 if (getToken().cat() != catBegin) {
729 error("'{' in \\newcommand expected (1) \n");
733 name = getToken().cs();
735 if (getToken().cat() != catEnd) {
736 error("'}' in \\newcommand expected\n");
740 string arg = getArg('[', ']');
742 nargs = atoi(arg.c_str());
747 parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
749 // we cannot handle recursive stuff at all
751 //test.push_back(createMathInset(name));
752 //if (ar1.contains(test)) {
753 // error("we cannot handle recursive macros at all.\n");
757 // is a version for display attached?
760 if (nextToken().cat() == catBegin) {
761 parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
764 cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
767 else if (t.cs() == "(") {
768 cell->push_back(MathAtom(new MathHullInset("simple")));
769 parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
772 else if (t.cs() == "[") {
773 cell->push_back(MathAtom(new MathHullInset("equation")));
774 parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
777 else if (t.cs() == "protect")
778 // ignore \\protect, will hopefully be re-added during output
781 else if (t.cs() == "end") {
782 if (flags & FLAG_END) {
783 // eat environment name
784 //string const name =
786 // FIXME: check that we ended the correct environment
789 error("found 'end' unexpectedly");
792 else if (t.cs() == ")") {
793 if (flags & FLAG_SIMPLE2)
795 error("found '\\)' unexpectedly");
798 else if (t.cs() == "]") {
799 if (flags & FLAG_EQUATION)
801 error("found '\\]' unexpectedly");
804 else if (t.cs() == "\\") {
805 grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
808 if (cellrow == grid.nrows())
809 grid.addRow(cellrow - 1);
810 if (grid.asHullInset())
811 grid.asHullInset()->numbered(cellrow, numbered);
812 cell = &grid.cell(grid.index(cellrow, cellcol));
816 else if (t.cs() == "multicolumn") {
817 // extract column count and insert dummy cells
819 parse(count, FLAG_ITEM, mode);
821 if (!extractNumber(count, cols)) {
822 lyxerr << " can't extract number of cells from " << count << "\n";
824 // resize the table if necessary
825 for (int i = 0; i < cols; ++i) {
827 if (cellcol == grid.ncols()) {
828 lyxerr << "adding column " << cellcol << "\n";
829 grid.addCol(cellcol - 1);
831 cell = &grid.cell(grid.index(cellrow, cellcol));
832 // mark this as dummy
833 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
835 // the last cell is the real thng, not a dummy
836 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
838 // read special alignment
840 parse(align, FLAG_ITEM, mode);
841 //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
843 // parse the remaining contents into the "real" cell
844 parse(*cell, FLAG_ITEM, mode);
848 else if (t.cs() == "limits")
851 else if (t.cs() == "nolimits")
854 else if (t.cs() == "nonumber") {
855 if (grid.asHullInset())
856 grid.asHullInset()->numbered(cellrow, false);
859 else if (t.cs() == "number") {
860 if (grid.asHullInset())
861 grid.asHullInset()->numbered(cellrow, true);
864 else if (t.cs() == "hline") {
865 if (grid.asHullInset())
866 grid.asHullInset()->rowinfo(cellrow + 1);
869 else if (t.cs() == "sqrt") {
871 parse(ar, FLAG_OPTION, mode);
873 cell->push_back(MathAtom(new MathRootInset));
874 cell->back().nucleus()->cell(0) = ar;
875 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
877 cell->push_back(MathAtom(new MathSqrtInset));
878 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
882 else if (t.cs() == "ref") {
883 cell->push_back(MathAtom(new RefInset));
884 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
885 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
888 else if (t.cs() == "left") {
889 string l = getToken().asString();
891 parse(ar, FLAG_RIGHT, mode);
892 string r = getToken().asString();
893 cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
896 else if (t.cs() == "right") {
897 if (flags & FLAG_RIGHT)
899 //lyxerr << "got so far: '" << cell << "'\n";
900 error("Unmatched right delimiter");
904 else if (t.cs() == "begin") {
905 string const name = getArg('{', '}');
906 if (name == "array" || name == "subarray") {
907 string const valign = getArg('[', ']') + 'c';
908 string const halign = getArg('{', '}');
909 cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
910 parse2(cell->back(), FLAG_END, mode, false);
913 else if (name == "split" || name == "cases" ||
914 name == "gathered" || name == "aligned") {
915 cell->push_back(createMathInset(name));
916 parse2(cell->back(), FLAG_END, mode, false);
919 else if (name == "math") {
920 cell->push_back(MathAtom(new MathHullInset("simple")));
921 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
924 else if (name == "equation" || name == "equation*"
925 || name == "displaymath") {
926 cell->push_back(MathAtom(new MathHullInset("equation")));
927 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
930 else if (name == "eqnarray" || name == "eqnarray*") {
931 cell->push_back(MathAtom(new MathHullInset("eqnarray")));
932 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
935 else if (name == "align" || name == "align*") {
936 cell->push_back(MathAtom(new MathHullInset("align")));
937 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
940 else if (name == "alignat" || name == "alignat*") {
941 // ignore this for a while
943 cell->push_back(MathAtom(new MathHullInset("alignat")));
944 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
947 else if (name == "xalignat" || name == "xalignat*") {
948 // ignore this for a while
950 cell->push_back(MathAtom(new MathHullInset("xalignat")));
951 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
954 else if (name == "xxalignat") {
955 // ignore this for a while
957 cell->push_back(MathAtom(new MathHullInset("xxalignat")));
958 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
961 else if (name == "multline" || name == "multline*") {
962 cell->push_back(MathAtom(new MathHullInset("multline")));
963 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
966 else if (name == "gather" || name == "gather*") {
967 cell->push_back(MathAtom(new MathHullInset("gather")));
968 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
971 else if (latexkeys const * l = in_word_set(name)) {
972 if (l->inset == "matrix") {
973 cell->push_back(createMathInset(name));
974 parse2(cell->back(), FLAG_END, mode, false);
979 // lyxerr << "unknow math inset begin '" << name << "'\n";
980 // create generic environment inset
981 cell->push_back(MathAtom(new MathEnvInset(name)));
982 parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
986 else if (t.cs() == "kern") {
992 Token const & t = getToken();
998 if (isValidLength(s))
1001 cell->push_back(MathAtom(new MathKernInset(s)));
1004 else if (t.cs() == "label") {
1006 parse(ar, FLAG_ITEM, MathInset::VERBATIM_MODE);
1007 if (grid.asHullInset()) {
1008 grid.asHullInset()->label(cellrow, asString(ar));
1010 cell->push_back(createMathInset(t.cs()));
1011 cell->push_back(MathAtom(new MathBraceInset(ar)));
1015 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1016 MathAtom at = createMathInset(t.cs());
1017 at.nucleus()->cell(0) = *cell;
1019 parse(at.nucleus()->cell(1), flags, mode);
1020 cell->push_back(at);
1024 else if (t.cs() == "substack") {
1025 cell->push_back(createMathInset(t.cs()));
1026 parse2(cell->back(), FLAG_ITEM, mode, false);
1029 else if (t.cs() == "xymatrix") {
1030 cell->push_back(createMathInset(t.cs()));
1031 parse2(cell->back(), FLAG_ITEM, mode, false);
1036 else if (1 && t.cs() == "ar") {
1037 MathXYArrowInset * p = new MathXYArrowInset;
1038 // try to read target
1039 parse(p->cell(0), FLAG_OTPTION, mode);
1040 // try to read label
1041 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1042 p->up_ = nextToken().cat() == catSuper;
1044 parse(p->cell(1), FLAG_ITEM, mode);
1045 //lyxerr << "read label: " << p->cell(1) << "\n";
1048 cell->push_back(MathAtom(p));
1049 //lyxerr << "read cell: " << cell << "\n";
1053 else if (t.cs().size()) {
1054 latexkeys const * l = in_word_set(t.cs());
1056 if (l->inset == "font") {
1057 cell->push_back(createMathInset(t.cs()));
1058 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
1061 else if (l->inset == "oldfont") {
1062 cell->push_back(createMathInset(t.cs()));
1063 parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
1067 else if (l->inset == "style") {
1068 cell->push_back(createMathInset(t.cs()));
1069 parse(cell->back().nucleus()->cell(0), flags, mode);
1073 else if (l->inset == "parbox") {
1074 // read optional positioning and width
1075 MathArray pos, width;
1076 parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
1077 parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
1078 cell->push_back(createMathInset(t.cs()));
1079 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
1080 cell->back().nucleus()->asParboxInset()->setPosition(asString(pos));
1081 cell->back().nucleus()->asParboxInset()->setWidth(asString(width));
1085 MathAtom at = createMathInset(t.cs());
1086 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1087 parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
1088 cell->push_back(at);
1093 MathAtom at = createMathInset(t.cs());
1094 MathInset::mode_type m = mode;
1095 if (m == MathInset::UNDECIDED_MODE)
1096 m = at->currentMode();
1097 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1098 parse(at.nucleus()->cell(i), FLAG_ITEM, m);
1099 cell->push_back(at);
1104 if (flags & FLAG_LEAVE) {
1105 flags &= ~FLAG_LEAVE;
1113 } // anonymous namespace
1116 void mathed_parse_cell(MathArray & ar, string const & str)
1118 istringstream is(str.c_str());
1119 mathed_parse_cell(ar, is);
1123 void mathed_parse_cell(MathArray & ar, istream & is)
1125 Parser(is).parse(ar, 0, MathInset::MATH_MODE);
1129 bool mathed_parse_normal(MathAtom & t, string const & str)
1131 istringstream is(str.c_str());
1132 return Parser(is).parse(t);
1136 bool mathed_parse_normal(MathAtom & t, istream & is)
1138 return Parser(is).parse(t);
1142 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1144 return Parser(lex).parse(t);