Metadata-Version: 2.4
Name: bopytex
Version: 1.0.0rc1
Summary: Command line tool for compiling latex with python command embedded
License: GPLv3
Author: Bertrand Benjamin
Author-email: benjamin.bertrand@opytex.org
Requires-Python: >=3.10,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: Jinja2 (>=3.1.2,<4.0.0)
Requires-Dist: click (>=8.1.3,<9.0.0)
Description-Content-Type: text/markdown

# Bopytex

[![Build Status](https://forge.opytex.org/benjamin/Bopytex/badges/workflows/publish.yml/badge.svg)](https://forge.opytex.org/benjamin/Bopytex/actions)

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.

## Installing

Bopytex depends on `texlive` and `textlive-extra-utils` (for latexmk and pdfjoin)

Install and update using [pip](https://pip.pypa.io/en/stable/quickstart/), from the forge's package registry:

    pip install -U bopytex --index-url https://forge.opytex.org/api/packages/benjamin/pypi/simple/

## Simple example

``` latex
% save this as tpl_simple.tex
\documentclass[12pt]{article}

\title{Bopytex example -- {{ number }}}

\begin{document}

\maketitle
%- set a = 10
%- set n = 2
We have two variables
\begin{itemize}
    \item a: \Var{a}
    \item n: \Var{n}
\end{itemize}

\section{Variables}
\subsection{subject}
\begin{itemize}
%- for k,v in subject.items()
    \item
\begin{verbatim}
    \Var{k}: \Var{v}
\end{verbatim}
%- endfor
\end{itemize}
\subsection{options}
\begin{itemize}
%- for k,v in options.items()
    \item
\begin{verbatim}
    \Var{k}: \Var{v}
\end{verbatim}
%- endfor
\end{itemize}

\end{document}

```

The following command produces the [joined_example.pdf](./example/simple/joined_example.pdf) document

``` bash
$ bopytex tpl_simple.tex
```

## How I use it

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.

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

random.seed(0) # Controlling the seed allows to make subject reproductible

direct_access = {
    "Expression": Expression,
}
```

Every variables, objects or function inside this file will be available inside the template.

``` latex
% tpl_example.tpl
\documentclass[12pt]{article}

\title{Bopytex with Mapytex example -- \Var{ subject.name }}

\begin{document}

\maketitle

%- set e = Expression.random("{a} + {b}")
\Var{e}

\Var{e.simplify()}


\section{Variables}
\subsection{subject}
\begin{itemize}
%- for k,v in subject.items()
    \item
\begin{verbatim}
    \Var{k}: \Var{v}
\end{verbatim}
%- endfor
\end{itemize}
\subsection{options}
\begin{itemize}
%- for k,v in options.items()
    \item
\begin{verbatim}
    \Var{k}: \Var{v}
\end{verbatim}
%- endfor
\end{itemize}

\end{document}
```

Information about my students are stored in a csv file (here `students.csv`)

``` csv
"Name","Age","Email","fraction level","calculus level"
"Spike Tucker","22","s.tucker@randatmail.com","7","3"
"Martin Payne","21","m.payne@randatmail.com","7","3"
"Kimberly Baker","20","k.baker@randatmail.com","1","8"
"Emma Bailey","29","e.bailey@randatmail.com","2","5"
"Nicholas Taylor","28","n.taylor@randatmail.com","3","3"
```

Then I can produce a [subject for each of my student](./example/usecase/joined_example.pdf)

``` bash
$ bopytex tpl_simple.tex -s students.csv -c bopytex_config.py
```


## Running examples

I build two examples base of the simple example and how I use it. They are playable through dockerfiles with make commands.

For the simple example

    make docker-simple

For how I use it

    make docker-usecase

