Module tex

Module tex

source code

Convert LaTeX or TeX source to PDF or DVI, and escape strings for LaTeX.

The python-tex project is obsolete! Please have a look at Texcaller.

Python-tex is a convenient interface to the TeX command line tools that handles all kinds of errors without much fuzz.

Temporary files are always cleaned up. The TeX interpreter is automatically re-run as often as necessary, and an exception is thrown in case the output fails to stabilize soon enough. The TeX interpreter is always run in batch mode, so it won't ever get in your way by stopping your application when there are issues with your TeX source. Instead, an exception is thrown that contains all information of the TeX log.

This enables you to debug TeX related issues directly within your application or within an interactive Python interpreter session.

Example:

>>> from tex import latex2pdf
>>> document = ur"""
... \documentclass{article}
... \begin{document}
... Hello, World!
... \end{document}
... """
>>> pdf = latex2pdf(document)
>>> type(pdf)
<type 'str'>
>>> print "PDF size: %.1f KB" % (len(pdf) / 1024.0)
PDF size: 5.6 KB
>>> pdf[:5]
'%PDF-'
>>> pdf[-6:]
'%%EOF\n'

Version: 1.8

Author: Volker Grabsch

License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions
 
convert(tex_source, input_format, output_format, max_runs=5)
Convert LaTeX or TeX source to PDF or DVI.
source code
 
tex2dvi(tex_source, **kwargs)
Convert TeX source to DVI.
source code
 
latex2dvi(tex_source, **kwargs)
Convert LaTeX source to DVI.
source code
 
tex2pdf(tex_source, **kwargs)
Convert TeX source to PDF.
source code
 
latex2pdf(tex_source, **kwargs)
Convert LaTeX source to PDF.
source code
 
escape_latex(s)
Escape a unicode string for LaTeX.
source code
Variables
  __author_email__ = 'vog@notjusthosting.com'
  __url__ = 'http://www.profv.de/python-tex/'
  __classifiers__ = '\n Development Status :: ...
  __package__ = None
Function Details

escape_latex(s)

source code 

Escape a unicode string for LaTeX.

>>> s = u'\\"{}_&%a$b#\nc[]"~<>^`\\'
>>> escape_latex(s)
u"\\textbackslash{}{''}\\{\\}\\_\\&\\%a\\$b\\#\\\\c{[}{]}{''}\\textasciitilde{}\\textless{}\\textgreater{}\\textasciicircum{}{}`\\textbackslash{}"
>>> print s
\"{}_&%a$b#
c[]"~<>^`\
>>> print escape_latex(s)
\textbackslash{}{''}\{\}\_\&\%a\$b\#\\c{[}{]}{''}\textasciitilde{}\textless{}\textgreater{}\textasciicircum{}{}`\textbackslash{}
Parameters:
  • s - : unicode object to escape for LaTeX

Warning:

The source string must not contain empty lines such as:
  • u'n...' -- empty first line
  • u'...nn...' -- empty line in between
  • u'...n' -- empty last line


Variables Details

__classifiers__

Value:
'''
                   Development Status :: 5 - Production/Stable
                   Development Status :: 6 - Mature
                   Development Status :: 7 - Inactive
                   Intended Audience :: Developers
                   License :: OSI Approved :: MIT License
                   Operating System :: OS Independent
                   Programming Language :: Python
...