]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview2bitmap.py
iucr.layout: use Item_Environment for a style as proposed by Jürgen
[lyx.git] / lib / scripts / lyxpreview2bitmap.py
index 90deec813c0f71b321d377de1497906354da2bdb..5eca9599908f6c6faccb97dec0c79e23dfef2a11 100755 (executable)
@@ -79,10 +79,11 @@ import getopt, glob, os, re, shutil, string, sys
 
 from legacy_lyxpreview2ppm import legacy_conversion_step1
 
-from lyxpreview_tools import bibtex_commands, copyfileobj, error, \
-     filter_pages, find_exe, find_exe_or_terminate, join_metrics_and_rename, \
-     latex_commands, latex_file_re, make_texcolor, mkstemp, pdflatex_commands, \
-     progress, run_command, run_latex, run_tex, warning, write_metrics_info
+from lyxpreview_tools import bibtex_commands, check_latex_log, copyfileobj, \
+     error, filter_pages, find_exe, find_exe_or_terminate, \
+     join_metrics_and_rename, latex_commands, latex_file_re, make_texcolor, \
+     mkstemp, pdflatex_commands, progress, run_command, run_latex, run_tex, \
+     warning, write_metrics_info
 
 
 def usage(prog_name):
@@ -159,25 +160,18 @@ def extract_metrics_info(dvipng_stdout):
 
 def fix_latex_file(latex_file):
     documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
-    newcommandx_re = re.compile("^(\\\\newcommandx)(.+)")
 
     tmp = mkstemp()
 
     changed = 0
     for line in open(latex_file, 'r').readlines():
         match = documentclass_re.match(line)
-        if match != None:
-            changed = 1
-            tmp.write("%s%s\n" % (match.group(1), match.group(3)))
-            continue
-
-        match = newcommandx_re.match(line)
         if match == None:
             tmp.write(line)
             continue
 
         changed = 1
-        tmp.write("\\providecommandx%s\n" % match.group(2))
+        tmp.write("%s%s\n" % (match.group(1), match.group(3)))
 
     if changed:
         copyfileobj(tmp, open(latex_file,"wb"), 1)
@@ -441,9 +435,11 @@ def main(argv):
                 fg_color, bg_color, latex, pdf_output)
 
     # Compile the latex file.
+    error_pages = []
     latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
     if latex_status:
         warning("trying to recover from failed compilation")
+        error_pages = check_latex_log(latex_file_re.sub(".log", latex_file))
 
     # The dvi output file name
     dvi_file = latex_file_re.sub(".dvi", latex_file)
@@ -537,6 +533,13 @@ def main(argv):
         join_metrics_and_rename(dvipng_metrics, legacy_metrics, pdf_pages,
             original_bitmap, destination_bitmap)
 
+    # Invalidate metrics for pages that produced errors
+    if len(error_pages) > 0:
+        for index in error_pages:
+            if index not in ps_pages and index not in pdf_pages:
+                dvipng_metrics.pop(index - 1)
+                dvipng_metrics.insert(index - 1, (index, -1.0))
+
     # Convert images to ppm format if necessary.
     if output_format == "ppm":
         convert_to_ppm_format(pngtopnm, latex_file_re.sub("", latex_file))