2019-07-11 16:45:33 +00:00
# Bopytex
2020-08-20 14:20:43 +00:00
[![Build Status ](https://drone.opytex.org/api/badges/lafrite/Bopytex/status.svg )](https://drone.opytex.org/lafrite/Bopytex)
2022-07-19 14:33:51 +00:00
Bopytex is a command line tool which embed python into latex. It uses jinja2 to do so with a modified environnement to match with latex syntax.
2019-07-11 16:45:33 +00:00
## Installing
Install and update using [pip ](https://pip.pypa.io/en/stable/quickstart/ )
pip install -U bopytex
## Simple example
``` latex
2022-07-19 14:33:51 +00:00
% save this as tpl_simple.tex
2019-07-11 16:45:33 +00:00
\documentclass[12pt]{article}
2022-07-19 14:33:51 +00:00
\title{Bopytex example -- {{ number }}}
2019-07-11 16:45:33 +00:00
\begin{document}
2022-07-19 14:33:51 +00:00
\maketitle
%- set a = 10
%- set n = 2
We have two variables
\begin{itemize}
\item a: \Var{a}
\item n: \Var{n}
\end{itemize}
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
%# We can use blocks
\begin{itemize}
%- for i in n
\item \Var{a}
%- endfor
\end{itemize}
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
\end{document}
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
```
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
To create a version a this document type this
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
``` bash
$ bopytex tpl_simple.tex
```
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
## How I use it
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
I build this program to produce individual exams subjects for each of my student with the correction associated. I write a template, and bopytex build subject and correction.
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
To produce formulas and values, I use an another tool I an developing: `mapytex <https://git.opytex.org/lafrite/Mapytex` . I am importing it through `bopytex_config.py` .
``` python
# bopytex_config.py
from mapytex import Expression
from random import random
2019-07-11 16:45:33 +00:00
```
2022-07-19 14:33:51 +00:00
Every variables, objects or function inside this file will be available inside the template.
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
``` latex
% tpl_example.tpl
2019-07-11 16:45:33 +00:00
\documentclass[12pt]{article}
2022-07-19 14:33:51 +00:00
\title{Bopytex with Mapytex example -- \Var{ number }}
2019-07-11 16:45:33 +00:00
\begin{document}
2022-07-19 14:33:51 +00:00
\maketitle
%- set e = Expression.random("{a} + {b}")
\Var{e}
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
\Var{e.simplify()}
2019-07-11 16:45:33 +00:00
\end{document}
```
2022-07-19 14:33:51 +00:00
Then I can produce multiple documents (3 here)
2019-07-11 16:45:33 +00:00
2022-07-19 14:33:51 +00:00
``` bash
$ bopytex tpl_simple.tex -q 3 -c bopytex_config.py
```