Doc: update README with docker examples

This commit is contained in:
Bertrand Benjamin 2022-07-19 16:33:51 +02:00
parent 1fd5ca9c96
commit 473f554ebe

125
README.md
View File

@ -2,7 +2,7 @@
[![Build Status](https://drone.opytex.org/api/badges/lafrite/Bopytex/status.svg)](https://drone.opytex.org/lafrite/Bopytex) [![Build Status](https://drone.opytex.org/api/badges/lafrite/Bopytex/status.svg)](https://drone.opytex.org/lafrite/Bopytex)
Bopytex is a command line tool for producing random math exercises with their correction. It embeds [mapytex](https://git.opytex.org/lafrite/Mapytex) and [python](python.org) into [latex](latex-project.org) through [jinja](jinja.pocoo.org). 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 ## Installing
@ -12,84 +12,75 @@ Install and update using [pip](https://pip.pypa.io/en/stable/quickstart/)
## Simple example ## Simple example
Let's say I want an exercise on adding 2 fractions (files are in `examples`). ``` latex
% save this as tpl_simple.tex
\documentclass[12pt]{article}
The *latex* template called `tpl_add_fraction.tex` \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}
%# We can use blocks
\begin{itemize}
%- for i in n
\item \Var{a}
%- endfor
\end{itemize}
\end{document}
```
To create a version a this document type this
``` 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
from random import random
```
Every variables, objects or function inside this file will be available inside the template.
``` latex ``` latex
% tpl_example.tpl
\documentclass[12pt]{article} \documentclass[12pt]{article}
\title{Bopytex with Mapytex example -- \Var{ number }}
\begin{document} \begin{document}
\section{Ajouts de fractions} \maketitle
Adding two fractions %- set e = Expression.random("{a} + {b}")
%- set e = Expression.random("{a} / {b} + {c} / {k*b}", ["b > 1", "k>1"]) \Var{e}
\[
A = \Var{e}
\]
Solution
\[
\Var{e.simplify().explain() | join('=')}
\]
\end{document}
```
Generate latex files and compile those for 2 different subjects. \Var{e.simplify()}
```
bopytex -t tpl_add_fractions.tex -N 2
```
It produces 2 sources files
- `01_add_fractions.tex`
```latex
\documentclass[12pt]{article}
\begin{document}
\section{Ajouts de fractions}
Adding two fractions
\[
A = \frac{- 2}{4} + \frac{7}{8}
\]
Solution
\[
\frac{- 2}{4} + \frac{7}{8}=\frac{- 2 \times 2}{4 \times 2} + \frac{7}{8}=\frac{- 4}{8} + \frac{7}{8}=\frac{- 4 + 7}{8}=\frac{3}{8}
\]
\end{document} \end{document}
``` ```
- `02_add_fractions.tex` Then I can produce multiple documents (3 here)
```latex ``` bash
\documentclass[12pt]{article} $ bopytex tpl_simple.tex -q 3 -c bopytex_config.py
\begin{document}
\section{Ajouts de fractions}
Adding two fractions
\[
A = \frac{8}{9} + \frac{3}{63}
\]
Solution
\[
\frac{8}{9} + \frac{3}{63}=\frac{8 \times 7}{9 \times 7} + \frac{3}{63}=\frac{56}{63} + \frac{3}{63}=\frac{56 + 3}{63}=\frac{59}{63}
\]
\end{document}
``` ```
And a ready to print pdf.
- [ all_add_fraction.pdf ]( ./examples/all_add_fraction.pdf )