commit 25678dae120fd968eb2a21ff5e81324bcd5dc083
Author: Guillaume MM <g...@lyx.org>
Date:   Sun Oct 8 23:21:10 2017 +0200

    Fix math mode for InsetMathMacro on output
    
    After 6642152e, user macros were no longer wrapped in \ensuremath. In 2.2 
and
    before, InsetMathMacro behaved as follow:
    
    * Textmode global symbols are wrapped in \text when in math.
    
    * Other global symbols, and user macros, are wrapped in \ensuremath when in
      text.
    
    * Undefined macros (ERT) are wrapped neither in \text nor in \ensuremath.
    
    This is also consistent with the documentation of MathEnsurer in
    mathed/MathStream.h.
    
    This patch defines InsetMathMacro::currentMode() accordingly (respectively
    TEXT_MODE, MATH_MODE and UNDECIDED_MODE) and uses it to determine the 
output.
    
    After this patch, there is a mismatch between screen and pdf output for user
    macros in \text. This is not a regression wrt 2.2 and is because 
linearization
    does not satisfy currentMode() currently.
    
    (cherry picked from commit 767f0df18fcd61611de1d1e10e0fd1867479fb59)
---
 src/mathed/InsetMathMacro.cpp |   32 +++++++++++---------------------
 src/mathed/InsetMathMacro.h   |    5 +----
 2 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index d2d4a8b..3abd751 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -861,23 +861,15 @@ MathClass InsetMathMacro::mathClass() const
 
 InsetMath::mode_type InsetMathMacro::currentMode() const
 {
-       // There is no way to guess the mode of user defined macros, so they are
-       // always assumed to be mathmode.  Only the global macros defined in
-       // lib/symbols may be textmode.
-       mode_type mode = modeToEnsure();
-       return (mode == UNDECIDED_MODE) ? MATH_MODE : mode;
-}
-
-
-InsetMath::mode_type InsetMathMacro::modeToEnsure() const
-{
-       // User defined macros can be either text mode or math mode for output 
and
-       // display. There is no way to guess. For global macros defined in
-       // lib/symbols, we ensure textmode if flagged as such, otherwise we 
ensure
-       // math mode.
-       if (MacroData const * m = macroBackup())
-               if (m->symbol())
-                       return (m->symbol()->extra == "textmode") ? TEXT_MODE : 
MATH_MODE;
+       // User defined macros are always assumed to be mathmode macros.
+       // Only the global macros defined in lib/symbols may be textmode.
+       if (MacroData const * m = macroBackup()) {
+               if (m->symbol() && m->symbol()->extra == "textmode")
+                       return TEXT_MODE;
+               else
+                       return MATH_MODE;
+       }
+       // Unknown macros are undecided.
        return UNDECIDED_MODE;
 }
 
@@ -1069,10 +1061,8 @@ bool InsetMathMacro::folded() const
 
 void InsetMathMacro::write(WriteStream & os) const
 {
-       mode_type mode = modeToEnsure();
-       bool textmode_macro = mode == TEXT_MODE;
-       bool needs_mathmode = mode == MATH_MODE;
-       MathEnsurer ensurer(os, needs_mathmode, true, textmode_macro);
+       mode_type mode = currentMode();
+       MathEnsurer ensurer(os, mode == MATH_MODE, true, mode == TEXT_MODE);
 
        // non-normal mode
        if (d->displayMode_ != DISPLAY_NORMAL) {
diff --git a/src/mathed/InsetMathMacro.h b/src/mathed/InsetMathMacro.h
index 4267a2b..7880aa0 100644
--- a/src/mathed/InsetMathMacro.h
+++ b/src/mathed/InsetMathMacro.h
@@ -84,7 +84,7 @@ public:
        ///
        mode_type currentMode() const;
 
-       ///
+       /// Assumes that macros are up-to-date
        void write(WriteStream & os) const;
        ///
        void normalize(NormalStream & os) const;
@@ -172,9 +172,6 @@ protected:
        void attachArguments(std::vector<MathData> const & args, size_t arity, 
int optionals);
 
 private:
-       /// Math mode for output and display. UNDECIDED for user macros: they 
could
-       /// be either.
-       mode_type modeToEnsure() const;
        /// This function is needed for now because of two shortfalls of the 
current
        /// implementation: the macro() pointer is often dangling, in which 
case we
        /// fall back to a backup copy, and the macro is not known at inset

Reply via email to