mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
Merge branch 'master' of git.lyx.org:lyx
This commit is contained in:
commit
f6fde9dbb2
@ -81,8 +81,8 @@
|
|||||||
|
|
||||||
import glob, os, pipes, re, string, sys
|
import glob, os, pipes, re, string, sys
|
||||||
|
|
||||||
from lyxpreview_tools import copyfileobj, error, filter_pages, find_exe, \
|
from lyxpreview_tools import check_latex_log, copyfileobj, error, filter_pages,\
|
||||||
find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
|
find_exe, find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
|
||||||
latex_file_re, make_texcolor, mkstemp, pdflatex_commands, progress, \
|
latex_file_re, make_texcolor, mkstemp, pdflatex_commands, progress, \
|
||||||
run_command, run_latex, warning, write_metrics_info
|
run_command, run_latex, warning, write_metrics_info
|
||||||
|
|
||||||
@ -325,7 +325,10 @@ def legacy_conversion_pdflatex(latex_file, failed_pages, legacy_metrics,
|
|||||||
filter_pages(latex_file, pdf_latex_file, failed_pages)
|
filter_pages(latex_file, pdf_latex_file, failed_pages)
|
||||||
|
|
||||||
# pdflatex call
|
# pdflatex call
|
||||||
|
error_pages = []
|
||||||
pdflatex_status, pdflatex_stdout = run_latex(pdflatex, pdf_latex_file)
|
pdflatex_status, pdflatex_stdout = run_latex(pdflatex, pdf_latex_file)
|
||||||
|
if pdflatex_status:
|
||||||
|
error_pages = check_latex_log(latex_file_re.sub(".log", pdf_latex_file))
|
||||||
|
|
||||||
pdf_file = latex_file_re.sub(".pdf", pdf_latex_file)
|
pdf_file = latex_file_re.sub(".pdf", pdf_latex_file)
|
||||||
latex_file_root = latex_file_re.sub("", pdf_latex_file)
|
latex_file_root = latex_file_re.sub("", pdf_latex_file)
|
||||||
@ -359,6 +362,12 @@ def legacy_conversion_pdflatex(latex_file, failed_pages, legacy_metrics,
|
|||||||
pdf_log_file = latex_file_re.sub(".log", pdf_latex_file)
|
pdf_log_file = latex_file_re.sub(".log", pdf_latex_file)
|
||||||
pdf_metrics = legacy_extract_metrics_info(pdf_log_file)
|
pdf_metrics = legacy_extract_metrics_info(pdf_log_file)
|
||||||
|
|
||||||
|
# Invalidate metrics for pages that produced errors
|
||||||
|
if len(error_pages) > 0:
|
||||||
|
for index in error_pages:
|
||||||
|
pdf_metrics.pop(index - 1)
|
||||||
|
pdf_metrics.insert(index - 1, (index, -1.0))
|
||||||
|
|
||||||
original_bitmap = latex_file_re.sub("%d." + output_format, pdf_latex_file)
|
original_bitmap = latex_file_re.sub("%d." + output_format, pdf_latex_file)
|
||||||
destination_bitmap = latex_file_re.sub("%d." + output_format, latex_file)
|
destination_bitmap = latex_file_re.sub("%d." + output_format, latex_file)
|
||||||
|
|
||||||
@ -414,6 +423,9 @@ def legacy_conversion_step3(latex_file, dpi, output_format, dvips_failed, skipMe
|
|||||||
log_file = latex_file_re.sub(".log", latex_file)
|
log_file = latex_file_re.sub(".log", latex_file)
|
||||||
resolution = extract_resolution(log_file, dpi)
|
resolution = extract_resolution(log_file, dpi)
|
||||||
|
|
||||||
|
# Check whether some pages produced errors
|
||||||
|
error_pages = check_latex_log(log_file)
|
||||||
|
|
||||||
# Older versions of gs have problems with a large degree of
|
# Older versions of gs have problems with a large degree of
|
||||||
# anti-aliasing at high resolutions
|
# anti-aliasing at high resolutions
|
||||||
alpha = 4
|
alpha = 4
|
||||||
@ -505,6 +517,13 @@ def legacy_conversion_step3(latex_file, dpi, output_format, dvips_failed, skipMe
|
|||||||
use_pdftocairo, conv, gs_device, gs_ext, alpha, resolution,
|
use_pdftocairo, conv, gs_device, gs_ext, alpha, resolution,
|
||||||
output_format)
|
output_format)
|
||||||
|
|
||||||
|
# Invalidate metrics for pages that produced errors
|
||||||
|
if len(error_pages) > 0:
|
||||||
|
for index in error_pages:
|
||||||
|
if index not in failed_pages:
|
||||||
|
legacy_metrics.pop(index - 1)
|
||||||
|
legacy_metrics.insert(index - 1, (index, -1.0))
|
||||||
|
|
||||||
# Crop the ppm images
|
# Crop the ppm images
|
||||||
if pnmcrop != None and output_format == "ppm":
|
if pnmcrop != None and output_format == "ppm":
|
||||||
crop_files(pnmcrop, latex_file_root)
|
crop_files(pnmcrop, latex_file_root)
|
||||||
|
@ -79,10 +79,11 @@ import getopt, glob, os, re, shutil, string, sys
|
|||||||
|
|
||||||
from legacy_lyxpreview2ppm import legacy_conversion_step1
|
from legacy_lyxpreview2ppm import legacy_conversion_step1
|
||||||
|
|
||||||
from lyxpreview_tools import bibtex_commands, copyfileobj, error, \
|
from lyxpreview_tools import bibtex_commands, check_latex_log, copyfileobj, \
|
||||||
filter_pages, find_exe, find_exe_or_terminate, join_metrics_and_rename, \
|
error, filter_pages, find_exe, find_exe_or_terminate, \
|
||||||
latex_commands, latex_file_re, make_texcolor, mkstemp, pdflatex_commands, \
|
join_metrics_and_rename, latex_commands, latex_file_re, make_texcolor, \
|
||||||
progress, run_command, run_latex, run_tex, warning, write_metrics_info
|
mkstemp, pdflatex_commands, progress, run_command, run_latex, run_tex, \
|
||||||
|
warning, write_metrics_info
|
||||||
|
|
||||||
|
|
||||||
def usage(prog_name):
|
def usage(prog_name):
|
||||||
@ -441,9 +442,11 @@ def main(argv):
|
|||||||
fg_color, bg_color, latex, pdf_output)
|
fg_color, bg_color, latex, pdf_output)
|
||||||
|
|
||||||
# Compile the latex file.
|
# Compile the latex file.
|
||||||
|
error_pages = []
|
||||||
latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
|
latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
|
||||||
if latex_status:
|
if latex_status:
|
||||||
warning("trying to recover from failed compilation")
|
warning("trying to recover from failed compilation")
|
||||||
|
error_pages = check_latex_log(latex_file_re.sub(".log", latex_file))
|
||||||
|
|
||||||
# The dvi output file name
|
# The dvi output file name
|
||||||
dvi_file = latex_file_re.sub(".dvi", latex_file)
|
dvi_file = latex_file_re.sub(".dvi", latex_file)
|
||||||
@ -537,6 +540,13 @@ def main(argv):
|
|||||||
join_metrics_and_rename(dvipng_metrics, legacy_metrics, pdf_pages,
|
join_metrics_and_rename(dvipng_metrics, legacy_metrics, pdf_pages,
|
||||||
original_bitmap, destination_bitmap)
|
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.
|
# Convert images to ppm format if necessary.
|
||||||
if output_format == "ppm":
|
if output_format == "ppm":
|
||||||
convert_to_ppm_format(pngtopnm, latex_file_re.sub("", latex_file))
|
convert_to_ppm_format(pngtopnm, latex_file_re.sub("", latex_file))
|
||||||
|
@ -363,3 +363,39 @@ def string_in_file(string, infile):
|
|||||||
return True
|
return True
|
||||||
f.close()
|
f.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# Returns a list of indexes of pages giving errors extracted from the latex log
|
||||||
|
def check_latex_log(log_file):
|
||||||
|
|
||||||
|
error_re = re.compile("^! ")
|
||||||
|
snippet_re = re.compile("^Preview: Snippet ")
|
||||||
|
data_re = re.compile("([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)")
|
||||||
|
|
||||||
|
found_error = False
|
||||||
|
error_pages = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
for line in open(log_file, 'r').readlines():
|
||||||
|
if not found_error:
|
||||||
|
match = error_re.match(line)
|
||||||
|
if match != None:
|
||||||
|
found_error = True
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
match = snippet_re.match(line)
|
||||||
|
if match == None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
found_error = False
|
||||||
|
match = data_re.search(line)
|
||||||
|
if match == None:
|
||||||
|
error("Unexpected data in %s\n%s" % (log_file, line))
|
||||||
|
|
||||||
|
error_pages.append(int(match.group(1)))
|
||||||
|
|
||||||
|
except:
|
||||||
|
warning('check_latex_log: Unable to open "%s"' % log_file)
|
||||||
|
warning(`sys.exc_type` + ',' + `sys.exc_value`)
|
||||||
|
|
||||||
|
return error_pages
|
||||||
|
Loading…
Reference in New Issue
Block a user