]> git.lyx.org Git - features.git/commitdiff
Fix bug #10581
authorEnrico Forestieri <forenr@lyx.org>
Sun, 2 Apr 2017 22:26:49 +0000 (00:26 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 2 Apr 2017 22:26:49 +0000 (00:26 +0200)
Tell the math parser that we are parsing a macro definition, so that
it doesn't try to return a verbatim copy in case of failure.

src/mathed/MacroTable.cpp
src/mathed/MathMacro.cpp
src/mathed/MathParser.cpp
src/mathed/MathParser_flags.h
src/mathed/MathSupport.cpp

index d23855c511f5bd3fadd26661f81fc2d0b97a9abf..2899e40c2e7e75b76d55d5ef040ecd83a6b9fab5 100644 (file)
@@ -71,7 +71,7 @@ bool MacroData::expand(vector<MathData> const & args, MathData & to) const
        InsetMathSqrt inset(const_cast<Buffer *>(buffer_));
 
        docstring const & definition(display_.empty() ? definition_ : display_);
-       asArray(definition, inset.cell(0), Parse::QUIET);
+       asArray(definition, inset.cell(0), Parse::QUIET | Parse::MACRODEF);
        //lyxerr << "MathData::expand: args: " << args << endl;
        //LYXERR0("MathData::expand: ar: " << inset.cell(0));
        for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) {
index 8f16e2b696a986f8a286e70c1ea2cff061da6f57..4bd14d6b72e4d971ccb53af371fd90404a282d01 100644 (file)
@@ -672,7 +672,7 @@ void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
        // get definition for list edit mode
        docstring const & display = d->macro_->display();
        asArray(display.empty() ? d->macro_->definition() : display,
-               d->definition_, Parse::QUIET);
+               d->definition_, Parse::QUIET | Parse::MACRODEF);
 }
 
 
index ace167c439608455f732a80db037f7084ec610cc..9bc5ff9362bbd8514eec8b83610ef2c9bcc05abb 100644 (file)
@@ -1757,7 +1757,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                        else {
                                success_ = false;
-                               if (!(mode_ & Parse::QUIET)) {
+                               if (!(mode_ & Parse::QUIET) &&
+                                   !(mode_ & Parse::TRACKMACRO)) {
                                        dump();
                                        lyxerr << "found unknown math environment '"
                                               << to_utf8(name) << "'" << endl;
index 9c9c4a3b95e7f204f27d5ed3adca3552655fdb03..fa9501abe3a0c65d5ba3cc2ef527a65619dbb3ed 100644 (file)
@@ -28,7 +28,9 @@ enum flags {
        /// Wrap unicode symbols in \text{}.
        USETEXT = 0x08,
        /// Track macro creation while loading a document
-       TRACKMACRO = 0x10
+       TRACKMACRO = 0x10,
+       /// Parse a macro definition
+       MACRODEF = 0x20
 };
 
 
index 1c4f89ca8dc9dcf69695303a1605c068715d8c5a..086d219c56f95cfc2bdf1e980d47c4bd8f450daf 100644 (file)
@@ -961,8 +961,13 @@ docstring asString(MathData const & ar)
 
 void asArray(docstring const & str, MathData & ar, Parse::flags pf)
 {
+       // If the QUIET flag is set, we are going to parse for either
+       // a paste operation or a macro definition. We try to do the
+       // right thing in all cases.
+
        bool quiet = pf & Parse::QUIET;
-       if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet))
+       bool macro = pf & Parse::MACRODEF;
+       if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet && !macro))
                mathed_parse_cell(ar, str, pf | Parse::VERBATIM);
 }