Hi all!

In 1.4.0 dvipng is used by default for generating instant preview
images of math formulas. One has to adjust preview_scale_factor in
the preference file in order to have a correct size and alignment
for the images.

However, when the latex font size is changed in Document->Settings,
this change is not reflected in the LyX window but it is for the
images generated by dvipng, so the images turn out having the wrong
size and alignment.

To avoid this problem I used the patch to lyxpreview2bitmap.py
pasted at the bottom. It simply omits the font size information
from the latex file before calling latex. In this way one doesn't
have to adjust preview_scale_factor when changing the (latex) font
size.

I think that this should be done directly by LyX, i.e.,
#lyxpreview.tex should be generated by omitting the font size from
the optional arguments of \documentclass.

Btw, I think that it would be useful to add a GUI way for changing
preview_scale_factor.

--
Enrico


--- lyxpreview2bitmap.py.old    2006-01-07 17:31:26.000000000 +0100
+++ lyxpreview2bitmap.py    2006-01-07 17:54:20.000000000 +0100
@@ -49,8 +49,8 @@
 
 from legacy_lyxpreview2ppm import legacy_conversion
 
-from lyxpreview_tools import error, find_exe, \
-     find_exe_or_terminate, run_command
+from lyxpreview_tools import copyfileobj, error, find_exe, \
+     find_exe_or_terminate, mkstemp, run_command
 
 
 # Pre-compiled regular expressions.
@@ -123,6 +123,27 @@
         os.remove(png_file)
 
 
+def fix_latex_file(latex_file):
+    documentclass_re = re.compile("(\\\\documentclass\[)(1[12]pt,)(.+)")
+
+    tmp = mkstemp()
+
+    changed = 0
+    for line in open(latex_file, 'r').readlines():
+        match = documentclass_re.match(line)
+        if match == None:
+            tmp.write(line)
+            continue
+
+        changed = 1
+        tmp.write("%s%s\n" % (match.group(1), match.group(3)))
+
+    if changed:
+        copyfileobj(tmp, open(latex_file,"wb"), 1)
+
+    return
+
+
 def main(argv):
     # Parse and manipulate the command line arguments.
     if len(argv) != 6:
@@ -155,6 +176,9 @@
     if output_format == "ppm":
         pngtopnm = find_exe_or_terminate(["pngtopnm"], path)
 
+    # Omit font size specification in latex file.
+    fix_latex_file(latex_file)
+
     # Compile the latex file.
     latex_call = '%s "%s"' % (latex, latex_file)
 



Reply via email to