2026/07/15 20:47、Jürgen Spitzmüller <[email protected]>のメール:

Am Donnerstag, dem 09.07.2026 um 17:07 +0200 schrieb Jürgen
Spitzmüller:
Am Mittwoch, dem 08.07.2026 um 10:06 +0900 schrieb Koji Yokota:
I noticed the preview of equations have the same background as the
main text, so in colored insets like LyX Comment, they are shown as
if in another colored box. Can this be fixed e.g. using the
transparency package or else?

It would need to be fixed in the preview loader which sets the
background and foreground color of previews to Color_background and
Color_foreground, respectively. You would need to use the inset
background color instead, and with transparency, overlay that with
Color_background.

On a closer look, this small change will cause dvipng to generate
previews with transparent background:

diff --git a/lib/scripts/lyxpreview2bitmap.py
b/lib/scripts/lyxpreview2bitmap.py
index 56314356d1..1542af1663 100755
--- a/lib/scripts/lyxpreview2bitmap.py
+++ b/lib/scripts/lyxpreview2bitmap.py
@@ -393,7 +393,7 @@ def main(argv):
    bg_color = bytes(bg_color, 'ascii')

    fg_color_dvipng = make_texcolor(fg_color, False).decode('ascii')
-    bg_color_dvipng = make_texcolor(bg_color, False).decode('ascii')
+    bg_color_dvipng = "Transparent"

    # External programs used by the script.
    latex = find_exe_or_terminate(latex or latex_commands)

pdftocairo (the PDF chain) does (should) already produce transparent
background.


However, the previews are still displayed with the workarea background.
If the generated pngs are inserted via inset graphics, on the other
hand, the background is correctly transparent.

So there seems to be some transparency support missing in the
PreviewLoader chain, as opposed to InsetGraphics.

Many thanks, Jürgen!

The attached is a tentative patch that creates png’s with transparent background for preview. But preview still picks up the workarea background even though png’s background is transparent.

This solid background color cannot be changed from the preferences dialog.

Workarea color may be hardcoded to lower layer of the preview image somewhere.

Koji


diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py
index 6be99d360e..eceead324d 100644
--- a/lib/scripts/legacy_lyxpreview2ppm.py
+++ b/lib/scripts/legacy_lyxpreview2ppm.py
@@ -234,10 +234,8 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
                 tmp.write(b"""
 \\usepackage{color}
 \\definecolor{lyxfg}{rgb}{%s}
-\\definecolor{lyxbg}{rgb}{%s}
-\\pagecolor{lyxbg}
 \\usepackage{polyglossia}
-""" % (fg_color_gr, bg_color_gr))
+""" % (fg_color_gr))
                 polyglossia = True
                 continue
         success = 1
@@ -247,22 +245,20 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
             tmp.write(b"""
 \\usepackage{color}
 \\definecolor{lyxfg}{rgb}{%s}
-\\definecolor{lyxbg}{rgb}{%s}
-\\pagecolor{lyxbg}
 \\makeatletter
 \\def\\@tempa{cmr}
 \\ifx\\f@family\\@tempa
   \\IfFileExists{lmodern.sty}{\\usepackage{lmodern}}{\\usepackage{ae,aecompl}}
 \\fi
-""" % (fg_color_gr, bg_color_gr))
+""" % (fg_color_gr))
         tmp.write(b"""
 \\usepackage[%s,tightpage]{preview}
 \\makeatletter
 \\ifdefined\\AddToHook
-  \\AddToHook{env/preview/before}{\\leavevmode\\begingroup\\color{lyxbg}\\special{background \\current@color}\\special{ps::clippath fill}}
+  \\AddToHook{env/preview/before}{\\leavevmode\\begingroup\\special{ps::clippath fill}}
   \\AddToHook{env/preview/after}{\\endgroup}
 \\else
-  \\g@addto@macro\\preview{\\leavevmode\\begingroup\\color{lyxbg}\\special{background \\current@color}\\special{ps::clippath fill}}
+  \\g@addto@macro\\preview{\\leavevmode\\begingroup\\special{ps::clippath fill}}
   \\g@addto@macro\\endpreview{\\endgroup}
 \\fi
 \\g@addto@macro\\preview{\\color{lyxfg}}
diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py
index 56314356d1..1542af1663 100755
--- a/lib/scripts/lyxpreview2bitmap.py
+++ b/lib/scripts/lyxpreview2bitmap.py
@@ -393,7 +393,7 @@ def main(argv):
     bg_color = bytes(bg_color, 'ascii')
 
     fg_color_dvipng = make_texcolor(fg_color, False).decode('ascii')
-    bg_color_dvipng = make_texcolor(bg_color, False).decode('ascii')
+    bg_color_dvipng = "Transparent"
 
     # External programs used by the script.
     latex = find_exe_or_terminate(latex or latex_commands)


Attachment: preview.patch
Description: Binary data

-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to