from lyxpreview_tools import copyfileobj, error, filter_pages, find_exe, \
find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
latex_file_re, make_texcolor, mkstemp, pdflatex_commands, progress, \
- run_command, warning, write_metrics_info
+ run_command, run_latex, warning, write_metrics_info
def usage(prog_name):
error("Unable to move color info into the latex file")
# Compile the latex file.
- latex_call = '%s "%s"' % (latex, latex_file)
-
- latex_status, latex_stdout = run_command(latex_call)
- if latex_status:
- warning("%s had problems compiling %s" \
- % (os.path.basename(latex), latex_file))
+ latex_status, latex_stdout = run_latex(latex, latex_file)
if pdf_output:
return legacy_conversion_step3(latex_file, dpi, output_format, True, skipMetrics)
filter_pages(latex_file, pdf_latex_file, failed_pages)
# pdflatex call
- pdflatex_call = '%s "%s"' % (pdflatex, pdf_latex_file)
- pdflatex_status, pdflatex_stdout = run_command(pdflatex_call)
- if pdflatex_status:
- warning("%s had problems compiling %s" \
- % (os.path.basename(pdflatex), pdf_latex_file))
+ pdflatex_status, pdflatex_stdout = run_latex(pdflatex, pdf_latex_file)
pdf_file = latex_file_re.sub(".pdf", pdf_latex_file)
# --fg=<color>: The foreground color as a hexadecimal string, eg '000000'.
# --bg=<color>: The background color as a hexadecimal string, eg 'faf0e6'.
# --latex=<exe>: The converter for latex files. Default is latex.
+# --bibtex=<exe>: The converter for bibtex files. Default is bibtex.
# --lilypond: Preprocess through lilypond-book. Default is false.
# --lilypond-book=<exe>:
# The converter for lytex files. Default is lilypond-book.
from legacy_lyxpreview2ppm import legacy_conversion_step1
-from lyxpreview_tools import copyfileobj, error, filter_pages, find_exe, \
- find_exe_or_terminate, join_metrics_and_rename, latex_commands, \
- latex_file_re, make_texcolor, mkstemp, pdflatex_commands, progress, \
- run_command, warning, write_metrics_info
+from lyxpreview_tools import bibtex_commands, copyfileobj, error, \
+ filter_pages, find_exe, find_exe_or_terminate, join_metrics_and_rename, \
+ latex_commands, latex_file_re, make_texcolor, mkstemp, pdflatex_commands, \
+ progress, run_command, run_latex, run_tex, warning, write_metrics_info
def usage(prog_name):
--fg=<color>: Foreground color (default: black, ie '000000')
--bg=<color>: Background color (default: white, ie 'ffffff')
--latex=<exe>: Specify the executable for latex (default: latex)
+ --bibtex=<exe>: Specify the executable for bibtex (default: bibtex)
--lilypond: Preprocess through lilypond-book (default: false)
--lilypond-book=<exe>:
The executable for lilypond-book (default: lilypond-book)
dpi = 128
fg_color = "000000"
bg_color = "ffffff"
+ bibtex = None
latex = None
lilypond = False
lilypond_book = None
# Parse and manipulate the command line arguments.
try:
- (opts, args) = getopt.gnu_getopt(argv[1:], "dhv", ["bg=", "debug",
- "dpi=", "fg=", "help", "latex=", "lilypond", "lilypond-book=",
- "png", "ppm", "verbose"])
+ (opts, args) = getopt.gnu_getopt(argv[1:], "dhv", ["bibtex=", "bg=",
+ "debug", "dpi=", "fg=", "help", "latex=", "lilypond",
+ "lilypond-book=", "png", "ppm", "verbose"])
except getopt.GetoptError, err:
error("%s\n%s" % (err, usage(script_name)))
if opt in ("-h", "--help"):
print usage(script_name)
sys.exit(0)
+ elif opt == "--bibtex":
+ bibtex = [val]
elif opt == "--bg":
bg_color = val
elif opt in ("-d", "--debug"):
# External programs used by the script.
latex = find_exe_or_terminate(latex or latex_commands)
+ bibtex = find_exe(bibtex or bibtex_commands)
if lilypond:
lilypond_book = find_exe_or_terminate(lilypond_book or ["lilypond-book"])
progress("Latex command: %s" % latex)
progress("Latex produces pdf output: %s" % pdf_output)
+ progress("Bibtex command: %s" % bibtex)
progress("Lilypond-book command: %s" % lilypond_book)
progress("Preprocess through lilypond-book: %s" % lilypond)
progress("Altering the latex file for font size and colors")
warning("Unable to move color info into the latex file")
# Compile the latex file.
- latex_call = '%s "%s"' % (latex, latex_file)
-
- latex_status, latex_stdout = run_command(latex_call)
- if latex_status:
- warning("%s had problems compiling %s" \
- % (os.path.basename(latex), latex_file))
+ latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
# The dvi output file name
dvi_file = latex_file_re.sub(".dvi", latex_file)
# A repository of the following functions, used by the lyxpreview2xyz scripts.
# copyfileobj, error, find_exe, find_exe_or_terminate, make_texcolor, mkstemp,
-# progress, run_command, warning
+# progress, run_command, run_latex, warning
# Requires python 2.4 or later (subprocess module).
debug = False
verbose = False
-# Known flavors of latex
+# Known flavors of latex and bibtex
+bibtex_commands = ("bibtex", "bibtex8", "biber")
latex_commands = ("latex", "pplatex", "platex", "latex2e")
pdflatex_commands = ("pdflatex", "xelatex", "lualatex")
original_metrics[legacy_index] = (index, metric)
else:
original_metrics.insert(legacy_index, (index, metric))
+
+
+def run_latex(latex, latex_file, bibtex = None):
+ # Run latex
+ latex_status, latex_stdout = run_tex(latex, latex_file)
+
+ if bibtex is None:
+ return latex_status, latex_stdout
+
+ # The aux and log output file names
+ aux_file = latex_file_re.sub(".aux", latex_file)
+ log_file = latex_file_re.sub(".log", latex_file)
+
+ # Run bibtex/latex if necessary
+ progress("Checking if a bibtex run is necessary")
+ if string_in_file(r"\bibdata", aux_file):
+ bibtex_status, bibtex_stdout = run_tex(bibtex, aux_file)
+ latex_status, latex_stdout = run_tex(latex, latex_file)
+ # Rerun latex if necessary
+ progress("Checking if a latex rerun is necessary")
+ if string_in_file("Warning: Citation", log_file):
+ latex_status, latex_stdout = run_tex(latex, latex_file)
+
+ return latex_status, latex_stdout
+
+
+def run_tex(tex, tex_file):
+ tex_call = '%s "%s"' % (tex, tex_file)
+
+ tex_status, tex_stdout = run_command(tex_call)
+ if tex_status:
+ warning("%s had problems compiling %s" \
+ % (os.path.basename(tex), tex_file))
+ return tex_status, tex_stdout
+
+
+def string_in_file(string, infile):
+ if not os.path.isfile(infile):
+ return False
+ f = open(infile, 'r')
+ for line in f.readlines():
+ if string in line:
+ f.close()
+ return True
+ f.close()
+ return False
cs << " --latex=xelatex";
if (buffer_.params().encoding().package() == Encoding::japanese)
cs << " --latex=platex";
+ if (buffer_.params().bibtex_command != "default")
+ cs << " --bibtex=" << quoteName(buffer_.params().bibtex_command);
+ else if (buffer_.params().encoding().package() == Encoding::japanese)
+ cs << " --bibtex=" << quoteName(lyxrc.jbibtex_command);
+ else
+ cs << " --bibtex=" << quoteName(lyxrc.bibtex_command);
if (buffer_.params().bufferFormat() == "lilypond-book")
cs << " --lilypond";