Rename eolString() to eol() and pass a MathTeXStream parameter

This is completely equivalent, but will allow in eol() to determine
whether one is preparing a preview.

Related to bug #11535.
This commit is contained in:
Jean-Marc Lasgouttes 2022-07-25 22:02:59 +02:00
parent 01da93521d
commit a42f7ea7cd
5 changed files with 18 additions and 21 deletions

View 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(); }

View 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 << "\\\\";

View 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

View 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

View 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;