commit 2f5e169ac272e91d51d5b2209067ee07a4d60718
Author: Koji Yokota <[email protected]>
Date:   Tue Jul 21 16:12:11 2026 +0900

    Make background of math preview transparent
    
    Thanks for Jürgen's help
---
 lib/scripts/legacy_lyxpreview2ppm.py | 13 ++++---------
 lib/scripts/lyxpreview2bitmap.py     |  2 +-
 src/Color.cpp                        |  1 +
 src/ColorCode.h                      |  2 ++
 src/frontends/qt/GuiPrefs.cpp        |  1 +
 src/mathed/InsetMathHull.cpp         |  2 +-
 6 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/lib/scripts/legacy_lyxpreview2ppm.py 
b/lib/scripts/legacy_lyxpreview2ppm.py
index 6be99d360e..575a34be5a 100644
--- a/lib/scripts/legacy_lyxpreview2ppm.py
+++ b/lib/scripts/legacy_lyxpreview2ppm.py
@@ -202,7 +202,6 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
     use_polyglossia_re = re.compile(b"\\s*\\\\usepackage{polyglossia}")
     use_preview_re = re.compile(b"\\s*\\\\usepackage\\[([^]]+)\\]{preview}")
     fg_color_gr = make_texcolor(fg_color, True)
-    bg_color_gr = make_texcolor(bg_color, True)
 
     tmp = tempfile.TemporaryFile()
 
@@ -234,10 +233,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 +244,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)
diff --git a/src/Color.cpp b/src/Color.cpp
index 5fd774afa8..1ca2c0ced3 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -299,6 +299,7 @@ ColorSet::ColorSet()
        { Color_none, N_("none"), "none", black, black, "none" },
        { Color_black, N_("black"), "black", black, black, "black" },
        { Color_white, N_("white"), "white", white, white, "white" },
+       { Color_transparent, N_("transparent"), "transparent", transparent, 
transparent, "transparent" },
        { Color_blue, N_("blue"), "blue", blue, blue, "blue" },
        { Color_brown, N_("brown"), "brown", brown, brown, "brown" },
        { Color_cyan, N_("cyan"), "cyan", cyan, cyan, "cyan" },
diff --git a/src/ColorCode.h b/src/ColorCode.h
index 3492498746..d101b43d62 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -21,6 +21,8 @@ enum ColorCode {
        ///
        Color_white,
        ///
+       Color_transparent,
+       ///
        Color_blue,
        ///
        Color_brown,
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 175afdc6d8..adcbc4a051 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -995,6 +995,7 @@ PrefColors::PrefColors(GuiPreferences * form)
                if (lc == Color_none
                    || lc == Color_black
                    || lc == Color_white
+                       || lc == Color_transparent
                    || lc == Color_blue
                    || lc == Color_brown
                    || lc == Color_cyan
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 9ba086a715..96fa9a42c3 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -615,7 +615,7 @@ ColorCode InsetMathHull::backgroundColor(PainterInfo const 
& pi) const
                Dimension const dim = dimension(*pi.base.bv);
                if (previewTooSmall(dim))
                        return Color_error;
-               return graphics::PreviewLoader::backgroundColor();
+               return Color_transparent;
        }
        return InsetMath::backgroundColor(pi);
 }
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to