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.
This commit is contained in:
Juergen Spitzmueller 2017-07-11 10:03:03 +02:00
parent 0237292eb1
commit 476705ba76
2 changed files with 35 additions and 6 deletions

View File

@ -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)

View File

@ -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