]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
Attempt to fix #8137 (arrived at r40862).
[lyx.git] / src / mathed / MathParser.cpp
index 288a14a97d16cb1179ff04764736295b5f068cf8..b3f1bca76b64cabbfcb33b9f8d879503bc15aca3 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"
@@ -1384,6 +1385,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,13 +1828,15 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                error("'}' expected in \\" + t.cs());
                                return success_;
                        }
+                       bool termination;
                        docstring rem;
                        do {
                                cmd = Encodings::fromLaTeXCommand(cmd,
-                                       Encodings::MATH_CMD | Encodings::TEXT_CMD, rem);
+                                       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);
@@ -1914,9 +1925,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                                }
                                        }
                                        bool is_combining;
+                                       bool termination;
                                        char_type c = Encodings::fromLaTeXCommand(cmd,
                                                Encodings::MATH_CMD | Encodings::TEXT_CMD,
-                                               is_combining);
+                                               is_combining, termination);
                                        if (is_combining) {
                                                if (cat == catLetter)
                                                        cmd += '{';
@@ -1926,9 +1938,24 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                                        cmd += '}';
                                                c = Encodings::fromLaTeXCommand(cmd,
                                                        Encodings::MATH_CMD | Encodings::TEXT_CMD,
-                                                       is_combining);
+                                                       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 {