]> git.lyx.org Git - lyx.git/commitdiff
Fix issue with change-tracked deleted display math
authorEnrico Forestieri <forenr@lyx.org>
Sun, 22 Oct 2017 11:12:33 +0000 (13:12 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 22 Oct 2017 11:12:33 +0000 (13:12 +0200)
- 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
src/Paragraph.cpp
src/mathed/InsetMathHull.cpp

index 8d4933c55fc353f76e262aaa9c94b86069c468de..b4226582f4f7b97e88323607223f9f691c005178 100644 (file)
@@ -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
index 76202516a88eb424c963907b775ffb47e83792b2..f130fa08c8fc2640cdecd5b0efb0e874da747de9 100644 (file)
@@ -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.
index e07d5984b237fcf4e2b4f1eb2e32b8707750f7db..78175f3f70d524f1145829c77afc17dbe2f07e05 100644 (file)
@@ -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}{";
        }