]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
Move <algorithm> from DocIterator.h
[lyx.git] / src / mathed / InsetMathHull.cpp
index cb6cec53fb09dfd8413f6c6597ef20b8396790d3..ebf8843d7939a07191a902dcb5523c7df4e23b26 100644 (file)
@@ -228,8 +228,8 @@ InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other)
 
 InsetMathHull::~InsetMathHull()
 {
-       for (size_t i = 0; i < label_.size(); ++i)
-               delete label_[i];
+       for (auto & i : label_)
+               delete i;
 }
 
 
@@ -248,8 +248,8 @@ InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
        numbered_ = other.numbered_;
        numbers_ = other.numbers_;
        buffer_ = other.buffer_;
-       for (size_t i = 0; i < label_.size(); ++i)
-               delete label_[i];
+       for (auto & i : label_)
+               delete i;
        label_ = other.label_;
        for (size_t i = 0; i != label_.size(); ++i) {
                if (label_[i])
@@ -995,8 +995,8 @@ bool InsetMathHull::ams() const
        case hullEqnArray:
                break;
        }
-       for (size_t row = 0; row < numbered_.size(); ++row)
-               if (numbered_[row] == NOTAG)
+       for (auto const & row : numbered_)
+               if (row == NOTAG)
                        return true;
        return false;
 }
@@ -1579,7 +1579,7 @@ void InsetMathHull::mutate(HullType newtype)
                        numbered(0, false);
                } else {
                        setType(hullEquation);
-                       numbered(0, label_[0] ? true : false);
+                       numbered(0, label_[0] != nullptr);
                        mutate(newtype);
                }
                break;
@@ -2418,12 +2418,16 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 {
        // Choose the tag around the MathML equation.
        docstring name;
+       bool doCR = false;
        if (getType() == hullSimple)
                name = from_ascii("inlineequation");
-       else
+       else {
+               doCR = true; // This is a block equation, always have <informalequation> on its own line.
                name = from_ascii("informalequation");
+       }
 
        // DocBook also has <equation>, but it comes with a title.
+       // TODO: recognise \tag from amsmath? This would allow having <equation> with a proper title.
 
        docstring attr;
        for (row_type i = 0; i < nrows(); ++i) {
@@ -2433,6 +2437,10 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
                }
        }
 
+       if (doCR)
+               if (!xs.isLastTagCR())
+                       xs << xml::CR();
+
        xs << xml::StartTag(name, attr);
        xs << xml::CR();
 
@@ -2471,13 +2479,16 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
                osmath << ostmp.str(); // osmath is not a XMLStream, so no need for XMLStream::ESCAPE_NONE.
                ms << ETag("math");
        } catch (MathExportException const &) {
-               osmath << "MathML export failed. Please report this as a bug.";
+               ms.cr();
+               osmath << "<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>";
        }
 
        // Output the complete formula to the DocBook stream.
        xs << XMLStream::ESCAPE_NONE << osmath.str();
        xs << xml::CR();
        xs << xml::EndTag(name);
+       if (doCR)
+               xs << xml::CR();
 }