X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/5f92f5a341c58a30c0a5c0d64ba3ed498bb9db85..43f9887701dbe454dcaee6f4f68afe7e3d14ebe6:/librarian/embeds/latex.py?ds=sidebyside diff --git a/librarian/embeds/latex.py b/librarian/embeds/latex.py index e10d165..0201d08 100644 --- a/librarian/embeds/latex.py +++ b/librarian/embeds/latex.py @@ -1,9 +1,11 @@ +# -*- coding: utf-8 -*- import os import shutil from subprocess import call, PIPE from tempfile import mkdtemp from librarian import get_resource -from . import DataEmbed, create_embed, downgrades_to, converts_to +from . import DataEmbed, create_embed, downgrades_to + class LaTeX(DataEmbed): @downgrades_to('image/png') @@ -15,7 +17,7 @@ class LaTeX(DataEmbed): f.write((tmpl % {'code': self.data}).encode('utf-8')) call(['xelatex', '-interaction=batchmode', '-output-directory', tempdir, fpath], stdout=PIPE, stderr=PIPE) call(['convert', '-density', '150', os.path.join(tempdir, 'doc.pdf'), '-trim', - os.path.join(tempdir, 'doc.png')]) + os.path.join(tempdir, 'doc.png')]) pngdata = open(os.path.join(tempdir, 'doc.png')).read() shutil.rmtree(tempdir) return create_embed('image/png', data=pngdata)