Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptyx-28.1.0.tar.gz (62.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptyx-28.1.0-py3-none-any.whl (68.6 kB view details)

Uploaded Python 3

File details

Details for the file ptyx-28.1.0.tar.gz.

File metadata

  • Download URL: ptyx-28.1.0.tar.gz
  • Upload date:
  • Size: 62.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.1.0-17-amd64

File hashes

Hashes for ptyx-28.1.0.tar.gz
Algorithm Hash digest
SHA256 57cb62aa36610c130ee23f819106399ed8715f8c7d7be9ac764f792c285ac98c
MD5 0d4b1a0318c5c7ce19ab88323d502ad1
BLAKE2b-256 ffdfad18c9d7bd41be8e3ae0a3744c2c5fb138d1ced4f748d2f6333fbbaa970e

See more details on using hashes here.

File details

Details for the file ptyx-28.1.0-py3-none-any.whl.

File metadata

  • Download URL: ptyx-28.1.0-py3-none-any.whl
  • Upload date:
  • Size: 68.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.1.0-17-amd64

File hashes

Hashes for ptyx-28.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61c0b2416728e9118475ee71178f4e4fd99a9238203edcaa8d4d9f2e7c7fa6a5
MD5 6c9ec6c308916b71d0420ee04367269e
BLAKE2b-256 afe641dda5ba34d0f07f6d59745a6343afa24578ee6e94507b28539579a174ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page