Convert GMPL (GNU MathProg) models into LaTeX.
Project description
gmpl-tex
Convert GMPL (GNU MathProg) optimization models into LaTeX, so the sets, parameters, variables, constraints and objectives you wrote for a solver can go straight into a paper with readable, renamed symbols.
Either way you use it, the tool works in two phases so you stay in control of the notation:
- Lookup table - every name in the model is collected into a table, where each raw name maps to a label you can edit.
- LaTeX generation - the model is rendered to LaTeX using your edited labels.
There are two front-ends:
gmpl-tex-web- a local web app: paste or drop a model, rename labels, and watch the LaTeX render live. Best for interactive work.gmpl-tex- a command-line tool: a scriptable two-step (JSON table → LaTeX) for batch use.
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:
larkandnicegui- installed automatically.
Install
pip install gmpl-tex
One install gives you both front-ends: the gmpl-tex command line and the
gmpl-tex-web UI.
Windows: use
py -m pip install gmpl-texifpipisn't on your PATH.
Web UI
gmpl-tex-web # opens http://localhost:8080 in your browser
gmpl-tex-web 9000 # ... on a different port
The app runs only on your machine - nothing is uploaded or reachable from the network. Closing the terminal stops it.
How to use it:
- Add your model - paste GMPL into the editor on the left, or drop / click to
upload a
.modfile. - Rename labels - in the middle lookup table, each row maps a raw name to the label you want in the output. Edits apply instantly. The section tabs (Sets, Parameters, Variables, Constraints, Objectives) filter the view.
- Take the LaTeX - on the right, List shows each statement rendered; expand a card to edit or copy that single line. Tex shows the full document to copy or download. Both follow the active section tab.
The three panes: model editor (left), editable lookup table (middle), live preview (right).
Editing a label in the lookup table updates the rendered statement immediately.
The Tex tab shows the full LaTeX document, ready to copy or download.
Command line
gmpl-tex model.mod [lookup.json] --json
gmpl-tex model.mod [lookup.json] [output.tex] --latex
1. Generate the editable lookup table (writes 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. Edit the labels you want to rename
// Example: rename "cost" to "c"
{
...
"objectives": { "cost": "c" }
}
3. Render LaTeX using your edited labels (writes model.tex)
gmpl-tex model.mod model.json --latex
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. An existingmodel.jsonnext to the model is reused as-is and never overwritten.
An example model is included under examples/model.mod.
(Not sure which front-end you have? Run gmpl-tex --help or gmpl-tex-web --help - each points you to the other.)
Troubleshooting
- Double subscript on LaTeX compile: LaTeX rejects multiple
_in a symbol. The converter will happily emit them, but LaTeX throws aDouble subscripterror. Remove the extra_from the label (in the lookup table or the JSON) and re-render. - A symbol shows up in red: that name has no label - it's missing from the
lookup table. This mainly happens with a hand-edited
model.json(CLI); add the missing entry and re-run.
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.tar.gz.
File metadata
- Download URL: gmpl_tex-0.1.1.tar.gz
- Upload date:
- Size: 1.1 MB
- 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 |
1eba91df30156145304533fbe82cf76224c795f05d7251eb0184ac1992c1ec25
|
|
| MD5 |
282e412f6ce64b3aaeb5ada1d1349056
|
|
| BLAKE2b-256 |
a0e64117800e3d1485b718538034047902f20edf8f3796a305b25b572b307dea
|
File details
Details for the file gmpl_tex-0.1.1-py3-none-any.whl.
File metadata
- Download URL: gmpl_tex-0.1.1-py3-none-any.whl
- Upload date:
- Size: 378.3 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 |
99766f89f2a1a7586292f66c1ae982c9346515223adceb1a9269f7151fb2f446
|
|
| MD5 |
4548638624c79c5bcd78fcd35dc2964a
|
|
| BLAKE2b-256 |
1faa7894d22ca9d72d7774f92c7d80b1c395b73fe2922a717c82464bc3cb56ae
|