X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/12b5230d8fdb3ad995e867fb5d58a69e8a627e68..318d79c6ec02163ec898a66723055da25837346a:/librarian/embeds/latex.py?ds=inline diff --git a/librarian/embeds/latex.py b/librarian/embeds/latex.py index 0201d08..8425d03 100644 --- a/librarian/embeds/latex.py +++ b/librarian/embeds/latex.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals + import os import shutil from subprocess import call, PIPE @@ -10,14 +12,14 @@ from . import DataEmbed, create_embed, downgrades_to class LaTeX(DataEmbed): @downgrades_to('image/png') def to_png(self): - tmpl = open(get_resource('res/embeds/latex/template.tex')).read().decode('utf-8') + tmpl = open(get_resource('res/embeds/latex/template.tex'), 'rb').read().decode('utf-8') tempdir = mkdtemp('-librarian-embed-latex') fpath = os.path.join(tempdir, 'doc.tex') - with open(fpath, 'w') as f: + with open(fpath, 'wb') as f: 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')]) - pngdata = open(os.path.join(tempdir, 'doc.png')).read() + pngdata = open(os.path.join(tempdir, 'doc.png'), 'rb').read() shutil.rmtree(tempdir) return create_embed('image/png', data=pngdata)