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.1.dev1.tar.gz (367.5 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.1.dev1-py3-none-any.whl (377.5 kB view details)

Uploaded Python 3

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

Hashes for gmpl_tex-0.1.1.dev1.tar.gz
Algorithm Hash digest
SHA256 9dbfeca99e0fee3b0adbc44cdedbbd82b0a54f4dd9907b065003cd032056390a
MD5 c4d4bee29bdb086e60deeea1bdda6110
BLAKE2b-256 d2d91e54fd1eb3e112e065b8f43c8d88e1e385e0cca584bee18e89e89e5fb3df

See more details on using hashes here.

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

Hashes for gmpl_tex-0.1.1.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf6206b1de56036a59c4bc166a4249f140ee81c73206c8a17a720a19cf190af4
MD5 79458e778b897f7b43de369b1a155e09
BLAKE2b-256 cfdc7e24f40fd4c271a4d699de35b2914e7471664f06d6f0570fc86fd72b9067

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