]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview2bitmap.py
configure.py: Replace 'ltx' by 'log' case insensitively
[lyx.git] / lib / scripts / lyxpreview2bitmap.py
index 7b19e482444f597cbb484b8699c556bf9b09a82a..09ac3a936820a85dc01b2f222bbf31398176f270 100755 (executable)
@@ -155,42 +155,6 @@ def extract_metrics_info(dvipng_stdout):
     return results
 
 
-def color_pdf(latex_file, bg_color, fg_color):
-    use_preview_pdf_re = re.compile("(\s*\\\\usepackage\[[^]]+)((pdftex|xetex)\]{preview})")
-
-    tmp = mkstemp()
-
-    fg = ""
-    if fg_color != "0.000000,0.000000,0.000000":
-        fg = '  \\AtBeginDocument{\\let\\oldpreview\\preview\\renewcommand\\preview{\\oldpreview\\color[rgb]{%s}}}\n' % (fg_color)
-
-    success = 0
-    try:
-        for line in open(latex_file, 'r').readlines():
-            match = use_preview_pdf_re.match(line)
-            if match == None:
-                tmp.write(line)
-                continue
-            success = 1
-            tmp.write("  \\usepackage{color}\n" \
-                  "  \\pagecolor[rgb]{%s}\n" \
-                  "%s" \
-                  "%s\n" \
-                  % (bg_color, fg, match.group()))
-            continue
-
-    except:
-        # Unable to open the file, but do nothing here because
-        # the calling function will act on the value of 'success'.
-        warning('Warning in color_pdf! Unable to open "%s"' % latex_file)
-        warning(`sys.exc_type` + ',' + `sys.exc_value`)
-
-    if success:
-        copyfileobj(tmp, open(latex_file,"wb"), 1)
-
-    return success
-
-
 def fix_latex_file(latex_file):
     documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
 
@@ -385,14 +349,12 @@ def main(argv):
     fg_color_dvipng = make_texcolor(fg_color, False)
     bg_color_dvipng = make_texcolor(bg_color, False)
 
-    fg_color_gr = make_texcolor(fg_color, True)
-    bg_color_gr = make_texcolor(bg_color, True)
-
     # External programs used by the script.
     latex = find_exe_or_terminate(latex or latex_commands)
     bibtex = find_exe(bibtex or bibtex_commands)
     if lilypond:
-        lilypond_book = find_exe_or_terminate(lilypond_book or ["lilypond-book"])
+        lilypond_book = find_exe_or_terminate(lilypond_book or
+            ["lilypond-book --safe"])
 
     # These flavors of latex are known to produce pdf output
     pdf_output = latex in pdflatex_commands
@@ -411,19 +373,15 @@ def main(argv):
     if lilypond:
         progress("Preprocess the latex file through %s" % lilypond_book)
         if pdf_output:
-            lilypond_book += ' --pdf'
+            lilypond_book += " --pdf"
+        lilypond_book += " --latex-program=%s" % latex.split()[0]
 
         # Make a copy of the latex file
         lytex_file = latex_file_re.sub(".lytex", latex_file)
         shutil.copyfile(latex_file, lytex_file)
 
         # Preprocess the latex file through lilypond-book.
-        lytex_call = '%s --safe --latex-program=%s "%s"' % (lilypond_book,
-            latex, lytex_file)
-        lytex_status, lytex_stdout = run_command(lytex_call)
-        if lytex_status:
-            warning("%s failed to compile %s" \
-                % (os.path.basename(lilypond_book), lytex_file))
+        lytex_status, lytex_stdout = run_tex(lilypond_book, lytex_file)
 
     if pdf_output:
         progress("Using the legacy conversion method (PDF support)")
@@ -451,10 +409,6 @@ def main(argv):
             return legacy_conversion_step1(latex_file, dpi, output_format,
                 fg_color, bg_color, latex, pdf_output)
 
-    # Move color information for PDF into the latex file.
-    if not color_pdf(latex_file, bg_color_gr, fg_color_gr):
-        warning("Unable to move color info into the latex file")
-
     # Compile the latex file.
     latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)