- Synopsis
texcaller.convert(source, source_format, result_format, max_runs) # returns a pair (result, info)
- Description
These Python functions are simple wrappers around the Texcaller C interface library functions, making TeX typesetting easily accessible from Python.
- Example
from __future__ import division, print_function, unicode_literals
import texcaller
latex = r'''\documentclass{article}
\begin{document}
Hello world!
\end{document}'''
print('PDF size: %.1f KB' % (len(pdf) / 1024))
print('PDF content: %s ... %s' % (pdf[:5], pdf[-6:]))
s = 'Téxt → "with" $peciäl <characters>'
print('Original: %r' % s)
- Beware of
\u
Unfortunately, Python always interprets \uXXXX
sequences in unicode strings (even in raw unicode strings), which interferes badly with common LaTeX commands such as \usepackage{}
. This means every backslash \
which is followed by the character u
needs to be escaped via \u005c
, which looks really strange:
latex = ur'''
\documentclass{article}
\u005cusepackage{amsmath}
\begin{document} Hello math! \end{document}
'''
Fortunately, this problem is easily solved by using raw byte strings, and converting those to unicode strings via the decode()
method:
latex = r'''
\documentclass{article}
\usepackage{amsmath}
\begin{document} Hello math! \end{document}
'''.decode('utf-8')