]> git.lyx.org Git - features.git/commitdiff
Fix bug #11595
authorEnrico Forestieri <forenr@lyx.org>
Sun, 9 Jun 2019 20:35:05 +0000 (22:35 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:33 +0000 (15:48 +0200)
Avoid an endless loop when in the definition of a macro the macro
itself is used in the LyX representation part.

src/mathed/InsetMathMacro.cpp

index 5269df005f36edc67c4e929959dbc413e3f23efa..5e72eecdc27850b4737e833593b420df9f9f4bdb 100644 (file)
@@ -661,17 +661,20 @@ void InsetMathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
                values[i].insert(0, MathAtom(proxy));
        }
        // expanding macro with the values
-       // Only update the argument macros if anything was expanded, otherwise
-       // we would get an endless loop (bug 9140). UpdateLocker does not work
-       // in this case, since MacroData::expand() creates new InsetMathMacro
-       // objects, so this would be a different recursion path than the one
-       // protected by UpdateLocker.
-       if (d->macro_->expand(values, d->expanded_)) {
+       // Only update the argument macros if anything was expanded or the LyX
+       // representation part does not contain the macro itself, otherwise we
+       // would get an endless loop (bugs 9140 and 11595). UpdateLocker does
+       // not work in this case, since MacroData::expand() creates new
+       // InsetMathMacro objects, so this would be a different recursion path
+       // than the one protected by UpdateLocker.
+       docstring const & display = d->macro_->display();
+       docstring const latexname = from_ascii("\\") + macroName();
+       if (d->macro_->expand(values, d->expanded_)
+           && !support::contains(display, latexname)) {
                if (utype == OutputUpdate && !d->expanded_.empty())
                        d->expanded_.updateMacros(cur, mc, utype, nesting);
        }
        // get definition for list edit mode
-       docstring const & display = d->macro_->display();
        asArray(display.empty() ? d->macro_->definition() : display,
                d->definition_, Parse::QUIET | Parse::MACRODEF);
 }