#include <config.h>
#include "MathMacro.h"
-#include "MathSupport.h"
+
+#include "MathCompletionList.h"
#include "MathExtern.h"
#include "MathStream.h"
+#include "MathSupport.h"
#include "Buffer.h"
#include "BufferView.h"
#include "frontends/Painter.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_;
}
&& editing_[mi.base.bv]) {
// Macro will be edited in a old-style list mode here:
- BOOST_ASSERT(macro_ != 0);
+ LASSERT(macro_ != 0, /**/);
Dimension fontDim;
FontInfo labelFont = sane_font;
math_font_max_dim(labelFont, fontDim.asc, fontDim.des);
dim.wid += 2;
metricsMarkers2(dim);
} else {
- BOOST_ASSERT(macro_ != 0);
+ LASSERT(macro_ != 0, /**/);
// metrics are computed here for the cells,
// in the proxy we will then use the dim from the cache
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:
if (name() == "binom" || name() == "mathcircumflex")
features.require(to_utf8(name()));
+
+ // validate the cells and the definition
+ if (displayMode() == DISPLAY_NORMAL) {
+ definition_.validate(features);
+ InsetMathNest::validate(features);
+ }
}
void MathMacro::removeArgument(Inset::pos_type pos) {
if (displayMode_ == DISPLAY_NORMAL) {
- BOOST_ASSERT(size_t(pos) < cells_.size());
+ LASSERT(size_t(pos) < cells_.size(), /**/);
cells_.erase(cells_.begin() + pos);
if (size_t(pos) < attachedArgsNum_)
--attachedArgsNum_;
void MathMacro::insertArgument(Inset::pos_type pos) {
if (displayMode_ == DISPLAY_NORMAL) {
- BOOST_ASSERT(size_t(pos) <= cells_.size());
+ LASSERT(size_t(pos) <= cells_.size(), /**/);
cells_.insert(cells_.begin() + pos, MathData());
if (size_t(pos) < attachedArgsNum_)
++attachedArgsNum_;
void MathMacro::detachArguments(vector<MathData> & args, bool strip)
{
- BOOST_ASSERT(displayMode_ == DISPLAY_NORMAL);
+ LASSERT(displayMode_ == DISPLAY_NORMAL, /**/);
args = cells_;
// strip off empty cells, but not more than arity-attachedArgsNum_
void MathMacro::attachArguments(vector<MathData> const & args, size_t arity, int optionals)
{
- BOOST_ASSERT(displayMode_ == DISPLAY_NORMAL);
+ LASSERT(displayMode_ == DISPLAY_NORMAL, /**/);
cells_ = args;
attachedArgsNum_ = args.size();
cells_.resize(arity);
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;
}
// normal mode
- BOOST_ASSERT(macro_);
+ LASSERT(macro_, /**/);
// optional arguments make macros fragile
if (optionals_ > 0 && os.fragile())
}
-Inset::CompletionList const *
+CompletionList const *
MathMacro::createCompletionList(Cursor const & cur) const
{
if (displayMode() != DISPLAY_UNFOLDED)