]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacro.cpp
InsetMathHull.cpp: whitespace
[lyx.git] / src / mathed / MathMacro.cpp
index 339719483b89e533a83743e527165d4a5555ae7e..ca3ec2298dd5ef28de987e93d728c980267671bb 100644 (file)
@@ -32,8 +32,9 @@
 
 #include "frontends/Painter.h"
 
-#include "support/lassert.h"
 #include "support/debug.h"
+#include "support/lassert.h"
+#include "support/textutils.h"
 
 #include <ostream>
 #include <vector>
@@ -132,10 +133,11 @@ Inset * MathMacro::clone() const
 
 docstring MathMacro::name() const
 {
-       if (displayMode_ == DISPLAY_UNFOLDED)
+       if (displayMode_ == DISPLAY_UNFOLDED
+           && (name_.size() > 1 || (name_[0] != '_' && name_[0] != '^')))
                return asString(cell(0));
-       else
-               return name_;
+
+       return name_;
 }
 
 
@@ -336,18 +338,14 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
        int expy = y;
 
        if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {         
-               PainterInfo pi2(pi.base.bv, pi.pain);
-               pi2.base.font.setColor(macro_ ? Color_latex : Color_error);
-               //pi2.base.style = LM_ST_TEXT;
-               pi2.pain.text(x, y, from_ascii("\\") + name(), pi2.base.font);
+               FontSetChanger dummy(pi.base, "lyxtex");
+               pi.pain.text(x, y, from_ascii("\\") + name(), pi.base.font);
        } else if (displayMode_ == DISPLAY_UNFOLDED) {
-               PainterInfo pi2(pi.base.bv, pi.pain);
-               pi2.base.font.setColor(macro_ ? Color_latex : Color_error);
-               //pi2.base.style = LM_ST_TEXT;
-               pi2.pain.text(x, y, from_ascii("\\"), pi2.base.font);
-               x += mathed_string_width(pi2.base.font, from_ascii("\\")) + 1;
-               cell(0).draw(pi2, x, y);
-               drawMarkers(pi2, expx, expy);
+               FontSetChanger dummy(pi.base, "lyxtex");
+               pi.pain.text(x, y, from_ascii("\\"), pi.base.font);
+               x += mathed_string_width(pi.base.font, from_ascii("\\")) + 1;
+               cell(0).draw(pi, x, y);
+               drawMarkers(pi, expx, expy);
        } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
                   && editing_[pi.base.bv]) {
                // Macro will be edited in a old-style list mode here:
@@ -655,27 +653,13 @@ bool MathMacro::folded() const
 
 void MathMacro::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-        os.pendingBrace(false);
-       if (os.latex()) {
-               if (os.textMode() && macro_) {
-                       // This is for sure a math macro
-                       os << "\\ensuremath{";
-                       os.textMode(false);
-                       brace = true;
-               } else if (brace && !macro_) {
-                       // Cannot tell, so don't mess with the mode
-                       os << '}';
-                       os.textMode(true);
-                       brace = false;
-               }
-        }
+       MathEnsurer ensurer(os, macro_ != 0, true);
 
        // non-normal mode
        if (displayMode_ != DISPLAY_NORMAL) {
                os << "\\" << name();
-               os.pendingSpace(true);
-               os.pendingBrace(brace);
+               if (name().size() != 1 || isAlphaASCII(name()[0]))
+                       os.pendingSpace(true);
                return;
        }
 
@@ -722,8 +706,6 @@ void MathMacro::write(WriteStream & os) const
        // add space if there was no argument
        if (first)
                os.pendingSpace(true);
-
-       os.pendingBrace(brace);
 }