+MathClass MathMacro::mathClass() const
+{
+ // This can be just a heuristic, since it is only considered for display
+ // when the macro is not linearised. Therefore it affects:
+ // * The spacing of the inset while being edited,
+ // * Intelligent splitting
+ // * Cursor word movement (Ctrl-Arrow).
+ if (MacroData const * m = macroBackup()) {
+ // If it is a global macro and is defined explicitly
+ if (m->symbol()) {
+ MathClass mc = string_to_class(m->symbol()->extra);
+ if (mc != MC_UNKNOWN)
+ return mc;
+ }
+ }
+ // Otherwise guess from the expanded macro
+ return d->expanded_.mathClass();
+}
+
+
+InsetMath::mode_type MathMacro::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 MathMacro::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;
+ return UNDECIDED_MODE;
+}
+
+
+MacroData const * MathMacro::macroBackup() const
+{
+ if (macro())
+ return &d->macroBackup_;
+ if (MacroData const * data = MacroTable::globalMacros().get(name()))
+ return data;
+ return nullptr;
+}
+
+