]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Substack should not be allowed to change columns
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 260d61ef8b2fac4e469fb6da070151a330b6aa81..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;
 }
 
 
@@ -1158,7 +1158,7 @@ void InsetMathGrid::normalize(NormalStream & os) const
 }
 
 
-void InsetMathGrid::mathmlize(MathStream & ms) const
+void InsetMathGrid::mathmlize(MathMLStream & ms) const
 {
        bool const havetable = nrows() > 1 || ncols() > 1;
        if (havetable)
@@ -1237,17 +1237,22 @@ void InsetMathGrid::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetMathGrid::write(WriteStream & os) const
+void InsetMathGrid::write(TeXMathStream & os) const
 {
        write(os, 0, 0, nrows(), ncols());
 }
 
-void InsetMathGrid::write(WriteStream & os,
-                         row_type beg_row, col_type beg_col,
-                         row_type end_row, col_type end_col) const
+void InsetMathGrid::write(TeXMathStream & os,
+                          row_type beg_row, col_type beg_col,
+                          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
+       bool const fragile = os.fragile()
+                       && !LaTeXFeatures::isAvailable("LaTeX-2021/06/01");
        for (row_type row = beg_row; row < end_row; ++row) {
                os << verboseHLine(rowinfo_[row].lines);
                // don't write & and empty cells at end of line,
@@ -1258,7 +1263,7 @@ void InsetMathGrid::write(WriteStream & os,
                for (col_type col = beg_col; col < end_col; ++col) {
                        idx_type const idx = index(row, col);
                        bool const empty_cell = cell(idx).empty();
-                       if (!empty_cell || cellinfo_[idx].multi != CELL_NORMAL)
+                       if (last_eoln && (!empty_cell || cellinfo_[idx].multi != CELL_NORMAL))
                                last_eoln = false;
                        if (!empty_cell || cellinfo_[idx].multi != CELL_NORMAL ||
                            colinfo_[col + 1].lines) {
@@ -1269,7 +1274,7 @@ void InsetMathGrid::write(WriteStream & os,
                for (col_type col = beg_col; col < end_col;) {
                        int nccols = 1;
                        idx_type const idx = index(row, col);
-                       TexRow::RowEntry entry = TexRow::mathEntry(id(),idx);
+                       TexRow::RowEntry const entry = TexRow::mathEntry(id(),idx);
                        os.texrow().start(entry);
                        if (col >= lastcol) {
                                ++col;
@@ -1294,19 +1299,18 @@ void InsetMathGrid::write(WriteStream & os,
                        os << eocString(col + nccols - 1, lastcol);
                        col += nccols;
                }
-               eol = eolString(row, os.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 (os.fragile())
+               if (eolstr.empty()) {
+                       if (fragile)
                                os << "\\protect";
                        os << "\\\\";
                }
@@ -1566,7 +1570,8 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        idocstringstream is(cmd.argument());
                        int n = 0;
                        is >> n;
-                       topaste = cap::selection(n, buffer().params().documentClassPtr());
+                       topaste = cap::selection(n, make_pair(buffer().params().documentClassPtr(),
+                                                             buffer().params().authors()), true);
                }
                InsetMathGrid grid(buffer_, 1, 1);
                if (!topaste.empty())