]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacro.cpp
InsetMathHull.cpp: whitespace
[lyx.git] / src / mathed / MathMacro.cpp
index bf6132630a7f60b0721c0c810768b77a3eee0094..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,10 +653,13 @@ bool MathMacro::folded() const
 
 void MathMacro::write(WriteStream & os) const
 {
+       MathEnsurer ensurer(os, macro_ != 0, true);
+
        // non-normal mode
        if (displayMode_ != DISPLAY_NORMAL) {
-               os << "\\" << name() << " ";
-               os.pendingSpace(true);
+               os << "\\" << name();
+               if (name().size() != 1 || isAlphaASCII(name()[0]))
+                       os.pendingSpace(true);
                return;
        }