mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Output SVG instead of PNG for LaTeX
This commit is contained in:
parent
52f8a4a75e
commit
da437fa16e
1 changed files with 7 additions and 4 deletions
|
@ -7,11 +7,14 @@ 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 _
|
||||||
|
|
||||||
|
# change this if latexCmds outputs alternate filetype
|
||||||
|
outputFileExt = "svg"
|
||||||
|
|
||||||
# if you modify these in an add-on, you must make sure to take tmp.tex as the
|
# if you modify these in an add-on, you must make sure to take tmp.tex as the
|
||||||
# input, and output tmp.png as the output file
|
# input, and change outputFileExt to the output file extension
|
||||||
latexCmds = [
|
latexCmds = [
|
||||||
["latex", "-interaction=nonstopmode", "tmp.tex"],
|
["latex", "-interaction=nonstopmode", "tmp.tex"],
|
||||||
["dvipng", "-D", "200", "-T", "tight", "tmp.dvi", "-o", "tmp.png"]
|
["dvisvgm", "--no-fonts", "tmp.dvi", "-o", "tmp.%s" % outputFileExt]
|
||||||
# ["dvipng", "-D", "600", "-T", "tight", "-bg", "Transparent", "tmp.dvi", "-o", "tmp.png"]
|
# ["dvipng", "-D", "600", "-T", "tight", "-bg", "Transparent", "tmp.dvi", "-o", "tmp.png"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -51,7 +54,7 @@ def mungeQA(html, type, fields, model, data, col):
|
||||||
def _imgLink(col, latex, model):
|
def _imgLink(col, latex, model):
|
||||||
"Return an img link for LATEX, creating if necesssary."
|
"Return an img link for LATEX, creating if necesssary."
|
||||||
txt = _latexFromHtml(col, latex)
|
txt = _latexFromHtml(col, latex)
|
||||||
fname = "latex-%s.png" % checksum(txt.encode("utf8"))
|
fname = "latex-%s.%s" % (checksum(txt.encode("utf8")), outputFileExt)
|
||||||
link = '<img class=latex src="%s">' % fname
|
link = '<img class=latex src="%s">' % fname
|
||||||
if os.path.exists(fname):
|
if os.path.exists(fname):
|
||||||
return link
|
return link
|
||||||
|
@ -96,7 +99,7 @@ package in the LaTeX header instead.""") % bad
|
||||||
texfile.close()
|
texfile.close()
|
||||||
mdir = col.media.dir()
|
mdir = col.media.dir()
|
||||||
oldcwd = os.getcwd()
|
oldcwd = os.getcwd()
|
||||||
png = namedtmp("tmp.png")
|
png = namedtmp("tmp.%s", outputFileExt)
|
||||||
try:
|
try:
|
||||||
# generate png
|
# generate png
|
||||||
os.chdir(tmpdir())
|
os.chdir(tmpdir())
|
||||||
|
|
Loading…
Reference in a new issue