From 40dd37089d39010105ae7163c07733ed515c54be Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 15 Dec 2024 09:49:36 +0100 Subject: [PATCH] Fix erroneous whitespace before and after math preview (#13127) --- lib/scripts/legacy_lyxpreview2ppm.py | 9 +++++++-- src/mathed/InsetMathHull.cpp | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py index 77636e340e..71ec171a87 100644 --- a/lib/scripts/legacy_lyxpreview2ppm.py +++ b/lib/scripts/legacy_lyxpreview2ppm.py @@ -258,8 +258,13 @@ def legacy_latex_file(latex_file, fg_color, bg_color): tmp.write(b""" \\usepackage[%s,tightpage]{preview} \\makeatletter -\\g@addto@macro\\preview{\\leavevmode\\begingroup\\color{lyxbg}\\special{background \\current@color}\\special{ps::clippath fill}\\color{lyxfg}} -\\g@addto@macro\\endpreview{\\endgroup} +\\ifdefined\\AddToHook + \\AddToHook{env/preview/before}{\\leavevmode\\begingroup\\color{lyxbg}\\special{background \\current@color}\\special{ps::clippath fill}\\color{lyxfg}} + \\AddToHook{env/preview/after}{\\endgroup} +\\else + \\g@addto@macro\\preview{\\leavevmode\\begingroup\\color{lyxbg}\\special{background \\current@color}\\special{ps::clippath fill}\\color{lyxfg}} + \\g@addto@macro\\endpreview{\\endgroup} +\\fi \\let\\pr@set@pagerightoffset\\@empty \\ifx\\pagerightoffset\\@undefined\\else \\def\\pr@set@pagerightoffset{\\ifnum\\pagedirection=1 diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index efefb04fa0..4cc695334e 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -883,7 +883,8 @@ void InsetMathHull::preparePreview(DocIterator const & pos, if (lsize != "normalsize" && !prefixIs(lsize, "error")) setfont += from_ascii("\\" + lsize + '\n'); - docstring const snippet = macro_preamble + setfont + latexString(*this) + endfont; + docstring const snippet = macro_preamble + setfont + + trim(latexString(*this), "\n") + endfont; LYXERR(Debug::MACROS, "Preview snippet: " << snippet); preview_->addPreview(snippet, *buffer, forexport); }