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.
This commit is contained in:
Enrico Forestieri 2016-10-18 03:29:53 +02:00
parent 9c0281126e
commit 129459a71b
5 changed files with 44 additions and 10 deletions

View File

@ -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();

View File

@ -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),

View File

@ -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

View File

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

View File

@ -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";