Skip to main content

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:

  1. Lookup-table generation - parse model.mod into a JSON table listing every set, parameter, variable, constraint and objective name. Each name maps to a label you can edit.
  2. 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.
  • 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-tex if pip isn'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 --latex directly, a default table is created automatically (labels equal to the raw names) and used. If a model.json already 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 a Double subscript error 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.json lookup table.

License

MIT - see LICENSE.

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

gmpl_tex-0.1.0.dev1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

gmpl_tex-0.1.0.dev1-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file gmpl_tex-0.1.0.dev1.tar.gz.

File metadata

  • Download URL: gmpl_tex-0.1.0.dev1.tar.gz
  • Upload date:
  • Size: 16.7 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.4.0

File hashes

Hashes for gmpl_tex-0.1.0.dev1.tar.gz
Algorithm Hash digest
SHA256 56d90dce7e10580b5606b8ebc1a369a0153b718a82d181718f044a8d22da1893
MD5 c3e19ab88cf495001a9d346e7bff56af
BLAKE2b-256 26b4c266fb6920720240e45cdc6a2b8cf51499f4b9622e9b9c9515a4f0e88643

See more details on using hashes here.

File details

Details for the file gmpl_tex-0.1.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: gmpl_tex-0.1.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 19.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.4.0

File hashes

Hashes for gmpl_tex-0.1.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 13a3d0904e2ec82b5748c23ae71abcc5e9b987836cce935c08a246a5f000bb67
MD5 29fdacba7cb38ebd2626774aaca3b91f
BLAKE2b-256 085f0a970ea7e65c88586fba20e5e1bd07271277af7327fa9e4862a70e1a9bd1

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