]> git.lyx.org Git - features.git/commitdiff
Rename eolString() to eol() and pass a MathTeXStream parameter
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 25 Jul 2022 20:02:59 +0000 (22:02 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 26 Jul 2022 20:21:44 +0000 (22:21 +0200)
This is completely equivalent, but will allow in eol() to determine
whether one is preparing a preview.

Related to bug #11535.

src/mathed/InsetMathEnsureMath.h
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathHull.h

index d0a60d036b0c3c7fbd2501cd0ca485276b881bbc..40efe73cd366bbf48e09d7f21faa32cc98211dff 100644 (file)
@@ -44,8 +44,7 @@ public:
        ///
        void delCol(col_type) override {}
        ///
-       docstring eolString(row_type, bool, bool, bool) const override
-       { return docstring(); }
+       void eol(TeXMathStream &, row_type, bool, bool, bool) const override {}
        ///
        docstring eocString(col_type, col_type) const override
        { return docstring(); }
index 96ec13b954b67ee9806a37e08cc0d4aba7491e6a..85511e6ddfad4af59d26c1dd50bd3af42506430e 100644 (file)
@@ -750,7 +750,7 @@ void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype, bool
 }
 
 
-docstring InsetMathGrid::eolString(row_type row, bool fragile,
+void InsetMathGrid::eol(TeXMathStream & os, row_type row, bool fragile,
                bool /*latex*/, bool last_eoln) const
 {
        docstring eol;
@@ -770,9 +770,9 @@ docstring InsetMathGrid::eolString(row_type row, bool fragile,
 
        // only add \\ if necessary
        if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
-               return docstring();
+               return;
 
-       return (fragile ? "\\protect\\\\" : "\\\\") + eol;
+       os << (fragile ? "\\protect\\\\" : "\\\\") << eol;
 }
 
 
@@ -1247,7 +1247,7 @@ void InsetMathGrid::write(TeXMathStream & os,
                           row_type end_row, col_type end_col) const
 {
        MathEnsurer ensurer(os, false);
-       docstring eol;
+       docstring eolstr;
        // As of 2018 (with amendment in LaTeX 2021/06),
        // \\ is a robust command and its protection
        // is no longer necessary
@@ -1299,18 +1299,17 @@ void InsetMathGrid::write(TeXMathStream & os,
                        os << eocString(col + nccols - 1, lastcol);
                        col += nccols;
                }
-               eol = eolString(row, fragile, os.latex(), last_eoln);
-               os << eol;
+               eol(os, row, fragile, os.latex(), last_eoln);
                // append newline only if line wasn't completely empty
                // and the formula is not written on a single line
-               bool const empty = emptyline && eol.empty();
+               bool const empty = emptyline && eolstr.empty();
                if (!empty && nrows() > 1)
                        os << "\n";
        }
        // @TODO use end_row instead of nrows() ?
        docstring const s = verboseHLine(rowinfo_[nrows()].lines);
        if (!s.empty()) {
-               if (eol.empty()) {
+               if (eolstr.empty()) {
                        if (fragile)
                                os << "\\protect";
                        os << "\\\\";
index ce8a8524011c44b60d614589bc2d8caf93b5c40f..ae95eaf0957086e79c34662bf71e8c89c8a3c9d2 100644 (file)
@@ -246,8 +246,8 @@ protected:
        virtual int rightMargin() const { return 0; }
 
        /// returns proper 'end of line' code for LaTeX
-       virtual docstring eolString(row_type row, bool fragile, bool latex,
-                       bool last_eoln) const;
+       virtual void eol(TeXMathStream & os, row_type row, bool fragile, bool latex,
+                        bool last_eoln) const;
        /// returns proper 'end of column' code for LaTeX
        virtual docstring eocString(col_type col, col_type lastcol) const;
        /// splits cells and shifts right part to the next cell
index 689950d53ecdaec882c7e36e5c83d7e79098ffa0..8ede26063284c30f2b9b72ae3946df15e8358de6 100644 (file)
@@ -1680,27 +1680,26 @@ void InsetMathHull::mutate(HullType newtype)
 }
 
 
-docstring InsetMathHull::eolString(row_type row, bool fragile, bool latex,
-               bool last_eoln) const
+void InsetMathHull::eol(TeXMathStream & os, row_type row, bool fragile, bool latex,
+                        bool last_eoln) const
 {
-       docstring res;
        if (numberedType()) {
                if (label_[row]) {
                        docstring const name =
                                latex ? escape(label_[row]->getParam("name"))
                                      : label_[row]->getParam("name");
-                       res += "\\label{" + name + '}';
+                       os << "\\label{" + name + '}';
                }
                if (type_ != hullMultline) {
                        if (numbered_[row]  == NONUMBER)
-                               res += "\\nonumber ";
+                               os << "\\nonumber ";
                        else if (numbered_[row]  == NOTAG)
-                               res += "\\notag ";
+                               os<< "\\notag ";
                }
        }
        // Never add \\ on the last empty line of eqnarray and friends
        last_eoln = false;
-       return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
+       InsetMathGrid::eol(os, row, fragile, latex, last_eoln);
 }
 
 void InsetMathHull::write(TeXMathStream & os) const
index b0191886e4fb2241523f6cc9c45f3b250f0110e7..52e8177631cf93f738cf4b0da6e47e95d1fde036 100644 (file)
@@ -202,8 +202,8 @@ protected:
        /// override to set to 0 for inline equation
        int border() const override;
        ///
-       docstring eolString(row_type row, bool fragile, bool latex,
-                       bool last_eoln) const override;
+       void eol(TeXMathStream & os, row_type row, bool fragile, bool latex,
+                bool last_eoln) const override;
 
 private:
        Inset * clone() const override;