]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
Add \makeat switches to babel settings if necessary.
[lyx.git] / src / mathed / MathParser.cpp
index d5724fdb893a39d60d83ea6751e9c8f5ddcc49b8..9752320095312a75ff1b857d007ee0e679b50c27 100644 (file)
@@ -42,6 +42,7 @@ following hack as starting point to write some macros:
 #include "InsetMathArray.h"
 #include "InsetMathBig.h"
 #include "InsetMathBrace.h"
+#include "InsetMathCancelto.h"
 #include "InsetMathChar.h"
 #include "InsetMathColor.h"
 #include "InsetMathComment.h"
@@ -535,7 +536,6 @@ char_type Parser::getChar()
 {
        if (!good()) {
                error("The input stream is not well...");
-               putback();
                return 0;
        }
        return tokens_[pos_++].character();
@@ -544,9 +544,12 @@ char_type Parser::getChar()
 
 docstring Parser::getArg(char_type left, char_type right)
 {
+       docstring result;
        skipSpaces();
 
-       docstring result;
+       if (!good())
+               return result;
+
        char_type c = getChar();
 
        if (c != left)
@@ -914,7 +917,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                }
 
                else if (t.cat() == catActive)
-                       cell->push_back(MathAtom(new InsetMathChar(t.character())));
+                       cell->push_back(MathAtom(new InsetMathSpace(string(1, t.character()), "")));
 
                else if (t.cat() == catBegin) {
                        MathData ar;
@@ -1015,7 +1018,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                Token const & t = getToken();
                                if (t.cat() == catNewline)
                                        break;
-                               s += t.asString();
+                               s += t.asInput();
                        }
                        cell->push_back(MathAtom(new InsetMathComment(buf, s)));
                        skipSpaces();
@@ -1384,6 +1387,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        }
                }
 
+               else if (t.cs() == "cancelto") {
+                       MathData ar;
+                       parse(ar, FLAG_ITEM, mode);
+                               cell->push_back(MathAtom(new InsetMathCancelto(buf)));
+                               cell->back().nucleus()->cell(1) = ar;
+                               parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+               }
+
                else if (t.cs() == "unit") {
                        // Allowed formats \unit[val]{unit}
                        MathData ar;
@@ -1819,12 +1830,15 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                error("'}' expected in \\" + t.cs());
                                return success_;
                        }
+                       bool termination;
                        docstring rem;
                        do {
-                               cmd = Encodings::fromLaTeXCommand(cmd, rem);
+                               cmd = Encodings::fromLaTeXCommand(cmd,
+                                       Encodings::MATH_CMD | Encodings::TEXT_CMD,
+                                       termination, rem);
                                for (size_t i = 0; i < cmd.size(); ++i)
                                        cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
-                               if (rem.size()) {
+                               if (!rem.empty()) {
                                        char_type c = rem[0];
                                        cell->push_back(MathAtom(new InsetMathChar(c)));
                                        cmd = rem.substr(1);
@@ -1837,7 +1851,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                else if (t.cs().size()) {
                        bool const no_mhchem =
                                (t.cs() == "ce" || t.cs() == "cf")
-                               && buf && buf->params().use_mhchem ==
+                               && buf && buf->params().use_package("mhchem") ==
                                                BufferParams::package_off;
 
                        bool const is_user_macro = no_mhchem ||
@@ -1913,8 +1927,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                                }
                                        }
                                        bool is_combining;
-                                       char_type c =
-                                               Encodings::fromLaTeXCommand(cmd, is_combining);
+                                       bool termination;
+                                       char_type c = Encodings::fromLaTeXCommand(cmd,
+                                               Encodings::MATH_CMD | Encodings::TEXT_CMD,
+                                               is_combining, termination);
                                        if (is_combining) {
                                                if (cat == catLetter)
                                                        cmd += '{';
@@ -1922,9 +1938,26 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                                ++num_tokens;
                                                if (cat == catLetter)
                                                        cmd += '}';
-                                               c = Encodings::fromLaTeXCommand(cmd, is_combining);
+                                               c = Encodings::fromLaTeXCommand(cmd,
+                                                       Encodings::MATH_CMD | Encodings::TEXT_CMD,
+                                                       is_combining, termination);
                                        }
                                        if (c) {
+                                               if (termination) {
+                                                       if (nextToken().cat() == catBegin) {
+                                                               getToken();
+                                                               if (nextToken().cat() == catEnd) {
+                                                                       getToken();
+                                                                       num_tokens += 2;
+                                                               } else
+                                                                       putback();
+                                                       } else {
+                                                               while (nextToken().cat() == catSpace) {
+                                                                       getToken();
+                                                                       ++num_tokens;
+                                                               }
+                                                       }
+                                               }
                                                is_unicode_symbol = true;
                                                cell->push_back(MathAtom(new InsetMathChar(c)));
                                        } else {