]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parser.C
small up/down tweaking
[lyx.git] / src / mathed / math_parser.C
index 6cfa4f05721e635e9647a046ac69c774498f2297..fb00252908f933449fd83d77c58921ddf1a31bd0 100644 (file)
@@ -86,13 +86,13 @@ using std::atoi;
 
 namespace {
 
-MathInset::mode_type asMode(string const & str)
+MathInset::mode_type asMode(MathInset::mode_type oldmode, string const & str)
 {
        if (str == "mathmode")
                return MathInset::MATH_MODE;
        if (str == "textmode" || str == "forcetext")
                return MathInset::TEXT_MODE;
-       return MathInset::UNDECIDED_MODE;
+       return oldmode;
 }
 
 
@@ -207,9 +207,9 @@ private:
 ostream & operator<<(ostream & os, Token const & t)
 {
        if (t.cs().size())
-               os << "\\" << t.cs();
+               os << '\\' << t.cs();
        else
-               os << "[" << t.character() << "," << t.cat() << "]";
+               os << '[' << t.character() << ',' << t.cat() << ']';
        return os;
 }
 
@@ -403,6 +403,9 @@ void Parser::tokenize(istream & is)
                        break;
                }
        }
+       // Remove the space after \end_inset
+       if (is.get(c) && c != ' ')
+               is.unget();
 
        // tokenize buffer
        tokenize(s);
@@ -535,7 +538,7 @@ string Parser::parse_verbatim_option()
                        if (t.cat() == catBegin) {
                                putback();
                                res += '{' + parse_verbatim_item() + '}';
-                       } else 
+                       } else
                                res += t.asString();
                }
        }
@@ -553,7 +556,7 @@ string Parser::parse_verbatim_item()
                                putback();
                                res += '{' + parse_verbatim_item() + '}';
                        }
-                       else 
+                       else
                                res += t.asString();
                }
        }
@@ -940,8 +943,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                }
 
                else if (t.cs() == "hline") {
-                       if (grid.asHullInset())
-                               grid.asHullInset()->rowinfo(cellrow + 1);
+                       grid.rowinfo(cellrow).lines_ ++;
                }
 
                else if (t.cs() == "sqrt") {
@@ -957,6 +959,12 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        }
                }
 
+               else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
+                       cell->push_back(createMathInset(t.cs()));
+                       parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
+                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+               }
+
                else if (t.cs() == "ref") {
                        cell->push_back(MathAtom(new RefInset));
                        parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
@@ -1016,6 +1024,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
                        }
 
+                       else if (name == "flalign" || name == "flalign*") {
+                               cell->push_back(MathAtom(new MathHullInset("flalign")));
+                               parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
+                       }
+
                        else if (name == "alignat" || name == "alignat*") {
                                // ignore this for a while
                                getArg('{', '}');
@@ -1067,7 +1080,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
 #warning A hack...
 #endif
                        string s;
-                       while (1) {
+                       while (true) {
                                Token const & t = getToken();
                                if (!good()) {
                                        putback();
@@ -1146,12 +1159,12 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        if (l) {
                                if (l->inset == "font") {
                                        cell->push_back(createMathInset(t.cs()));
-                                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
+                                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(mode, l->extra));
                                }
 
                                else if (l->inset == "oldfont") {
                                        cell->push_back(createMathInset(t.cs()));
-                                       parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
+                                       parse(cell->back().nucleus()->cell(0), flags, asMode(mode, l->extra));
                                        return;
                                }
 
@@ -1164,7 +1177,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                else if (l->inset == "parbox") {
                                        // read optional positioning and width
                                        string pos   = parse_verbatim_option();
-                                       string width = parse_verbatim_item();
+                                       string width = parse_verbatim_item();
                                        cell->push_back(createMathInset(t.cs()));
                                        parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
                                        cell->back().nucleus()->asParboxInset()->setPosition(pos);
@@ -1174,7 +1187,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                else {
                                        MathAtom at = createMathInset(t.cs());
                                        for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
-                                               parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
+                                               parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(mode, l->extra));
                                        cell->push_back(at);
                                }
                        }
@@ -1248,4 +1261,3 @@ void mathed_parse_normal(MathGridInset & grid, string const & str)
        istringstream is(str.c_str());
        Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);
 }
-