Convert GMPL (GNU MathProg) models into LaTeX.
Project description
gmpl-tex
Convert GMPL (GNU MathProg) optimization models into LaTeX, so the constraints, sets, parameters, variables and objectives you wrote for a solver can go straight into a paper with readable, renamed symbols.
The tool works in two phases so you stay in control of the notation:
- Lookup-table generation - parse
model.modinto a JSON table listing every set, parameter, variable, constraint and objective name. Each name maps to a label you can edit. - LaTeX generation - render the model to LaTeX, substituting your edited labels from the JSON table.
Requirements
- Python 3.10 or newer. Check what you have:
- Windows:
py --version - macOS / Linux:
python3 --version - If it's missing, install from python.org. On Windows, tick "Add python.exe to PATH" in the installer.
- Windows:
lark- installed automatically.
Install
pip install gmpl-tex
After installing, the command gmpl-tex works the same on every platform.
Windows users: use
py -m pip install gmpl-texifpipisn't on your PATH.
Usage
gmpl-tex model.mod [lookup.json] --json
gmpl-tex model.mod [lookup.json] [output.tex] --latex
The example below illustrates a full run of the application.
1. Generate the editable lookup table (generates model.json)
gmpl-tex model.mod --json
For a model like
set I;
param d{i in I} >= 0;
var x{i in I} >= 0;
s.t. demand{i in I}: x[i] >= d[i];
minimize cost: sum{i in I} x[i];
model.json is:
{
"sets": { "I": "I" },
"parameters": { "d": "d" },
"variables": { "x": "x" },
"constraints": { "demand": "demand" },
"objectives": { "cost": "cost" }
}
2. Open model.json and edit the labels you wish to rename
//Example: "cost" to "c"
{
...
"objectives": { "cost": "c" }
}
3. Render LaTeX using your edited labels (generates model.tex)
gmpl-tex model.mod model.json --latex
The following command generates a .tex file with mathematical statements
in LaTeX, based on the labels in the model.json file.
Note: If you skip step 1 and run
gmpl-tex model.mod --latexdirectly, a default table is created automatically (labels equal to the raw names) and used. If amodel.jsonalready exists next to the model, it is reused as-is and never overwritten.
An example model is included under examples/model.mod.
Troubleshooting
-
Subscripted label values warning: LaTeX doesn't like multiple
'_'in names. While the converter has no problem generating code with multiple name subscripts, LaTeX will eventually throw aDouble subscripterror on compilation. To generate valid LaTeX code, remove the '_' in any label values inside the json table. Then re-run the converter with--latex. -
A symbol shows up in red in the output: That symbol is missing from your
model.jsonlookup table.
License
MIT - see LICENSE.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmpl_tex-0.1.1.dev1.tar.gz.
File metadata
- Download URL: gmpl_tex-0.1.1.dev1.tar.gz
- Upload date:
- Size: 367.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.12.13"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.12.13","system":{"name":"Linux","release":"6.12.94+deb13-amd64"}} HTTPX2/2.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dbfeca99e0fee3b0adbc44cdedbbd82b0a54f4dd9907b065003cd032056390a
|
|
| MD5 |
c4d4bee29bdb086e60deeea1bdda6110
|
|
| BLAKE2b-256 |
d2d91e54fd1eb3e112e065b8f43c8d88e1e385e0cca584bee18e89e89e5fb3df
|
File details
Details for the file gmpl_tex-0.1.1.dev1-py3-none-any.whl.
File metadata
- Download URL: gmpl_tex-0.1.1.dev1-py3-none-any.whl
- Upload date:
- Size: 377.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.12.13"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.12.13","system":{"name":"Linux","release":"6.12.94+deb13-amd64"}} HTTPX2/2.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf6206b1de56036a59c4bc166a4249f140ee81c73206c8a17a720a19cf190af4
|
|
| MD5 |
79458e778b897f7b43de369b1a155e09
|
|
| BLAKE2b-256 |
cfdc7e24f40fd4c271a4d699de35b2914e7471664f06d6f0570fc86fd72b9067
|