Move some common variables to lyxpreview_tools. Otherwise,
add a few variable names, making it easier to track things.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39656
a592a061-630c-0410-9148-
cb99ea01b6c8
import glob, os, pipes, re, string, sys
import glob, os, pipes, re, string, sys
-from lyxpreview_tools import copyfileobj, error, find_exe, \
- find_exe_or_terminate, make_texcolor, mkstemp, run_command, warning, \
- write_metrics_info, filter_pages, join_metrics_and_rename
+from lyxpreview_tools import copyfileobj, error, filter_pages, find_exe, \
+ find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
+ latex_file_re, make_texcolor, mkstemp, run_command, warning, \
+ write_metrics_info
-# Pre-compiled regular expression.
-latex_file_re = re.compile("\.tex$")
-
-# PATH environment variable
-path = string.split(os.environ["PATH"], os.pathsep)
def usage(prog_name):
return "Usage: %s <latex file> <dpi> ppm <fg color> <bg color>\n" \
def usage(prog_name):
return "Usage: %s <latex file> <dpi> ppm <fg color> <bg color>\n" \
def legacy_conversion(argv, skipMetrics = False):
def legacy_conversion(argv, skipMetrics = False):
- latex_commands = ["latex", "pplatex", "platex", "latex2e"]
# Parse and manipulate the command line arguments.
if len(argv) == 7:
# Parse and manipulate the command line arguments.
if len(argv) == 7:
- latex_commands = [argv[6]]
elif len(argv) != 6:
error(usage(argv[0]))
elif len(argv) != 6:
error(usage(argv[0]))
dir, latex_file = os.path.split(argv[1])
if len(dir) != 0:
dir, latex_file = os.path.split(argv[1])
if len(dir) != 0:
bg_color_gr = make_texcolor(argv[5], True)
# External programs used by the script.
bg_color_gr = make_texcolor(argv[5], True)
# External programs used by the script.
- latex = find_exe_or_terminate(latex_commands, path)
+ latex = find_exe_or_terminate(latex or latex_commands)
# Move color information into the latex file.
if not legacy_latex_file(latex_file, fg_color, bg_color, bg_color_gr):
# Move color information into the latex file.
if not legacy_latex_file(latex_file, fg_color, bg_color, bg_color_gr):
gs_device, gs_ext, alpha, resolution, output_format):
# Search for pdflatex executable
gs_device, gs_ext, alpha, resolution, output_format):
# Search for pdflatex executable
- pdflatex = find_exe(["pdflatex"], path)
+ pdflatex = find_exe(["pdflatex"])
if pdflatex == None:
warning("Can't find pdflatex. Some pages failed with all the possible routes.")
else:
if pdflatex == None:
warning("Can't find pdflatex. Some pages failed with all the possible routes.")
else:
def legacy_conversion_step2(latex_file, dpi, output_format, skipMetrics = False):
# External programs used by the script.
def legacy_conversion_step2(latex_file, dpi, output_format, skipMetrics = False):
# External programs used by the script.
- dvips = find_exe_or_terminate(["dvips"], path)
- gs = find_exe_or_terminate(["gswin32c", "gs"], path)
- pnmcrop = find_exe(["pnmcrop"], path)
+ dvips = find_exe_or_terminate(["dvips"])
+ gs = find_exe_or_terminate(["gswin32c", "gs"])
+ pnmcrop = find_exe(["pnmcrop"])
# Run the dvi file through dvips.
dvi_file = latex_file_re.sub(".dvi", latex_file)
# Run the dvi file through dvips.
dvi_file = latex_file_re.sub(".dvi", latex_file)
import glob, os, re, string, sys
from legacy_lyxpreview2ppm import legacy_conversion, \
import glob, os, re, string, sys
from legacy_lyxpreview2ppm import legacy_conversion, \
- legacy_conversion_step2, legacy_extract_metrics_info, filter_pages
+ legacy_conversion_step2, legacy_extract_metrics_info
-from lyxpreview_tools import copyfileobj, error, find_exe, \
- find_exe_or_terminate, make_texcolor, mkstemp, run_command, warning, \
- write_metrics_info, join_metrics_and_rename
+from lyxpreview_tools import copyfileobj, error, filter_pages, find_exe, \
+ find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
+ latex_file_re, make_texcolor, mkstemp, run_command, warning, \
+ write_metrics_info
-# Pre-compiled regular expressions.
-latex_file_re = re.compile("\.tex$")
-
-# PATH environment variable
-path = string.split(os.environ["PATH"], os.pathsep)
-
def usage(prog_name):
return "Usage: %s <format> <latex file> <dpi> <fg color> <bg color>\n" \
"\twhere the colors are hexadecimal strings, eg 'faf0e6'" \
def usage(prog_name):
return "Usage: %s <format> <latex file> <dpi> <fg color> <bg color>\n" \
"\twhere the colors are hexadecimal strings, eg 'faf0e6'" \
# Check for PostScript specials in the dvi, badly supported by dvipng
# This is required for correct rendering of PSTricks and TikZ
# Check for PostScript specials in the dvi, badly supported by dvipng
# This is required for correct rendering of PSTricks and TikZ
- dv2dt = find_exe_or_terminate(["dv2dt"], path)
+ dv2dt = find_exe_or_terminate(["dv2dt"])
dv2dt_call = '%s "%s"' % (dv2dt, dvi_file)
# The output from dv2dt goes to stdout
dv2dt_call = '%s "%s"' % (dv2dt, dvi_file)
# The output from dv2dt goes to stdout
if len(argv) != 6 and len(argv) != 7:
error(usage(argv[0]))
if len(argv) != 6 and len(argv) != 7:
error(usage(argv[0]))
+ script_name = argv[0]
+
output_format = string.lower(argv[1])
output_format = string.lower(argv[1])
- dir, latex_file = os.path.split(argv[2])
+ input_path = argv[2]
+ dir, latex_file = os.path.split(input_path)
if len(dir) != 0:
os.chdir(dir)
dpi = string.atoi(argv[3])
if len(dir) != 0:
os.chdir(dir)
dpi = string.atoi(argv[3])
- fg_color = make_texcolor(argv[4], False)
- bg_color = make_texcolor(argv[5], False)
+ fg_color = argv[4]
+ bg_color = argv[5]
+
+ fg_color_dvipng = make_texcolor(fg_color, False)
+ bg_color_dvipng = make_texcolor(bg_color, False)
- fg_color_gr = make_texcolor(argv[4], True)
- bg_color_gr = make_texcolor(argv[5], True)
+ fg_color_gr = make_texcolor(fg_color, True)
+ bg_color_gr = make_texcolor(bg_color, True)
# External programs used by the script.
if len(argv) == 7:
# External programs used by the script.
if len(argv) == 7:
- latex = find_exe_or_terminate(["latex", "pplatex", "platex", "latex2e"], path)
+ latex = None
+ latex = find_exe_or_terminate(latex or latex_commands)
# Omit font size specification in latex file.
fix_latex_file(latex_file)
# This can go once dvipng becomes widespread.
# Omit font size specification in latex file.
fix_latex_file(latex_file)
# This can go once dvipng becomes widespread.
- dvipng = find_exe(["dvipng"], path)
+ dvipng = find_exe(["dvipng"])
if dvipng == None:
# The data is input to legacy_conversion in as similar
# as possible a manner to that input to the code used in
# LyX 1.3.x.
if dvipng == None:
# The data is input to legacy_conversion in as similar
# as possible a manner to that input to the code used in
# LyX 1.3.x.
- vec = [ argv[0], argv[2], argv[3], argv[1], argv[4], argv[5], latex ]
+ vec = [ script_name, input_path, str(dpi), output_format, fg_color, bg_color, latex ]
return legacy_conversion(vec)
pngtopnm = ""
if output_format == "ppm":
return legacy_conversion(vec)
pngtopnm = ""
if output_format == "ppm":
- pngtopnm = find_exe_or_terminate(["pngtopnm"], path)
+ pngtopnm = find_exe_or_terminate(["pngtopnm"])
# Move color information for PDF into the latex file.
if not color_pdf(latex_file, bg_color_gr, fg_color_gr):
# Move color information for PDF into the latex file.
if not color_pdf(latex_file, bg_color_gr, fg_color_gr):
# If all pages need PostScript, directly use the legacy method.
if len(ps_pages) == page_count:
# If all pages need PostScript, directly use the legacy method.
if len(ps_pages) == page_count:
- vec = [argv[0], argv[2], argv[3], argv[1], argv[4], argv[5], latex]
+ vec = [ script_name, input_path, str(dpi), output_format, fg_color, bg_color, latex ]
return legacy_conversion(vec)
# Run the dvi file through dvipng.
dvipng_call = '%s -Ttight -depth -height -D %d -fg "%s" -bg "%s" %s "%s"' \
return legacy_conversion(vec)
# Run the dvi file through dvipng.
dvipng_call = '%s -Ttight -depth -height -D %d -fg "%s" -bg "%s" %s "%s"' \
- % (dvipng, dpi, fg_color, bg_color, pages_parameter, dvi_file)
+ % (dvipng, dpi, fg_color_dvipng, bg_color_dvipng, pages_parameter, dvi_file)
dvipng_status, dvipng_stdout = run_command(dvipng_call)
if dvipng_status != None:
dvipng_status, dvipng_stdout = run_command(dvipng_call)
if dvipng_status != None:
filter_pages(latex_file, legacy_latex_file, ps_pages)
# Pass the new LaTeX file to the legacy method
filter_pages(latex_file, legacy_latex_file, ps_pages)
# Pass the new LaTeX file to the legacy method
- vec = [ argv[0], latex_file_re.sub("_legacy.tex", argv[2]),
- argv[3], argv[1], argv[4], argv[5], latex ]
+ vec = [ script_name, latex_file_re.sub("_legacy.tex", input_path),
+ str(dpi), output_format, fg_color, bg_color, latex ]
legacy_metrics = legacy_conversion(vec, True)[1]
# Now we need to mix metrics data from dvipng and the legacy method
legacy_metrics = legacy_conversion(vec, True)[1]
# Now we need to mix metrics data from dvipng and the legacy method
import os, re, string, sys, tempfile
import os, re, string, sys, tempfile
+
+# Known flavors of latex
+latex_commands = ("latex", "pplatex", "platex", "latex2e")
+pdflatex_commands = ("pdflatex", "xelatex", "lualatex")
+
+# Pre-compiled regular expressions
+latex_file_re = re.compile(r"\.tex$")
+
+# PATH and PATHEXT environment variables
+path = os.environ["PATH"].split(os.pathsep)
+extlist = ['']
+if "PATHEXT" in os.environ:
+ extlist += os.environ["PATHEXT"].split(os.pathsep)
+
use_win32_modules = 0
if os.name == "nt":
use_win32_modules = 1
use_win32_modules = 0
if os.name == "nt":
use_win32_modules = 1
return "rgb %f %f %f" % (red, green, blue)
return "rgb %f %f %f" % (red, green, blue)
-def find_exe(candidates, path):
- extlist = ['']
- if "PATHEXT" in os.environ:
- extlist = extlist + os.environ["PATHEXT"].split(os.pathsep)
+def find_exe(candidates):
+ global extlist, path
for prog in candidates:
for directory in path:
for prog in candidates:
for directory in path:
-def find_exe_or_terminate(candidates, path):
- exe = find_exe(candidates, path)
+def find_exe_or_terminate(candidates):
+ exe = find_exe(candidates)
if exe == None:
error("Unable to find executable from '%s'" % string.join(candidates))
if exe == None:
error("Unable to find executable from '%s'" % string.join(candidates))