Merge pull request #79 from joelmeyerhamme/patch-1

Expose latex command tool chain
This commit is contained in:
Damien Elmes 2014-06-03 16:19:59 +09:00
commit 4e41c61e73

View file

@ -7,8 +7,11 @@ from anki.utils import checksum, call, namedtmp, tmpdir, isMac, stripHTML
from anki.hooks import addHook from anki.hooks import addHook
from anki.lang import _ from anki.lang import _
latexCmd = ["latex", "-interaction=nonstopmode"] latexCmds = [
latexDviPngCmd = ["dvipng", "-D", "200", "-T", "tight"] ["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 build = True # if off, use existing media but don't create new
regexps = { regexps = {
"standard": re.compile(r"\[latex\](.+?)\[/latex\]", re.DOTALL | re.IGNORECASE), "standard": re.compile(r"\[latex\](.+?)\[/latex\]", re.DOTALL | re.IGNORECASE),
@ -89,14 +92,10 @@ package in the LaTeX header instead.""") % bad
oldcwd = os.getcwd() oldcwd = os.getcwd()
png = namedtmp("tmp.png") png = namedtmp("tmp.png")
try: try:
# generate dvi # generate png
os.chdir(tmpdir()) for latexCmd in latexCmds:
if call(latexCmd + ["tmp.tex"], stdout=log, stderr=log): if call(latexCmd, stdout=log, stderr=log):
return _errMsg("latex", texpath) return _errMsg(latexCmd[0], texpath)
# and png
if call(latexDviPngCmd + ["tmp.dvi", "-o", "tmp.png"],
stdout=log, stderr=log):
return _errMsg("dvipng", texpath)
# add to media # add to media
shutil.copyfile(png, os.path.join(mdir, fname)) shutil.copyfile(png, os.path.join(mdir, fname))
return return