Skip to main content

A wrapper to easily use Jinja2 for tex-templates.

Project description

A wrapper of Jinja2 for easy rendering of .tex files of all sorts.


pip install jinjatex


The main Jinjatex class provides wrappers to compile tex templates with jinja. Tex is not included, so make sure the binaries are available.

Template Syntax

The jinja template syntax is changed a little to not interference with latex commands:

((( This is a variable )))
((= This is a comment. =))
((* This is a block *))

((= Example =))
((* for value in somelist *))
    ((( value )))
((* endfor *))

Python Bindings

from jinjatex import Jinjatex

from textwrap import dedent

# Example 1: Compile string templates

template_string = dedent(r"""
    % Example Template

    Hi ((( name )))!

    The document will be compiled multiple times, until
    all references etc. are resolved, like this one: \ref{somelabel}


    Some more content.


tex = Jinjatex()

# Return rendered template only
# Compile .tex and return content of .pdf, default engine is pdflatex
with open('result.pdf', 'wb') as file:

# Example 2: Jinja options and other tex compilers
# Assuming a template 'mytemplate.tex' exists in mypackage/tex_templates

from jinja2 import PackageLoader, StrictUndefined

tex = Jinjatex(tex_engine='xelatex',
               loader=PackageLoader('mypackage', 'tex_templates'),

with open('result.pdf', 'wb') as file:

Project details

Download files

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

Source Distribution

jinjatex-0.2.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page