From: Enrico Forestieri Date: Tue, 2 Jun 2015 22:19:51 +0000 (+0200) Subject: Fix some preview issues reported on the devel list. X-Git-Tag: 2.2.0alpha1~568 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3924030e828592677178a2f87908f70de0e3268b;p=features.git Fix some preview issues reported on the devel list. * 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. --- diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py index 38dc825fdd..732e3b158a 100644 --- a/lib/scripts/legacy_lyxpreview2ppm.py +++ b/lib/scripts/legacy_lyxpreview2ppm.py @@ -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 diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py index 5eca959990..7d4787e01e 100755 --- a/lib/scripts/lyxpreview2bitmap.py +++ b/lib/scripts/lyxpreview2bitmap.py @@ -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) diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp index 36e866c37c..2e240da3be 100644 --- a/src/insets/InsetPreview.cpp +++ b/src/insets/InsetPreview.cpp @@ -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"));