Skip to main content

Wrappers for calling LaTeX/building LaTeX documents.

Project description

Documentation can be found at .

Allows calling LaTeX from Python without leaving a mess. Similar to the (officially obsolete) tex package, whose successor is not PyPi-installable:

min_latex = (r"\documentclass{article}"
             r"Hello, world!"

from latex import build_pdf

# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)

# look at the first few bytes of the header
print bytes(pdf)[:10]

Also comes with support for using Jinja2 templates to generate LaTeX files.

make_env can be used to create an Environment that plays well with LaTex:

Variables can be used in a LaTeX friendly way: Hello, \VAR{name|e}.

Note that autoescaping is off. Blocks are creating using the block macro:

\BLOCK{if weather is 'good'}

\#{comments are supported as well}
%# and so are line comments

To keep things short, line statements can be used:

%- if weather is good
%- endif

Example use

from jinja2.loaders import FileSystemLoader
from latex.jinja2 import make_env

env = make_env(loader=FileSystemLoader('.'))
tpl = env.get_template('doc.latex')


The base.latex demonstrates how \BLOCK{...} is substituted for {% ... %}:

\BLOCK{block body}\BLOCK{endblock}

Finally, doc.latex shows why the %- syntax is usually preferable:

%- extends "base.latex"

%- block body
Hello, \VAR{name|e}.
%- endblock

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for latex, version 0.7.0
Filename, size & hash File type Python version Upload date
latex-0.7.0.tar.gz (6.5 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page