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_tabularinset.h"
60 #include "math_xyarrowinset.h"
62 //#include "insets/insetref.h"
63 #include "ref_inset.h"
67 #include "support/LAssert.h"
68 #include "support/lstrings.h"
87 MathInset::mode_type asMode(MathInset::mode_type oldmode, string const & str)
89 //lyxerr << "handling mode: '" << str << "'\n";
90 if (str == "mathmode")
91 return MathInset::MATH_MODE;
92 if (str == "textmode" || str == "forcetext")
93 return MathInset::TEXT_MODE;
98 bool stared(string const & s)
100 string::size_type const n = s.size();
101 return n && s[n - 1] == '*';
105 // These are TeX's catcodes
107 catEscape, // 0 backslash
117 catSpace, // 10 space
118 catLetter, // 11 a-zA-Z
119 catOther, // 12 none of the above
122 catInvalid // 15 <delete>
125 CatCode theCatcode[256];
128 inline CatCode catcode(unsigned char c)
130 return theCatcode[c];
135 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
136 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
137 FLAG_END = 1 << 3, // next \\end ends the parsing process
138 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
139 FLAG_TEXTMODE = 1 << 5, // we are in a box
140 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
141 FLAG_LEAVE = 1 << 7, // leave the loop at the end
142 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
143 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
144 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
145 FLAG_OPTION = 1 << 11, // read [...] style option
146 FLAG_BRACED = 1 << 12 // read {...} style argument
152 fill(theCatcode, theCatcode + 256, catOther);
153 fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
154 fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
156 theCatcode['\\'] = catEscape;
157 theCatcode['{'] = catBegin;
158 theCatcode['}'] = catEnd;
159 theCatcode['$'] = catMath;
160 theCatcode['&'] = catAlign;
161 theCatcode['\n'] = catNewline;
162 theCatcode['#'] = catParameter;
163 theCatcode['^'] = catSuper;
164 theCatcode['_'] = catSub;
165 theCatcode['
\7f'] = catIgnore;
166 theCatcode[' '] = catSpace;
167 theCatcode['\t'] = catSpace;
168 theCatcode['\r'] = catNewline;
169 theCatcode['~'] = catActive;
170 theCatcode['%'] = catComment;
176 // Helper class for parsing
182 Token() : cs_(), char_(0), cat_(catIgnore) {}
184 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
186 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
189 string const & cs() const { return cs_; }
191 CatCode cat() const { return cat_; }
193 char character() const { return char_; }
195 string asString() const { return cs_.size() ? cs_ : string(1, char_); }
206 ostream & operator<<(ostream & os, Token const & t)
209 os << '\\' << t.cs();
210 else if (t.cat() == catLetter)
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 void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
237 MathArray parse(unsigned flags, mode_type mode);
239 int lineno() const { return lineno_; }
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);
277 string parse_verbatim_item();
279 string parse_verbatim_option();
284 vector<Token> tokens_;
290 Parser::Parser(LyXLex & lexer)
291 : lineno_(lexer.getLineNo()), pos_(0)
293 tokenize(lexer.getStream());
298 Parser::Parser(istream & is)
299 : lineno_(0), pos_(0)
305 void Parser::push_back(Token const & t)
307 tokens_.push_back(t);
311 void Parser::pop_back()
317 Token const & Parser::prevToken() const
319 static const Token dummy;
320 return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
324 Token const & Parser::nextToken() const
326 static const Token dummy;
327 return good() ? tokens_[pos_] : dummy;
331 Token const & Parser::getToken()
333 static const Token dummy;
334 //lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
335 return good() ? tokens_[pos_++] : dummy;
339 void Parser::skipSpaces()
341 while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
346 void Parser::putback()
352 bool Parser::good() const
354 return pos_ < tokens_.size();
358 char Parser::getChar()
361 error("The input stream is not well...");
362 return tokens_[pos_++].character();
366 string Parser::getArg(char left, char right)
376 while ((c = getChar()) != right && good())
383 void Parser::skipSpaceTokens(istream & is, char c)
385 // skip trailing spaces
386 while (catcode(c) == catSpace || catcode(c) == catNewline)
389 //lyxerr << "putting back: " << c << "\n";
394 void Parser::tokenize(istream & is)
396 // eat everything up to the next \end_inset or end of stream
397 // and store it in s for further tokenization
402 if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
403 s = s.substr(0, s.size() - 10);
407 // Remove the space after \end_inset
408 if (is.get(c) && c != ' ')
416 void Parser::tokenize(string const & buffer)
418 static bool init_done = false;
425 istringstream is(buffer.c_str(), ios::in | ios::binary);
429 //lyxerr << "reading c: " << c << "\n";
431 switch (catcode(c)) {
435 if (catcode(c) == catNewline)
436 ; //push_back(Token("par"));
438 push_back(Token('\n', catNewline));
446 while (is.get(c) && catcode(c) != catNewline)
456 error("unexpected end of input");
459 if (catcode(c) == catLetter) {
461 while (is.get(c) && catcode(c) == catLetter)
463 skipSpaceTokens(is, c);
472 push_back(Token(c, catcode(c)));
474 skipSpaceTokens(is, c);
479 lyxerr << "ignoring a char: " << int(c) << "\n";
484 push_back(Token(c, catcode(c)));
494 void Parser::dump() const
496 lyxerr << "\nTokens: ";
497 for (unsigned i = 0; i < tokens_.size(); ++i) {
500 lyxerr << tokens_[i];
502 lyxerr << " pos: " << pos_ << "\n";
506 void Parser::error(string const & msg)
508 lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
514 bool Parser::parse(MathAtom & at)
518 parse(ar, false, MathInset::UNDECIDED_MODE);
519 if (ar.size() != 1 || ar.front()->getType() == "none") {
520 lyxerr << "unusual contents found: " << ar << endl;
521 at = MathAtom(new MathParInset(ar));
522 //if (at->nargs() > 0)
523 // at.nucleus()->cell(0) = ar;
525 // lyxerr << "unusual contents found: " << ar << endl;
533 string Parser::parse_verbatim_option()
537 if (nextToken().character() == '[') {
538 Token t = getToken();
539 for (Token t = getToken(); t.character() != ']' && good(); t = getToken()) {
540 if (t.cat() == catBegin) {
542 res += '{' + parse_verbatim_item() + '}';
551 string Parser::parse_verbatim_item()
555 if (nextToken().cat() == catBegin) {
556 Token t = getToken();
557 for (Token t = getToken(); t.cat() != catEnd && good(); t = getToken()) {
558 if (t.cat() == catBegin) {
560 res += '{' + parse_verbatim_item() + '}';
570 MathArray Parser::parse(unsigned flags, mode_type mode)
573 parse(ar, flags, mode);
578 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
580 MathGridInset grid(1, 1);
581 parse1(grid, flags, mode, false);
582 array = grid.cell(0);
586 void Parser::parse2(MathAtom & at, const unsigned flags, const mode_type mode,
589 parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
593 void Parser::parse1(MathGridInset & grid, unsigned flags,
594 const mode_type mode, const bool numbered)
597 MathGridInset::row_type cellrow = 0;
598 MathGridInset::col_type cellcol = 0;
599 MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
601 if (grid.asHullInset())
602 grid.asHullInset()->numbered(cellrow, numbered);
605 //lyxerr << " flags: " << flags << "\n";
606 //lyxerr << " mode: " << mode << "\n";
607 //lyxerr << "grid: " << grid << endl;
610 Token const & t = getToken();
613 lyxerr << "t: " << t << " flags: " << flags << "\n";
614 lyxerr << "mode: " << mode << "\n";
619 if (flags & FLAG_ITEM) {
621 if (t.cat() == catBegin) {
622 // skip the brace and collect everything to the next matching
624 parse1(grid, FLAG_BRACE_LAST, mode, numbered);
628 // handle only this single token, leave the loop if done
633 if (flags & FLAG_BRACED) {
634 if (t.cat() == catSpace)
637 if (t.cat() != catBegin) {
638 error("opening brace expected");
642 // skip the brace and collect everything to the next matching
644 flags = FLAG_BRACE_LAST;
648 if (flags & FLAG_OPTION) {
649 if (t.cat() == catOther && t.character() == '[') {
651 parse(ar, FLAG_BRACK_LAST, mode);
654 // no option found, put back token and we are done
663 if (t.cat() == catMath) {
664 if (mode != MathInset::MATH_MODE) {
665 // we are inside some text mode thingy, so opening new math is allowed
666 Token const & n = getToken();
667 if (n.cat() == catMath) {
668 // TeX's $$...$$ syntax for displayed math
669 cell->push_back(MathAtom(new MathHullInset("equation")));
670 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
671 getToken(); // skip the second '$' token
673 // simple $...$ stuff
675 cell->push_back(MathAtom(new MathHullInset("simple")));
676 parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
680 else if (flags & FLAG_SIMPLE) {
681 // this is the end of the formula
686 error("something strange in the parser\n");
691 else if (t.cat() == catLetter)
692 cell->push_back(MathAtom(new MathCharInset(t.character())));
694 else if (t.cat() == catSpace && mode != MathInset::MATH_MODE) {
695 if (cell->empty() || cell->back()->getChar() != ' ')
696 cell->push_back(MathAtom(new MathCharInset(t.character())));
699 else if (t.cat() == catNewline && mode != MathInset::MATH_MODE) {
700 if (cell->empty() || cell->back()->getChar() != ' ')
701 cell->push_back(MathAtom(new MathCharInset(' ')));
704 else if (t.cat() == catParameter) {
705 Token const & n = getToken();
706 cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
709 else if (t.cat() == catActive)
710 cell->push_back(MathAtom(new MathCharInset(t.character())));
712 else if (t.cat() == catBegin) {
714 parse(ar, FLAG_BRACE_LAST, mode);
715 // do not create a BraceInset if they were written by LyX
716 // this helps to keep the annoyance of "a choose b" to a minimum
717 if (ar.size() == 1 && ar[0]->extraBraces())
720 cell->push_back(MathAtom(new MathBraceInset(ar)));
723 else if (t.cat() == catEnd) {
724 if (flags & FLAG_BRACE_LAST)
726 error("found '}' unexpectedly");
728 //add(cell, '}', LM_TC_TEX);
731 else if (t.cat() == catAlign) {
733 //lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
734 if (cellcol == grid.ncols()) {
735 //lyxerr << "adding column " << cellcol << "\n";
736 grid.addCol(cellcol - 1);
738 cell = &grid.cell(grid.index(cellrow, cellcol));
741 else if (t.cat() == catSuper || t.cat() == catSub) {
742 bool up = (t.cat() == catSuper);
743 // we need no new script inset if the last thing was a scriptinset,
744 // which has that script already not the same script already
746 cell->push_back(MathAtom(new MathScriptInset(up)));
747 else if (cell->back()->asScriptInset() &&
748 !cell->back()->asScriptInset()->has(up))
749 cell->back().nucleus()->asScriptInset()->ensure(up);
750 else if (cell->back()->asScriptInset())
751 cell->push_back(MathAtom(new MathScriptInset(up)));
753 cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
754 MathScriptInset * p = cell->back().nucleus()->asScriptInset();
755 // special handling of {}-bases
756 // is this always correct?
757 // It appears that this is wrong (Dekel)
758 //if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
759 // p->nuc().back()->extraBraces())
760 // p->nuc() = p->nuc().back()->asNestInset()->cell(0);
761 parse(p->cell(up), FLAG_ITEM, mode);
768 else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
769 //lyxerr << "finished reading option\n";
773 else if (t.cat() == catOther)
774 cell->push_back(MathAtom(new MathCharInset(t.character())));
776 else if (t.cat() == catComment) {
779 Token const & t = getToken();
780 if (t.cat() == catNewline)
784 cell->push_back(MathAtom(new MathCommentInset(s)));
792 else if (t.cs() == "lyxlock") {
794 cell->back().nucleus()->lock(true);
797 else if (t.cs() == "def" || t.cs() == "newcommand") {
800 if (t.cs() == "def") {
802 name = getToken().cs();
806 while (good() && nextToken().cat() != catBegin) {
807 pars += getToken().cs();
811 //lyxerr << "read \\def parameter list '" << pars << "'\n";
813 } else { // t.cs() == "newcommand"
815 if (getToken().cat() != catBegin) {
816 error("'{' in \\newcommand expected (1) \n");
820 name = getToken().cs();
822 if (getToken().cat() != catEnd) {
823 error("'}' in \\newcommand expected\n");
827 string arg = getArg('[', ']');
829 nargs = atoi(arg.c_str());
834 parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
836 // we cannot handle recursive stuff at all
838 //test.push_back(createMathInset(name));
839 //if (ar1.contains(test)) {
840 // error("we cannot handle recursive macros at all.\n");
844 // is a version for display attached?
847 if (nextToken().cat() == catBegin)
848 parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
850 cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
853 else if (t.cs() == "(") {
854 cell->push_back(MathAtom(new MathHullInset("simple")));
855 parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
858 else if (t.cs() == "[") {
859 cell->push_back(MathAtom(new MathHullInset("equation")));
860 parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
863 else if (t.cs() == "protect")
864 // ignore \\protect, will hopefully be re-added during output
867 else if (t.cs() == "end") {
868 if (flags & FLAG_END) {
869 // eat environment name
870 //string const name =
872 // FIXME: check that we ended the correct environment
875 error("found 'end' unexpectedly");
878 else if (t.cs() == ")") {
879 if (flags & FLAG_SIMPLE2)
881 error("found '\\)' unexpectedly");
884 else if (t.cs() == "]") {
885 if (flags & FLAG_EQUATION)
887 error("found '\\]' unexpectedly");
890 else if (t.cs() == "\\") {
891 grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
894 if (cellrow == grid.nrows())
895 grid.addRow(cellrow - 1);
896 if (grid.asHullInset())
897 grid.asHullInset()->numbered(cellrow, numbered);
898 cell = &grid.cell(grid.index(cellrow, cellcol));
902 else if (t.cs() == "multicolumn") {
903 // extract column count and insert dummy cells
905 parse(count, FLAG_ITEM, mode);
907 if (!extractNumber(count, cols)) {
908 lyxerr << " can't extract number of cells from " << count << "\n";
910 // resize the table if necessary
911 for (int i = 0; i < cols; ++i) {
913 if (cellcol == grid.ncols()) {
914 //lyxerr << "adding column " << cellcol << "\n";
915 grid.addCol(cellcol - 1);
917 cell = &grid.cell(grid.index(cellrow, cellcol));
918 // mark this as dummy
919 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
921 // the last cell is the real thng, not a dummy
922 grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
924 // read special alignment
926 parse(align, FLAG_ITEM, mode);
927 //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
929 // parse the remaining contents into the "real" cell
930 parse(*cell, FLAG_ITEM, mode);
934 else if (t.cs() == "limits")
937 else if (t.cs() == "nolimits")
940 else if (t.cs() == "nonumber") {
941 if (grid.asHullInset())
942 grid.asHullInset()->numbered(cellrow, false);
945 else if (t.cs() == "number") {
946 if (grid.asHullInset())
947 grid.asHullInset()->numbered(cellrow, true);
950 else if (t.cs() == "hline") {
951 grid.rowinfo(cellrow).lines_ ++;
954 else if (t.cs() == "sqrt") {
956 parse(ar, FLAG_OPTION, mode);
958 cell->push_back(MathAtom(new MathRootInset));
959 cell->back().nucleus()->cell(0) = ar;
960 parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
962 cell->push_back(MathAtom(new MathSqrtInset));
963 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
967 else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
968 cell->push_back(createMathInset(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() == "ref" || t.cs() == "prettyref" ||
974 t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
975 cell->push_back(MathAtom(new RefInset(t.cs())));
976 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
977 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
980 else if (t.cs() == "left") {
982 string l = getToken().asString();
984 parse(ar, FLAG_RIGHT, mode);
986 string r = getToken().asString();
987 cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
990 else if (t.cs() == "right") {
991 if (flags & FLAG_RIGHT)
993 //lyxerr << "got so far: '" << cell << "'\n";
994 error("Unmatched right delimiter");
998 else if (t.cs() == "begin") {
999 string const name = getArg('{', '}');
1001 if (name == "array" || name == "subarray") {
1002 string const valign = parse_verbatim_option() + 'c';
1003 string const halign = parse_verbatim_item();
1004 cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
1005 parse2(cell->back(), FLAG_END, mode, false);
1008 else if (name == "tabular") {
1009 string const valign = parse_verbatim_option() + 'c';
1010 string const halign = parse_verbatim_item();
1011 cell->push_back(MathAtom(new MathTabularInset(name, valign[0], halign)));
1012 parse2(cell->back(), FLAG_END, MathInset::TEXT_MODE, false);
1015 else if (name == "split" || name == "cases" ||
1016 name == "gathered" || name == "aligned") {
1017 cell->push_back(createMathInset(name));
1018 parse2(cell->back(), FLAG_END, mode, false);
1021 else if (name == "math") {
1022 cell->push_back(MathAtom(new MathHullInset("simple")));
1023 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
1026 else if (name == "equation" || name == "equation*"
1027 || name == "displaymath") {
1028 cell->push_back(MathAtom(new MathHullInset("equation")));
1029 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
1032 else if (name == "eqnarray" || name == "eqnarray*") {
1033 cell->push_back(MathAtom(new MathHullInset("eqnarray")));
1034 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1037 else if (name == "align" || name == "align*") {
1038 cell->push_back(MathAtom(new MathHullInset("align")));
1039 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1042 else if (name == "flalign" || name == "flalign*") {
1043 cell->push_back(MathAtom(new MathHullInset("flalign")));
1044 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1047 else if (name == "alignat" || name == "alignat*") {
1048 // ignore this for a while
1050 cell->push_back(MathAtom(new MathHullInset("alignat")));
1051 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1054 else if (name == "xalignat" || name == "xalignat*") {
1055 // ignore this for a while
1057 cell->push_back(MathAtom(new MathHullInset("xalignat")));
1058 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1061 else if (name == "xxalignat") {
1062 // ignore this for a while
1064 cell->push_back(MathAtom(new MathHullInset("xxalignat")));
1065 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1068 else if (name == "multline" || name == "multline*") {
1069 cell->push_back(MathAtom(new MathHullInset("multline")));
1070 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1073 else if (name == "gather" || name == "gather*") {
1074 cell->push_back(MathAtom(new MathHullInset("gather")));
1075 parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
1078 else if (latexkeys const * l = in_word_set(name)) {
1079 if (l->inset == "matrix") {
1080 cell->push_back(createMathInset(name));
1081 parse2(cell->back(), FLAG_END, mode, false);
1087 lyxerr << "found unknown math environment '" << name << "'\n";
1088 // create generic environment inset
1089 cell->push_back(MathAtom(new MathEnvInset(name)));
1090 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
1094 else if (t.cs() == "kern") {
1095 #ifdef WITH_WARNINGS
1100 Token const & t = getToken();
1106 if (isValidLength(s))
1109 cell->push_back(MathAtom(new MathKernInset(s)));
1112 else if (t.cs() == "label") {
1113 string label = parse_verbatim_item();
1114 if (grid.asHullInset()) {
1115 grid.asHullInset()->label(cellrow, label);
1117 cell->push_back(createMathInset(t.cs()));
1118 cell->push_back(MathAtom(new MathBraceInset(asArray(label))));
1122 else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
1123 MathAtom at = createMathInset(t.cs());
1124 at.nucleus()->cell(0) = *cell;
1126 parse(at.nucleus()->cell(1), flags, mode);
1127 cell->push_back(at);
1131 else if (t.cs() == "substack") {
1132 cell->push_back(createMathInset(t.cs()));
1133 parse2(cell->back(), FLAG_ITEM, mode, false);
1136 else if (t.cs() == "xymatrix") {
1137 cell->push_back(createMathInset(t.cs()));
1138 parse2(cell->back(), FLAG_ITEM, mode, false);
1141 else if (t.cs() == "framebox") {
1142 cell->push_back(createMathInset(t.cs()));
1143 parse(cell->back().nucleus()->cell(0), FLAG_OPTION, MathInset::TEXT_MODE);
1144 parse(cell->back().nucleus()->cell(1), FLAG_OPTION, MathInset::TEXT_MODE);
1145 parse(cell->back().nucleus()->cell(2), FLAG_ITEM, MathInset::TEXT_MODE);
1149 else if (t.cs() == "infer") {
1151 parse(ar, FLAG_OPTION, mode);
1152 cell->push_back(createMathInset(t.cs()));
1153 parse2(cell->back(), FLAG_ITEM, mode, false);
1157 else if (1 && t.cs() == "ar") {
1158 MathXYArrowInset * p = new MathXYArrowInset;
1159 // try to read target
1160 parse(p->cell(0), FLAG_OTPTION, mode);
1161 // try to read label
1162 if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
1163 p->up_ = nextToken().cat() == catSuper;
1165 parse(p->cell(1), FLAG_ITEM, mode);
1166 //lyxerr << "read label: " << p->cell(1) << "\n";
1169 cell->push_back(MathAtom(p));
1170 //lyxerr << "read cell: " << cell << "\n";
1174 else if (t.cs().size()) {
1175 latexkeys const * l = in_word_set(t.cs());
1177 if (l->inset == "font") {
1178 cell->push_back(createMathInset(t.cs()));
1179 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(mode, l->extra));
1182 else if (l->inset == "oldfont") {
1183 cell->push_back(createMathInset(t.cs()));
1184 parse(cell->back().nucleus()->cell(0), flags, asMode(mode, l->extra));
1188 else if (l->inset == "style") {
1189 cell->push_back(createMathInset(t.cs()));
1190 parse(cell->back().nucleus()->cell(0), flags, mode);
1194 else if (l->inset == "parbox") {
1195 // read optional positioning and width
1196 string pos = parse_verbatim_option();
1197 string width = parse_verbatim_item();
1198 cell->push_back(createMathInset(t.cs()));
1199 parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
1200 cell->back().nucleus()->asParboxInset()->setPosition(pos);
1201 cell->back().nucleus()->asParboxInset()->setWidth(width);
1205 MathAtom at = createMathInset(t.cs());
1206 for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
1207 parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(mode, l->extra));
1208 cell->push_back(at);
1213 MathAtom at = createMathInset(t.cs());
1214 MathInset::mode_type m = mode;
1215 //if (m == MathInset::UNDECIDED_MODE)
1216 //lyxerr << "default creation: m1: " << m << "\n";
1217 if (at->currentMode() != MathInset::UNDECIDED_MODE)
1218 m = at->currentMode();
1219 //lyxerr << "default creation: m2: " << m << "\n";
1220 MathInset::idx_type start = 0;
1221 // this fails on \bigg[...\bigg]
1223 //parse(opt, FLAG_OPTION, MathInset::VERBATIM_MODE);
1226 // at.nucleus()->cell(0) = opt;
1228 for (MathInset::idx_type i = start; i < at->nargs(); ++i)
1229 parse(at.nucleus()->cell(i), FLAG_ITEM, m);
1230 cell->push_back(at);
1235 if (flags & FLAG_LEAVE) {
1236 flags &= ~FLAG_LEAVE;
1244 } // anonymous namespace
1247 void mathed_parse_cell(MathArray & ar, string const & str)
1249 istringstream is(str.c_str());
1250 mathed_parse_cell(ar, is);
1254 void mathed_parse_cell(MathArray & ar, istream & is)
1256 Parser(is).parse(ar, 0, MathInset::MATH_MODE);
1260 bool mathed_parse_normal(MathAtom & t, string const & str)
1262 istringstream is(str.c_str());
1263 return Parser(is).parse(t);
1267 bool mathed_parse_normal(MathAtom & t, istream & is)
1269 return Parser(is).parse(t);
1273 bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
1275 return Parser(lex).parse(t);
1279 void mathed_parse_normal(MathGridInset & grid, string const & str)
1281 istringstream is(str.c_str());
1282 Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);