commit 476705ba7600dca175dd53a2593bd3497a613786
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Tue Jul 11 10:03:03 2017 +0200

    Load color before polyglossia also in preview snippets
    
    This fixes an error in the preview generation with polyglossia
    and bidi that prevents snippet generation (and consequently also
    "math as image" xhtml output).
    
    Fixes: #10716.
---
 lib/scripts/legacy_lyxpreview2ppm.py |   38 ++++++++++++++++++++++++++++-----
 status.22x                           |    3 ++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/lib/scripts/legacy_lyxpreview2ppm.py 
b/lib/scripts/legacy_lyxpreview2ppm.py
index ee49e6a..96e8ad7 100644
--- a/lib/scripts/legacy_lyxpreview2ppm.py
+++ b/lib/scripts/legacy_lyxpreview2ppm.py
@@ -202,6 +202,7 @@ def extract_resolution(log_file, dpi):
 
 def legacy_latex_file(latex_file, fg_color, bg_color):
     use_preview_re = re.compile(r"\s*\\usepackage\[([^]]+)\]{preview}")
+    use_polyglossia_re = re.compile(r"\s*\\usepackage{polyglossia}")
     fg_color_gr = make_texcolor(fg_color, True)
     bg_color_gr = make_texcolor(bg_color, True)
 
@@ -216,18 +217,36 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
         warning('Warning in legacy_latex_file! Unable to open "%s"' % 
latex_file)
         warning(`sys.exc_type` + ',' + `sys.exc_value`)
 
+    polyglossia = False
     for line in f.readlines():
         if success:
             tmp.write(line)
             continue
         match = use_preview_re.match(line)
+        polymatch = use_polyglossia_re.match(line)
+        # Package order:
+        # * if polyglossia is used, we need to load color before that
+        #   (also, we do not have to load lmodern)
+        # * else, color should be loaded before preview
         if match == None:
-            tmp.write(line)
-            continue
+            if polymatch == None:
+                tmp.write(line)
+                continue
+            else:
+                tmp.write(b"""
+\\usepackage{color}
+\\definecolor{fg}{rgb}{%s}
+\\definecolor{bg}{rgb}{%s}
+\\pagecolor{bg}
+\\usepackage{polyglossia}
+""" % (fg_color_gr, bg_color_gr))
+                polyglossia = True
+                continue
         success = 1
-        # Package order: color should be loaded before preview
         # Preview options: add the options lyx and tightpage
-        tmp.write(r"""
+        previewopts = match.group(1)
+        if not polyglossia:
+            tmp.write(r"""
 \usepackage{color}
 \definecolor{fg}{rgb}{%s}
 \definecolor{bg}{rgb}{%s}
@@ -241,8 +260,15 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
 \g@addto@macro\preview{\begingroup\color{bg}\special{ps::clippath 
fill}\color{fg}}
 \g@addto@macro\endpreview{\endgroup}
 \makeatother
-""" % (fg_color_gr, bg_color_gr, match.group(1)))
-
+""" % (fg_color_gr, bg_color_gr, previewopts))
+        else:
+            tmp.write(r"""
+\usepackage[%s,tightpage]{preview}
+\makeatletter
+\g@addto@macro\preview{\begingroup\color{bg}\special{ps::clippath 
fill}\color{fg}}
+\g@addto@macro\endpreview{\endgroup}
+\makeatother
+""" % previewopts)
     if success:
         copyfileobj(tmp, open(latex_file,"wb"), 1)
 
diff --git a/status.22x b/status.22x
index fbd57bd..72e014b 100644
--- a/status.22x
+++ b/status.22x
@@ -57,6 +57,9 @@ What's new
 - Do not let the natbibapa module overwrite what the class or other packages
   add to the preamble.
 
+- Assure the color package is loaded before polyglossia in preview snippets
+  This fixes preview image generation with polyglossia and bidi (bug 10716).
+
 
 * LYX2LYX
 

Reply via email to