Skip to main content

Templating with LaTex and Python

This year I'm trying to generate quizzes automatically to the degree possible.

I've cooked up a templating scheme using jijna2 that works with LaTeX templates.

This article was very helpful.

Now that this has been published to pypi you can simply:

pip install genlatex

Once you have that, you can 'cd' to the directory with your template and data generator file and run getlatex using:

genlatex [ options ] dataGeneratorFile.py

For example to create 10 versions of the example you could:

cd example

genlatex -n 10 tlo-EX-Data.py

Then check in the folder for your .tex files!

To convert to pdf en-masse, with bash:

find *.tex |  xargs -n 1 pdflatex

If your dataGeneratorFile needs to import any modules you should add '.' to the PYTHONPATH, e.g.,

PYTHONPATH=. genlatex -n 10 tlo-EX-Data.py

There is a shell script "buildZip.sh" that creates an importable .zip file that can be used to import quizzes into Sakai. It may also work for other LMS variations. Untested!

Update: Now you can run the full docker (Dockerfile-w-latex) version:

docker run --rm -it -v `pwd`:/work/src genlatex-full doExport.sh -n 10 tlo-EX-Data.py

Or the mini-docker (Dockerfile)

docker run --rm -it -v `pwd`:/work/src genlatex buildTeXs.sh -n 10 tlo-EX-Data.py

to build the mini-docker (without a full LaTeX install ~1.4GB)

docker build -t genlatex .

to build the full docker build (with a full LaTeX install ~7GB)

docker build -f Dockerfile-w-latex -t genlatex-full .

CHANGES:

v 0.12: Added units to formatters (e.g., latex_float(2.31, units="m"))

v 0.14: add units to latex_float and latex_vec, add some doc tests.

v 0.15: Changed the path handling to make it more Windows friendly.

v 0.16: Update README & other doc-strings

v 0.17: Add file path to items.xml so export.zip would contain individual filenames for students/instructors.

v 0.18: Possible breaking change. latex_float arguments are switching order, units first to save typing.
        Now you can type simply: latex_float(2.31,"m") and "m" will be units. If you want a different format
        then 'fmt' must be supplied as a *third* argument, or with a keyword, e.g. latex_float(2.234, fmt="{:0.2g}").

        Also, added a '-0' detector that should convert these to '0'.

v 0.19: Modified the attachment file paths so that Canvas would accept them. Unfortunately canvas does not
  	    support file upload questions in their current quiz tool.

v 0.20: Added eunit formatter to use "engineering" units.

v 0.24: Various changes, includeing command line variables in templates.

v 0.25: Force wheel in pypi

Metadata

Release files for genlatex 0.25

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genlatex 0.25
File Size Uploaded Provenance Actions
genlatex-0.25.tar.gz 6.9 kB Without provenance Details for genlatex-0.25.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genlatex 0.25
File Interpreter ABI Platform Actions
genlatex-0.25-py3-none-any.whl Python 3 none any Details for genlatex-0.25-py3-none-any.whl

Total release size: 14.7 kB

Release files / genlatex-0.25.tar.gz

Download URL genlatex-0.25.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
05d1a338bcb77ce8ed779492e3ccce1ead8a9293ede956c932bdc6f46a0b3e2c
BLAKE2b-256 checksum
How to use checksums
69462a4a0ad01f47e4ed1f37ea9fb03e14647c8b00f9e10390685ad8c974e051
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Release files / genlatex-0.25-py3-none-any.whl

Download URL genlatex-0.25-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bdcd25921115cd3bebc8e3099e2fd80e872785af8c3a0203e3ae2866bd32618
BLAKE2b-256 checksum
How to use checksums
35a8dd210fc562508621a805b3be3551b4368283bd8404fd28aa37d65ec9b875
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Security for genlatex 0.25

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page