commit 129459a71b52babb1a8e5a1e3de986976c93bde6 Author: Enrico Forestieri <for...@lyx.org> Date: Tue Oct 18 03:29:53 2016 +0200
Take into account font changes when striking out display math formulas Font changes are brought inside the \lyxdeleted macro, just before outputting the latex code for the math inset. The inset writes a signature before itself and this is checked by \lyxsout for recognizing a display math. So, the font changes confuse \lyxsout, which also swallows the first macro at the very start of \lyxdeleted. The result is that the font changing command is not seen by latex and \sout is also used to further strike out the formula already striked out by tikz. This commit makes sure that the expected signature actually appears just after the opening brace of \lyxdeleted. It also accounts for a paragraph break occurring just before the math inset, in order to not introduce too much vertical space, which is noticeable when using larger font sizes. --- src/Changes.cpp | 15 ++++++++++++++- src/OutputParams.cpp | 2 +- src/OutputParams.h | 5 +++++ src/Paragraph.cpp | 20 ++++++++++++++++++++ src/mathed/InsetMathHull.cpp | 12 ++++-------- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/Changes.cpp b/src/Changes.cpp index 0d464d8..c66668a 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -428,8 +428,10 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, // close \lyxadded or \lyxdeleted os << '}'; column++; - if (oldChange.type == Change::DELETED) + if (oldChange.type == Change::DELETED) { --runparams.inulemcmd; + runparams.inDisplayMath = false; + } } docstring chgTime; @@ -449,6 +451,17 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, bparams.authors().get(change.author).name(), chgTime, runparams); + // signature needed by \lyxsout to correctly strike out display math + if (change.type == Change::DELETED && runparams.inDisplayMath + && (!LaTeXFeatures::isAvailable("dvipost") + || (runparams.flavor != OutputParams::LATEX + && runparams.flavor != OutputParams::DVILUATEX))) { + if (os.afterParbreak()) + str += from_ascii("\\\\\\noindent\n"); + else + str += from_ascii("\\\\\\mbox{}\\\\\n"); + } + os << str; column += str.size(); diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 20c3a65..1633cf3 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -23,7 +23,7 @@ OutputParams::OutputParams(Encoding const * enc) moving_arg(false), intitle(false), inulemcmd(0), local_font(0), master_language(0), encoding(enc), free_spacing(false), use_babel(false), use_polyglossia(false), use_indices(false), use_japanese(false), linelen(0), depth(0), - exportdata(new ExportData), + exportdata(new ExportData), inDisplayMath(false), inComment(false), inTableCell(NO), inFloat(NONFLOAT), inIndexEntry(false), inIPA(false), inDeletedInset(0), changeOfDeletedInset(Change::UNCHANGED), diff --git a/src/OutputParams.h b/src/OutputParams.h index 3914617..4534b22 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -185,6 +185,11 @@ public: */ std::shared_ptr<ExportData> exportdata; + /** Whether we are inside a display math inset. + * Needed to correctly strike out deleted math in change tracking. + */ + mutable bool inDisplayMath; + /** Whether we are inside a comment inset. Insets that are including * external files like InsetGraphics, InsetInclude and InsetExternal * may only write the usual output and must not attempt to do diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index ce95ad8..90b5eef 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -53,6 +53,8 @@ #include "insets/InsetLabel.h" #include "insets/InsetSpecialChar.h" +#include "mathed/InsetMathHull.h" + #include "support/debug.h" #include "support/docstring_list.h" #include "support/ExceptionMessage.h" @@ -2399,6 +2401,24 @@ void Paragraph::latex(BufferParams const & bparams, basefont = getLayoutFont(bparams, outerfont); running_font = basefont; + // Check whether a display math inset follows + if (d->text_[i] == META_INSET + && i >= start_pos && (end_pos == -1 || i < end_pos)) { + InsetMath const * im = getInset(i)->asInsetMath(); + if (im && im->asHullInset()) { + switch (im->asHullInset()->getType()) { + case hullEquation: + case hullEqnArray: + case hullAlign: + case hullFlAlign: + case hullGather: + case hullMultline: + runparams.inDisplayMath = true; + break; + } + } + } + column += Changes::latexMarkChange(os, bparams, runningChange, change, runparams); runningChange = change; diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 8bc6779..eab42b0 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1021,10 +1021,8 @@ void InsetMathHull::header_write(WriteStream & os) const break; case hullEquation: - if (os.strikeoutMath()) { - os << "\\\\\\mbox{}\\\\\n" - << "\\lyxmathsout{\\parbox{\\columnwidth}{"; - } + if (os.strikeoutMath()) + os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; os << "\n"; os.startOuterRow(); if (n) @@ -1038,10 +1036,8 @@ void InsetMathHull::header_write(WriteStream & os) const case hullFlAlign: case hullGather: case hullMultline: - if (os.strikeoutMath()) { - os << "\\\\\\mbox{}\\\\\n" - << "\\lyxmathsout{\\parbox{\\columnwidth}{"; - } + if (os.strikeoutMath()) + os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; os << "\n"; os.startOuterRow(); os << "\\begin{" << hullName(type_) << star(n) << "}\n";