diff --git a/src/mathed/InsetMathPhantom.cpp b/src/mathed/InsetMathPhantom.cpp index bbc2234a18..cd4ae451cf 100644 --- a/src/mathed/InsetMathPhantom.cpp +++ b/src/mathed/InsetMathPhantom.cpp @@ -240,6 +240,8 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const void InsetMathPhantom::write(WriteStream & os) const { MathEnsurer ensurer(os); + if (os.fragile()) + os << "\\protect"; switch (kind_) { case phantom: os << "\\phantom{"; diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index fe6e9188b0..2f0241b5ac 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -707,8 +707,8 @@ void MathMacro::write(WriteStream & os) const // we should be ok to continue even if this fails. LATTEST(macro_); - // optional arguments make macros fragile - if (optionals_ > 0 && os.fragile()) + // Always protect macros in a fragile environment + if (os.fragile()) os << "\\protect"; os << "\\" << name();