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

A full run, start to finish:

# 1. Generate the editable lookup table (writes model.json)
gmpl-tex model.mod --json

# 2. Open model.json and edit the label on the right-hand side of each entry,
#    e.g. "finishTime": "fTime"

# 3. Render LaTeX using your edited labels (writes model.tex)
gmpl-tex model.mod model.json --latex

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-1.0.1b1.tar.gz (16.6 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-1.0.1b1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file gmpl_tex-1.0.1b1.tar.gz.

File metadata

  • Download URL: gmpl_tex-1.0.1b1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.3"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.3","system":{"name":"Linux","release":"6.17.0-35-generic"}} HTTPX2/2.4.0

File hashes

Hashes for gmpl_tex-1.0.1b1.tar.gz
Algorithm Hash digest
SHA256 1bb6f23188ac1ecc77458f5148e0e2133025c54ce4441402165ac2bc0a22f470
MD5 827407f9f88352330a71eefeb94d75b1
BLAKE2b-256 e5019c9e811081c631d342138572505242b5fd0115011df7f02f1f0e02a03c8a

See more details on using hashes here.

File details

Details for the file gmpl_tex-1.0.1b1-py3-none-any.whl.

File metadata

  • Download URL: gmpl_tex-1.0.1b1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.3"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.3","system":{"name":"Linux","release":"6.17.0-35-generic"}} HTTPX2/2.4.0

File hashes

Hashes for gmpl_tex-1.0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 817ab739cc996a63e695f2676f010ab371c0f4cc6328f398d8c839a5c4fd1474
MD5 8640ccbf576b40a97b558f18aa1a8be5
BLAKE2b-256 f42543f00cfba55acf2fc8bd1fe846d804e286f2110b34a3a0c857873df36a38

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