Skip to main content

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

Installation

pip install jinjatex

Usage

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
    \documentclass{article}

    \begin{document}
    Hi ((( name )))!

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

    \section{Somesection}
    \label{somelabel}

    Some more content.

    \end{document}
    """)

tex = Jinjatex()

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


# 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'),
               trim_blocks=True,
               undefined=StrictUndefined)

tex.render_template('mytemplate.tex')
with open('result.pdf', 'wb') as file:
    file.write(tex.compile_template('mytemplate.tex'))

Metadata

Release files for jinjatex 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinjatex 0.2
File Size Uploaded
jinjatex-0.2.tar.gz 3.6 kB Details

Release files / jinjatex-0.2.tar.gz

Download URL jinjatex-0.2.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
242723331cdfc8280343aed3d146754feeee487a14f1e4ee853ebf1610cda5b4
BLAKE2b-256 checksum
How to use checksums
794224d0e4b53fc7e2490e2ec7ceac0f77b4ad27dc02f0276e033e00a9020a06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page