#! /usr/bin/env python
+# -*- coding: iso-8859-1 -*-
# file lyxpreview2bitmap.py
# This file is part of LyX, the document processor.
# author Angus Leeming
# with much advice from members of the preview-latex project:
# David Kastrup, dak@gnu.org and
-# Jan-Åke Larsson, jalar@mai.liu.se.
+# Jan-Åke Larsson, jalar@mai.liu.se.
# Full author contact details are available in file CREDITS
# the images correctly on the screen.
import glob, os, re, string, sys
+from legacy_lyxpreview2ppm import legacy_conversion
# Pre-compiled regular expressions.
def find_exe(candidates, path):
for prog in candidates:
for directory in path:
- full_path = os.path.join(directory, prog)
+ if os.name == "nt":
+ full_path = os.path.join(directory, prog + ".exe")
+ else:
+ full_path = os.path.join(directory, prog)
+
if os.access(full_path, os.X_OK):
return full_path
def extract_metrics_info(dvipng_stdout, metrics_file):
metrics = open(metrics_file, 'w')
- metrics_re = re.compile("\[([0-9]+) depth=([0-9]+) height=([0-9]+)\]")
+ metrics_re = re.compile("\[([0-9]+) depth=(-?[0-9]+) height=(-?[0-9]+)")
success = 0
pos = 0
# External programs used by the script.
path = string.split(os.getenv("PATH"), os.pathsep)
latex = find_exe_or_terminate(["pplatex", "latex2e", "latex"], path)
- dvipng = find_exe_or_terminate(["dvipng"], path)
+
+ # This can go once dvipng becomes widespread.
+ dvipng = find_exe(["dvipng"], path)
+ if dvipng == None:
+ if output_format == "ppm":
+ return legacy_conversion(argv)
+ else:
+ error("The old 'dvi->ps->ppm' conversion requires "
+ "ppm as the output format")
+
pngtopnm = ""
if output_format == "ppm":
pngtopnm = find_exe_or_terminate(["pngtopnm"], path)
if output_format == "ppm":
convert_to_ppm_format(pngtopnm, latex_file_re.sub("", latex_file))
+ return 0
if __name__ == "__main__":
main(sys.argv)