1) SIGSEGV with previews (no math macros involved). I believe this is the one I mentioned in a previous message. See the attached lyx-preview-sigsegv.lyx for instructions.
2) Closing a file whose previews are being generated results in an error dialog "Could not remove the temporary directory /tmp/lyx_tmpdir.LXSnBrW17125" and the following output on the terminal:
Warning: Could not remove temporary directory ----------------------------------------Could not remove the temporary directory /tmp/lyx_tmpdir.LXSnBrW17125/lyx_tmpbuf0 Warning: Warning in extract_resolution! Unable to open "lyxpreviewQ17125_legacy.log"
Warning: <type 'exceptions.IOError'>,IOError(2, 'No such file or directory') Warning: check_latex_log: Unable to open "lyxpreviewQ17125_legacy.log" Warning: <type 'exceptions.IOError'>,IOError(2, 'No such file or directory')Warning: Warning in legacy_extract_metrics_info! Unable to open "lyxpreviewQ17125_legacy.log"
Warning: <type 'exceptions.IOError'>,IOError(2, 'No such file or directory') Error: Failed to extract metrics info from lyxpreviewQ17125_legacy.log So there's some additional cleanup to do now when closing a file.3) Previews have the incorrect size with layouts that offer font sizes other than 1[0-2]pt (lyx-preview-fontsize.lyx). The legacy method offers a function that retrieves the actual font size and calculates the actual dpi. Attached is a patch (extract_resolution.diff) that imports this function in the new script.
(It's possible to just replace:
documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
with:
documentclass_re = re.compile("(\\\\documentclass\[)([0-9]+pt,?)(.+)")
but this does not take into account custom classes, options, preambles,
etc. If this path is retained, here's the result of $grep FontSize
*.layout:
achemso.layout: FontSize 10|11|12 acmsiggraph.layout: FontSize 9|10|11|12 agutex.layout: FontSize 10|11|12 amsart.layout: FontSize 8|9|10|11|12 amsbook.layout: FontSize 8|9|10|11|12 apa6.layout: FontSize 10|11|12 apa.layout: FontSize 6|8|10|12 broadway.layout:FontSize 12 dtk.layout: FontSize default # only 10pt in fact of A5 elsarticle.layout: FontSize 10|11|12 elsart.layout:# FontSize "default" # controlled by class entcs.layout: FontSize 11 extarticle.layout: FontSize 8|9|10|11|12|14|17|20 extbook.layout: FontSize 8|9|10|11|12|14|17|20 extletter.layout: FontSize 8|9|10|11|12|14|17|20 extreport.layout: FontSize 8|9|10|11|12|14|17|20 foils.layout: FontSize 17|20|25|30 hollywood.layout: FontSize 12 IEEEtran-CompSoc.layout: FontSize 12 IEEEtran.layout: FontSize 9|10|11|12 iopart.layout: FontSize 10|12 jasatex.layout: FontSize 10|11|12 latex8.layout: FontSize 10 ltugboat.layout: FontSize default # only 11pt memoir.layout: FontSize 9|10|11|12|14|17powerdot.layout: FontSize size=8|size=9|size=10|size=11|size=12|size=14|size=17|size=20
sciposter.layout: FontSize 14|17|20|25|30|36 seminar.layout: FontSize 8|9|10|11|12|14|17 siamltex.layout: FontSize 8|9|10|11|12 sigplanconf.layout: FontSize 9|10|11 slides.layout: FontSize | svmono.layout: FontSize 10 svmult.layout: FontSize ""In particular, Powerdot has a special syntax, but the default font size is too big anyways (magnification=2000) so it's better to compute the font size from the log file, and this is precisely what extract_resolution already does.)
lyx-preview-sigsegv.lyx
Description: application/lyx
lyx-preview-fontsize.lyx
Description: application/lyx
diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py
index 9775b0e..f9ee3b3 100755
--- a/lib/scripts/lyxpreview2bitmap.py
+++ b/lib/scripts/lyxpreview2bitmap.py
@@ -77,7 +77,7 @@
import getopt, glob, os, re, shutil, string, sys
-from legacy_lyxpreview2ppm import legacy_conversion_step1
+from legacy_lyxpreview2ppm import legacy_conversion_step1, extract_resolution
from lyxpreview_tools import bibtex_commands, check_latex_log, copyfileobj, \
error, filter_pages, find_exe, find_exe_or_terminate, \
@@ -159,7 +159,6 @@ def extract_metrics_info(dvipng_stdout):
def fix_latex_file(latex_file, pdf_output):
- documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
def_re = re.compile(r"(\\newcommandx|\\global\\long\\def)(\\[a-zA-Z]+)")
tmp = mkstemp()
@@ -167,14 +166,9 @@ def fix_latex_file(latex_file, pdf_output):
changed = False
macros = []
for line in open(latex_file, 'r').readlines():
- if line.startswith("\\documentclass"):
- match = documentclass_re.match(line)
- if match != None:
- changed = True
- line = match.group(1) + match.group(3) + "\n"
- if not pdf_output:
- changed = True
- line += "\\PassOptionsToPackage{draft}{microtype}\n"
+ if not pdf_output and line.startswith("\\documentclass"):
+ changed = True
+ line += "\\PassOptionsToPackage{draft}{microtype}\n"
else:
match = def_re.match(line)
if match != None:
@@ -406,8 +400,8 @@ def main(argv):
progress("Preprocess through lilypond-book: %s" % lilypond)
progress("Altering the latex file for font size and colors")
- # Omit font size specification in latex file and make sure that multiple
- # defined macros and the microtype package don't cause issues.
+ # Make sure that multiple defined macros and the microtype package
+ # don't cause issues in the latex file.
fix_latex_file(latex_file, pdf_output)
if lilypond:
@@ -452,9 +446,10 @@ def main(argv):
# Compile the latex file.
error_pages = []
latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
+ latex_log = latex_file_re.sub(".log", latex_file)
if latex_status:
progress("Will try to recover from %s failure" % latex)
- error_pages = check_latex_log(latex_file_re.sub(".log", latex_file))
+ error_pages = check_latex_log(latex_log)
# The dvi output file name
dvi_file = latex_file_re.sub(".dvi", latex_file)
@@ -490,9 +485,12 @@ def main(argv):
return legacy_conversion_step1(latex_file, dpi, output_format, fg_color,
bg_color, "pdflatex", True)
+ # Retrieve resolution
+ resolution = extract_resolution(latex_log, dpi)
+
# Run the dvi file through dvipng.
dvipng_call = '%s -Ttight -depth -height -D %d -fg "%s" -bg "%s" %s "%s"' \
- % (dvipng, dpi, fg_color_dvipng, bg_color_dvipng, pages_parameter, dvi_file)
+ % (dvipng, resolution, fg_color_dvipng, bg_color_dvipng, pages_parameter, dvi_file)
dvipng_status, dvipng_stdout = run_command(dvipng_call)
if dvipng_status:
