From 7f23ca912c5e92bf30bdc05b6d801082f6643e8e Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sun, 22 Oct 2017 13:12:33 +0200 Subject: [PATCH] Fix issue with change-tracked deleted display math - If a display math not starting a new paragraph is deleted, the current \lyxdeleted macro (if any) must be closed and a new one started, otherwise the display math will be shifted up. - Use \linewidth instead of \columnwidth because the former will adapt to the reduced horizontal width in list environments, avoiding shifting to the right the diplay math. --- src/Changes.cpp | 13 ++++++++----- src/Paragraph.cpp | 27 +++++++++++++++++++++++---- src/mathed/InsetMathHull.cpp | 8 ++++---- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/Changes.cpp b/src/Changes.cpp index 8d4933c55f..b4226582f4 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -394,11 +394,16 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, int column = 0; + bool const dvipost = LaTeXFeatures::isAvailable("dvipost") && + (runparams.flavor == OutputParams::LATEX + || runparams.flavor == OutputParams::DVILUATEX); + if (oldChange.type != Change::UNCHANGED) { // close \lyxadded or \lyxdeleted os << '}'; column++; - if (oldChange.type == Change::DELETED && !runparams.wasDisplayMath) + if (oldChange.type == Change::DELETED + && !runparams.wasDisplayMath && !dvipost) --runparams.inulemcmd; } @@ -410,7 +415,7 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, docstring macro_beg; if (change.type == Change::DELETED) { macro_beg = from_ascii("\\lyxdeleted{"); - if (!runparams.inDisplayMath) + if (!runparams.inDisplayMath && !dvipost) ++runparams.inulemcmd; } else if (change.type == Change::INSERTED) @@ -422,9 +427,7 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, // 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))) { + && !dvipost) { if (os.afterParbreak()) str += from_ascii("\\\\\\noindent\n"); else diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 76202516a8..f130fa08c8 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2454,6 +2454,8 @@ void Paragraph::latex(BufferParams const & bparams, runparams.wasDisplayMath = runparams.inDisplayMath; runparams.inDisplayMath = false; bool deleted_display_math = false; + Change const & change = runparams.inDeletedInset + ? runparams.changeOfDeletedInset : lookupChange(i); // Check whether a display math inset follows if (d->text_[i] == META_INSET @@ -2468,11 +2470,28 @@ void Paragraph::latex(BufferParams const & bparams, // cannot set it here because it is a counter. deleted_display_math = isDeleted(i); } + if (bparams.output_changes && deleted_display_math + && runningChange == change + && change.type == Change::DELETED + && !os.afterParbreak()) { + // A display math in the same paragraph follows. + // We have to close and then reopen \lyxdeleted, + // otherwise the math will be shifted up. + OutputParams rp = runparams; + if (open_font) { + bool needPar = false; + column += running_font.latexWriteEndChanges( + os, bparams, rp, basefont, + basefont, needPar); + open_font = false; + } + basefont = getLayoutFont(bparams, outerfont); + running_font = basefont; + column += Changes::latexMarkChange(os, bparams, + Change(Change::INSERTED), change, rp); + } } - Change const & change = runparams.inDeletedInset - ? runparams.changeOfDeletedInset : lookupChange(i); - if (bparams.output_changes && runningChange != change) { if (open_font) { bool needPar = false; @@ -2549,7 +2568,7 @@ void Paragraph::latex(BufferParams const & bparams, char_type const c = d->text_[i]; // A display math inset inside an ulem command will be output - // as a box of width \columnwidth, so we have to either disable + // as a box of width \linewidth, so we have to either disable // indentation if the inset starts a paragraph, or start a new // line to accommodate such box. This has to be done before // writing any font changing commands. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index e07d5984b2..78175f3f70 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -126,14 +126,14 @@ namespace { if (os.strikeoutMath()) { if (os.ulemCmd() == WriteStream::UNDERLINE) os << "\\raisebox{-\\belowdisplayshortskip}{" - "\\lyxmathsout{\\parbox[b]{\\columnwidth}{"; + "\\lyxmathsout{\\parbox[b]{\\linewidth}{"; else - os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; + os << "\\lyxmathsout{\\parbox{\\linewidth}{"; } else if (os.ulemCmd() == WriteStream::UNDERLINE) os << "\\raisebox{-\\belowdisplayshortskip}{" - "\\parbox[b]{\\columnwidth}{"; + "\\parbox[b]{\\linewidth}{"; else if (os.ulemCmd() == WriteStream::STRIKEOUT) - os << "\\parbox{\\columnwidth}{"; + os << "\\parbox{\\linewidth}{"; }