From 980c68b2b09b0d5c7df76593f666efe6f7bc2215 Mon Sep 17 00:00:00 2001 From: Joel Meyer-Hamme Date: Tue, 20 May 2014 19:08:54 +0200 Subject: [PATCH] Expose latex command tool chain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dvi isn't compatible with quite a few Latex packages. I have been trying to include chemical formulas with the chemfig package. Exposing the tool chain to plugins would be very useful. For the record, I'm currently using: ´´´python latexCmds = [ ["pdflatex", "-interaction=nonstopmode", "tmp.tex"], ["pdflatex", "-interaction=nonstopmode", "tmp.tex"], ["pdfcrop", "tmp.pdf"], ["convert", "-density", "300", "tmp-crop.pdf", "tmp.png"] ] ´´´ --- anki/latex.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/anki/latex.py b/anki/latex.py index 0d447952b..d5d4711fb 100644 --- a/anki/latex.py +++ b/anki/latex.py @@ -7,8 +7,11 @@ from anki.utils import checksum, call, namedtmp, tmpdir, isMac, stripHTML from anki.hooks import addHook from anki.lang import _ -latexCmd = ["latex", "-interaction=nonstopmode"] -latexDviPngCmd = ["dvipng", "-D", "200", "-T", "tight"] +latexCmds = [ + ["latex", "-interaction=nonstopmode", "tmp.tex"], + ["dvipng", "-D", "200", "-T", "tight", "tmp.dvi", "-o", "tmp.png"] +] + build = True # if off, use existing media but don't create new regexps = { "standard": re.compile(r"\[latex\](.+?)\[/latex\]", re.DOTALL | re.IGNORECASE), @@ -89,14 +92,10 @@ package in the LaTeX header instead.""") % bad oldcwd = os.getcwd() png = namedtmp("tmp.png") try: - # generate dvi - os.chdir(tmpdir()) - if call(latexCmd + ["tmp.tex"], stdout=log, stderr=log): - return _errMsg("latex", texpath) - # and png - if call(latexDviPngCmd + ["tmp.dvi", "-o", "tmp.png"], - stdout=log, stderr=log): - return _errMsg("dvipng", texpath) + # generate png + for latexCmd in latexCmds: + if call(latexCmd, stdout=log, stderr=log): + return _errMsg(latexCmd[0], texpath) # add to media shutil.copyfile(png, os.path.join(mdir, fname)) return