From 696ea82b21f5f0729e14bdefe90d8e18563ddf2e Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 25 Oct 2016 00:49:26 +0200 Subject: [PATCH] Factor out common code used to underline/strike out math Also use the exact amount of vertical space TeX adds after a math display (instead of 1ex) for vertically shifting the box. We have to use \belowdisplayshortskip here, instead of \belowdisplayskip, because the math formula is typeset by alone in a box, and thus there is no following line. --- src/mathed/InsetMathHull.cpp | 67 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 345ee44af7..2bb8822acc 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -121,6 +121,37 @@ namespace { } + // writes a preamble for underlined or struck out math display + void writeMathdisplayPreamble(WriteStream & os) + { + if (os.strikeoutMath()) { + if (os.ulemCmd() == WriteStream::UNDERLINE) + os << "\\raisebox{-\\belowdisplayshortskip}{" + "\\lyxmathsout{\\parbox[b]{\\columnwidth}{"; + else + os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; + } else if (os.ulemCmd() == WriteStream::UNDERLINE) + os << "\\raisebox{-\\belowdisplayshortskip}{" + "\\parbox[b]{\\columnwidth}{"; + else if (os.ulemCmd() == WriteStream::STRIKEOUT) + os << "\\parbox{\\columnwidth}{"; + } + + + // writes a postamble for underlined or struck out math display + void writeMathdisplayPostamble(WriteStream & os) + { + if (os.strikeoutMath()) { + if (os.ulemCmd() == WriteStream::UNDERLINE) + os << "}"; + os << "}}\\\\\n"; + } else if (os.ulemCmd() == WriteStream::UNDERLINE) + os << "}}\\\\\n"; + else if (os.ulemCmd() == WriteStream::STRIKEOUT) + os << "}\\\\\n"; + } + + } // end anon namespace @@ -1029,14 +1060,7 @@ void InsetMathHull::header_write(WriteStream & os) const break; case hullEquation: - if (os.strikeoutMath()) { - if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "\\raisebox{1ex}{"; - os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; - } else if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "\\raisebox{-1ex}{\\parbox[b]{\\columnwidth}{"; - else if (os.ulemCmd() == WriteStream::STRIKEOUT) - os << "\\parbox{\\columnwidth}{"; + writeMathdisplayPreamble(os); os << "\n"; os.startOuterRow(); if (n) @@ -1050,14 +1074,7 @@ void InsetMathHull::header_write(WriteStream & os) const case hullFlAlign: case hullGather: case hullMultline: - if (os.strikeoutMath()) { - if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "\\raisebox{1ex}{"; - os << "\\lyxmathsout{\\parbox{\\columnwidth}{"; - } else if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "\\raisebox{-1ex}{\\parbox[b]{\\columnwidth}{"; - else if (os.ulemCmd() == WriteStream::STRIKEOUT) - os << "\\parbox{\\columnwidth}{"; + writeMathdisplayPreamble(os); os << "\n"; os.startOuterRow(); os << "\\begin{" << hullName(type_) << star(n) << "}\n"; @@ -1113,14 +1130,7 @@ void InsetMathHull::footer_write(WriteStream & os) const os << "\\end{equation" << star(n) << "}\n"; else os << "\\]\n"; - if (os.strikeoutMath()) { - if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "}"; - os << "}}\\\\\n"; - } else if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "}}\\\\\n"; - else if (os.ulemCmd() == WriteStream::STRIKEOUT) - os << "}\\\\\n"; + writeMathdisplayPostamble(os); break; case hullEqnArray: @@ -1131,14 +1141,7 @@ void InsetMathHull::footer_write(WriteStream & os) const os << "\n"; os.startOuterRow(); os << "\\end{" << hullName(type_) << star(n) << "}\n"; - if (os.strikeoutMath()) { - if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "}"; - os << "}}\\\\\n"; - } else if (os.ulemCmd() == WriteStream::UNDERLINE) - os << "}}\\\\\n"; - else if (os.ulemCmd() == WriteStream::STRIKEOUT) - os << "}\\\\\n"; + writeMathdisplayPostamble(os); break; case hullAlignAt: -- 2.39.2