]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacro.cpp
nullptr
[lyx.git] / src / mathed / InsetMathMacro.cpp
index 1e29fa54a68ff90ec8f5eaceacaa68b00312fd7c..d2c35c7e5bea913e1d857fc319871945de87d0db 100644 (file)
@@ -19,6 +19,7 @@
 #include "MathCompletionList.h"
 #include "MathExtern.h"
 #include "MathFactory.h"
+#include "MathRow.h"
 #include "MathStream.h"
 #include "MathSupport.h"
 
@@ -74,7 +75,7 @@ public:
        ///
        InsetMathMacro const * owner() { return mathMacro_; }
        ///
-       marker_type marker(BufferView const *) const override { return NO_MARKER; }
+       marker_type marker(BufferView const *) const override { return marker_type::NO_MARKER; }
        ///
        InsetCode lyxCode() const override { return ARGUMENT_PROXY_CODE; }
        /// The math data to use for display
@@ -168,7 +169,7 @@ public:
        ///
        void mathematica(MathematicaStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void mathmlize(MathStream & ms) const override { ms << mathMacro_->cell(idx_); }
+       void mathmlize(MathMLStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
        void htmlize(HtmlStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
@@ -352,7 +353,7 @@ bool InsetMathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 
        MathRow::Element e_beg(mi, MathRow::BEGIN);
        e_beg.inset = this;
-       e_beg.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : NO_MARKER;
+       e_beg.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : marker_type::NO_MARKER;
        mrow.push_back(e_beg);
 
        d->macro_->lock();
@@ -371,7 +372,7 @@ bool InsetMathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 
        MathRow::Element e_end(mi, MathRow::END);
        e_end.inset = this;
-       e_end.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : NO_MARKER;
+       e_end.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : marker_type::NO_MARKER;
        mrow.push_back(e_end);
 
        return has_contents;
@@ -397,14 +398,14 @@ bool InsetMathMacro::allowsLimitsChange() const
 }
 
 
-Limits InsetMathMacro::defaultLimits() const
+Limits InsetMathMacro::defaultLimits(bool display) 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();
+               ? in->defaultLimits(display) : in->limits();
        LATTEST(lim != AUTO_LIMITS);
        return lim;
 }
@@ -544,29 +545,29 @@ bool InsetMathMacro::editMetrics(BufferView const * bv) const
 }
 
 
-InsetMath::marker_type InsetMathMacro::marker(BufferView const * bv) const
+marker_type InsetMathMacro::marker(BufferView const * bv) const
 {
        if (nargs() == 0)
-               return NO_MARKER;
+               return marker_type::NO_MARKER;
 
        switch (d->displayMode_) {
        case DISPLAY_INIT:
        case DISPLAY_INTERACTIVE_INIT:
-               return NO_MARKER;
+               return marker_type::NO_MARKER;
        case DISPLAY_UNFOLDED:
-               return MARKER;
+               return marker_type::MARKER;
        case DISPLAY_NORMAL:
                switch (lyxrc.macro_edit_style) {
                case LyXRC::MACRO_EDIT_INLINE:
-                       return MARKER2;
+                       return marker_type::MARKER2;
                case LyXRC::MACRO_EDIT_INLINE_BOX:
-                       return d->editing_[bv] ? BOX_MARKER : MARKER2;
+                       return d->editing_[bv] ? marker_type::BOX_MARKER : marker_type::MARKER2;
                case LyXRC::MACRO_EDIT_LIST:
-                       return MARKER2;
+                       return marker_type::MARKER2;
                }
        }
        // please gcc 4.6
-       return NO_MARKER;
+       return marker_type::NO_MARKER;
 }
 
 
@@ -1132,7 +1133,7 @@ bool InsetMathMacro::folded() const
 }
 
 
-void InsetMathMacro::write(WriteStream & os) const
+void InsetMathMacro::write(TeXMathStream & os) const
 {
        mode_type mode = currentMode();
        MathEnsurer ensurer(os, mode == MATH_MODE, true, mode == TEXT_MODE);
@@ -1213,8 +1214,11 @@ void InsetMathMacro::write(WriteStream & os) const
        }
 
        // add space if there was no argument
-       if (first)
+       // or add braces if we have optionals but none are present and [ follows
+       if (first) {
                os.pendingSpace(true);
+               os.useBraces(d->optionals_ > 0);
+       }
 
        // write \(no)limits modifiers if relevant
        writeLimits(os);
@@ -1239,7 +1243,7 @@ void InsetMathMacro::mathematica(MathematicaStream & os) const
 }
 
 
-void InsetMathMacro::mathmlize(MathStream & ms) const
+void InsetMathMacro::mathmlize(MathMLStream & ms) const
 {
        // macro_ is 0 if this is an unknown macro
        LATTEST(d->macro_ || d->displayMode_ != DISPLAY_NORMAL);