No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Benjamin Bertrand b522c0a174 Doc: ... 11 months ago
pytex Fix: bug with path in pdflatex 11 months ago
.gitignore Start Pytex project 3 years ago
LICENSE Start Pytex project 3 years ago Doc: ... 11 months ago
requirements.txt Update requirement 3 years ago Change name to mypytex in setup to push it to pipy 2 years ago


Pytex is a simple package which make a bridge between Latex and Python.


pip install mypytex


  • Latex template file tpl_test.tex.


%# Init variables
\Block{set a = 1}
%- set b = 2

    \item a = \Var{a}
    \item b = \Var{b}
    \item a + b = \Var{a} + \Var{b} = \Var{a+b}

  • Turn it to latex with pytex
>>> import pytex
>>> pytex.feed("./tpl_test.tex")

It creates a new file 01_test.tex



    \item a = 1
    \item b = 2
    \item a + b = 1 + 2 = 3

  • Compile it
>>> pytex.pdflatex("./01_test.tex")

texenv: Bring Python inside latex

texenv is a jinja2 environment which allow to use python commands inside latex.

  • \Block{…} is the equivalent of {% block …%} in Jinja2. Every python’s commands will be run like in a script. %-… is also available for line statement.
  • \Var{…} is the equivalent of {{…}} which print the statment.

To comment a line for latex and pytex, it has to start with %#.

Compiling tools

update_export_dict: import extract tools inside template

feed: converting template into tex files

pdflatex: Compile files with pdflatex