#include "frontends/Painter.h"
-#include "support/lassert.h"
#include "support/debug.h"
+#include "support/lassert.h"
+#include "support/textutils.h"
#include <ostream>
#include <vector>
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_;
}
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:
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;
}
// add space if there was no argument
if (first)
os.pendingSpace(true);
-
- os.pendingBrace(brace);
}