pTyX is a python precompiler for LaTeX.
Project description
pTyX
Overview
pTyX is a LaTeX precompilator, written in Python. pTyX enables to generate LaTeX documents, using custom commands or plain python code. One single pTyX file may generate many latex documents, with different values. I developped and used pTyX to make several different versions of a same test in exams, for my student, to discourage cheating. Since it uses sympy library, pTyX has symbolic calculus abilities too.
Installation
pTyX is only tested on GNU/Linux (Ubuntu), but should work on MacOs X too.
Obviously, pTyX needs a working Python installation. Python version 3.8 (at least) is required for pTyX to run.
pTyX also needs a working LaTeX installation. Command pdflatex must be available in your terminal.
The easiest way to install it is using pip.
$ pip install ptyx
You may also download and install the latest version from Github:
$ git clone https://github.com/wxgeo/ptyx.git
$ cd ptyx
$ pip install -e .
Usage
To compile a pTyX file (see below), open a terminal, go to pTyX directory, and write:
$ ptyx my_file.ptyx
For more options:
$ ptyx --help
pTyX file specification
A pTyX file is essentially a LaTeX file, with a .ptyx extension, (optionally) some custom commands, and embedded python code.
To include python code in a pTyX file, use the #PYTHON and #END balise. A special write() command is available, to generate latex code on the flow from python.
This a simple \emph{addition}:\quad
#PYTHON
from random import randint
a = randint(5, 9)
b = randint(2, 4)
write('%s + %s = %s\\' % (a, b, a + b))
#END
Now, some basic \emph{subtraction}:\quad
#PYTHON
write('%s - %s = %s\\' % (a, b, a - b))
#END
To access any python variable outside python code scope, simply add a hashtag before the variable name.
Any valid python expression can also be evaluated this way, using syntax #{python_expr}.
$#a\mul#b=#{a*b}$
However, pTyX has also reserved tags, like conditionals statements #IF, #ELSE, #ENDIF...
(More to come...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ptyx-29.0.0.tar.gz
.
File metadata
- Download URL: ptyx-29.0.0.tar.gz
- Upload date:
- Size: 66.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.1.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43b8fa651c194575b0f670a1166e41ef25bd78cba8542955d2599e3f2a66b85f |
|
MD5 | 6b89dea2ff846cd5f766c846e06a7196 |
|
BLAKE2b-256 | f871cff418d349764e47ab9f51ee20da0ee228a1ecaaa7667af2b49a40040053 |
File details
Details for the file ptyx-29.0.0-py3-none-any.whl
.
File metadata
- Download URL: ptyx-29.0.0-py3-none-any.whl
- Upload date:
- Size: 73.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.1.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7352b46f2ce49b6058bca9ff98fd17e2df22a5e5fe0ef1898daa22ecdd5aa21 |
|
MD5 | 9d83c07fd4c81d7902bcb94d0bb357ae |
|
BLAKE2b-256 | dc8cd1d566d130d1e1aa72fbf60283e5f55eb436ced142dc7c8714a119794863 |