X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathMacro.cpp;h=5743dd0e452b2a12311d51b8a512a9d285f4f1f5;hb=fcd14df2306e0ee33c525da7997446c30c8dacd2;hp=bdf86258c710a06bfef8a272fa24b8088a097333;hpb=d6a7ec506eb4145f5a8108684222e77b695d21f9;p=features.git diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index bdf86258c7..5743dd0e45 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -142,7 +142,7 @@ public: void afterDraw(PainterInfo const & pi) const { if (mathMacro_->editMetrics(pi.base.bv)) - pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend); + pi.pain.enterMonochromeMode(Color_mathmacroblend); } /// void metrics(MetricsInfo &, Dimension &) const { @@ -206,7 +206,7 @@ public: expanded_(buf), definition_(buf), attachedArgsNum_(0), optionals_(0), nextFoldMode_(true), macroBackup_(buf), macro_(0), needsUpdate_(false), isUpdating_(false), - appetite_(9), nesting_(0) + appetite_(9), nesting_(0), limits_(AUTO_LIMITS) { } /// Update the pointers to our owner of all expanded macros. @@ -248,6 +248,8 @@ public: size_t appetite_; /// Level of nesting in macros (including this one) int nesting_; + /// + Limits limits_; }; @@ -371,6 +373,51 @@ bool InsetMathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const return has_contents; } + +/// Whether the inset allows \(no)limits +bool InsetMathMacro::allowsLimitsChange() const +{ + // similar to the code in mathClass(), except that we search for + // the right-side class. + MathClass mc = MC_UNKNOWN; + if (MacroData const * m = macroBackup()) { + // If it is a global macro and is defined explicitly + if (m->symbol()) + mc = string_to_class(m->symbol()->extra); + } + // Otherwise guess from the expanded macro + if (mc == MC_UNKNOWN) + mc = d->expanded_.lastMathClass(); + + return mc == MC_OP; +} + + +Limits InsetMathMacro::defaultLimits() const +{ + if (d->expanded_.empty()) + return NO_LIMITS; + // Guess from the expanded macro + InsetMath const * in = d->expanded_.back().nucleus(); + Limits const lim = in->limits() == AUTO_LIMITS + ? in->defaultLimits() : in->limits(); + LATTEST(lim != AUTO_LIMITS); + return lim; +} + + +Limits InsetMathMacro::limits() const +{ + return d->limits_; +} + + +void InsetMathMacro::limits(Limits lim) +{ + d->limits_ = lim; +} + + void InsetMathMacro::beforeMetrics() const { d->macro_->lock(); @@ -386,7 +433,7 @@ void InsetMathMacro::afterMetrics() const void InsetMathMacro::beforeDraw(PainterInfo const & pi) const { if (d->editing_[pi.base.bv]) - pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend); + pi.pain.enterMonochromeMode(Color_mathmacroblend); } @@ -744,7 +791,7 @@ void InsetMathMacro::draw(PainterInfo & pi, int x, int y) const pi.pain.text(x, y, from_ascii(":"), labelFont); x += strw2; - // draw paramter + // draw parameter cell(i).draw(pi, x, y); // next line @@ -920,7 +967,16 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const // validate the cells and the definition if (displayMode() == DISPLAY_NORMAL) { - d->definition_.validate(features); + // Don't update requirements if the macro comes from + // the symbols file and has not been redefined. + MathWordList const & words = mathedWordList(); + MathWordList::const_iterator it = words.find(name()); + MacroNameSet macros; + buffer().listMacroNames(macros); + if (it == words.end() || it->second.inset != "macro" + || macros.find(name()) != macros.end()) { + d->definition_.validate(features); + } InsetMathNest::validate(features); } } @@ -1155,6 +1211,9 @@ void InsetMathMacro::write(WriteStream & os) const // add space if there was no argument if (first) os.pendingSpace(true); + + // write \(no)limits modifiers if relevant + writeLimits(os); } @@ -1176,16 +1235,17 @@ void InsetMathMacro::mathematica(MathematicaStream & os) const } -void InsetMathMacro::mathmlize(MathStream & os) const +void InsetMathMacro::mathmlize(MathStream & ms) const { // macro_ is 0 if this is an unknown macro LATTEST(d->macro_ || d->displayMode_ != DISPLAY_NORMAL); if (d->macro_) { - docstring const xmlname = d->macro_->xmlname(); + docstring const xmlname = (ms.xmlMode()) ? d->macro_->xmlname() : d->macro_->htmlname(); if (!xmlname.empty()) { char const * type = d->macro_->MathMLtype(); - os << '<' << type << "> " << xmlname << " '; + ms << "<" << from_ascii(ms.namespacedTag(type)) << ">" + << xmlname + << ""; return; } } @@ -1193,7 +1253,7 @@ void InsetMathMacro::mathmlize(MathStream & os) const // this means that we do not recognize the macro throw MathExportException(); } - os << d->expanded_; + ms << d->expanded_; } @@ -1202,7 +1262,7 @@ void InsetMathMacro::htmlize(HtmlStream & os) const // macro_ is 0 if this is an unknown macro LATTEST(d->macro_ || d->displayMode_ != DISPLAY_NORMAL); if (d->macro_) { - docstring const xmlname = d->macro_->xmlname(); + docstring const xmlname = d->macro_->htmlname(); if (!xmlname.empty()) { os << ' ' << xmlname << ' '; return;