Follow us on TwitterFork us on GitHub

Templating Rules

jtex uses nunjucks, which is a javascript port of Jinja templating language with the modifications to allow easy reading and syntax highlighting with LaTeX\LaTeX. The nunjucks ecosystem is compatible with jinja templates, and they are modified with custom rules.


customizedstandard jinja2
Statements[# #]{% %}
Expressions[- -]{{ }}
Comments%# #%{# #}
Line Comment%%##

Statements can be if-blocks or for-loops, a minimal freeform LaTeX\LaTeX example illustrating these would be:

\section{Famous People}
%% Print a list of famous people defined in the context dictionary
[# for person in famous_people #]
\item [], [-person.job-] [# if #]([])[# endif #]
[# endfor #]

#Other environment differences

In addition to the custom syntax we also set the following options:

trim_blockstruefalseFirst newline after a block is removed
autoescapefalsetrueHTML autoescaping feature is disabled

jinja provide a whole host of tags, expressions and filters at global scope.


Some of the main filters used in the LaTeX\LaTeX templates, are, for example, join, title, or trim.


\keywords{[- doc.keywords | join(", ") -]}


\keywords{Keyword1, keyword2}

#Controlling Whitespace

Jinja allows you to strip all leading or trailing whitespace by adding a minus sign (-) to the start or end block or a variable. See nunjucks docs for more information.

The following expression will ensure that a template block, that may be templated over many lines in the template, will only show up on a single line in the exported LaTeX. In this case the syntax is [#- for blocks and [-- for variables.

[#- if parts.acknowledgments -#]
[- parts.acknowledgments -]
[#- endif -#]

This can also be used for inline variables that will have the final output only exist on a single line in the final export.


Note that even though the template is being rendered from a javascript environment, expressions and comparisons are Python-like. That is, they follow and over && as well as not over !.