]> git.lyx.org Git - features.git/commitdiff
Fix some preview issues reported on the devel list.
authorEnrico Forestieri <forenr@lyx.org>
Tue, 2 Jun 2015 22:19:51 +0000 (00:19 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Tue, 2 Jun 2015 22:24:54 +0000 (00:24 +0200)
* Provide for vector fonts only if needed.
* Make sure microtype doesn't throw a trantum in dvi mode.
* Use correct macro definition in preview insets.

lib/scripts/legacy_lyxpreview2ppm.py
lib/scripts/lyxpreview2bitmap.py
src/insets/InsetPreview.cpp

index 38dc825fdd23beac6aa0d76b7c1cf957cca2f398..732e3b158a8677d4b19588c1fc377e7975c84682 100644 (file)
@@ -233,8 +233,11 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
 \definecolor{bg}{rgb}{%s}
 \pagecolor{bg}
 \usepackage[%s,tightpage]{preview}
-\IfFileExists{lmodern.sty}{\usepackage{lmodern}}{\usepackage{ae,aecomp}}
 \makeatletter
+\def\t@a{cmr}
+\if\f@family\t@a
+\IfFileExists{lmodern.sty}{\usepackage{lmodern}}{\usepackage{ae,aecompl}}
+\fi
 \g@addto@macro\preview{\begingroup\color{bg}\special{ps::clippath fill}\color{fg}}
 \g@addto@macro\endpreview{\endgroup}
 \makeatother
index 5eca9599908f6c6faccb97dec0c79e23dfef2a11..7d4787e01e08c32d3865c2cc228f6082e8a9dab3 100755 (executable)
@@ -158,13 +158,46 @@ def extract_metrics_info(dvipng_stdout):
     return results
 
 
-def fix_latex_file(latex_file):
+def fix_latex_file(latex_file, pdf_output):
     documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
+    usepackage_re = re.compile("\\\\usepackage")
+    userpreamble_re = re.compile("User specified LaTeX commands")
+    enduserpreamble_re = re.compile("\\\\makeatother")
+    begindoc_re = re.compile("\\\\begin\{document\}")
 
     tmp = mkstemp()
 
+    in_doc_body = 0
+    in_user_preamble = 0
+    usepkg = 0
     changed = 0
     for line in open(latex_file, 'r').readlines():
+        if in_doc_body:
+            if changed:
+                tmp.write(line)
+                continue
+            else:
+                break
+
+        if begindoc_re.match(line) != None:
+            in_doc_body = 1
+
+        if not pdf_output and not usepkg:
+            if userpreamble_re.search(line) != None:
+                in_user_preamble = 1
+            elif enduserpreamble_re.search(line) != None:
+                in_user_preamble = 0
+            if usepackage_re.match(line) != None and in_user_preamble:
+                usepkg = 1
+                changed = 1
+                tmp.write("\\def\\t@a{microtype}\n")
+                tmp.write("\\let\\oldusepkg\usepackage\n")
+                tmp.write("\\def\\usepackage{\\@ifnextchar[\\@usepkg{\@usepkg[]}}\n")
+                tmp.write("\\def\@usepkg[#1]#2{\\def\\t@b{#2}")
+                tmp.write("\\ifx\\t@a\\t@b\\else\\oldusepkg[#1]{#2}\\fi}\n")
+                tmp.write(line)
+                continue
+
         match = documentclass_re.match(line)
         if match == None:
             tmp.write(line)
@@ -391,9 +424,9 @@ 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 multiple
-    # defined macros are not an issue.
-    fix_latex_file(latex_file)
+    # Omit font size specification in latex file and make sure that
+    # the microtype package doesn't cause issues in dvi mode.
+    fix_latex_file(latex_file, pdf_output)
 
     if lilypond:
         progress("Preprocess the latex file through %s" % lilypond_book)
index 36e866c37cfa142f887299773c3aed22d067fa6a..2e240da3be317011c5f1fb84c150cf5f2f021a81 100644 (file)
@@ -89,7 +89,7 @@ void InsetPreview::preparePreview(DocIterator const & pos) const
                MacroData const * data = buffer->getMacro(*it, pos, true);
                if (data) {
                        odocstringstream macro_def;
-                       data->write(macro_def, false);
+                       data->write(macro_def, true);
                        docstring const md = macro_def.str();
                        macro_def << endl;
                        bool is_newcomm = prefixIs(md, from_ascii("\\newcomm"));