Metadata-Version: 2.4
Name: gmpl-tex
Version: 0.1.1.dev1
Summary: Convert GMPL (GNU MathProg) models into LaTeX.
Author: Philipp Molnar
License: MIT License
        
        Copyright (c) 2026 philippmoln
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: lark>=1.1
Description-Content-Type: text/markdown

# 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](https://www.python.org/downloads/). On Windows,
    tick **"Add python.exe to PATH"** in the installer.
- [`lark`](https://github.com/lark-parser/lark) - installed automatically.

## Install

```bash
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
```text
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)

```bash
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:

```json
{
    "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

```json
//Example: "cost" to "c"
{
      ...
    "objectives":  { "cost": "c" }
}
```

### 3. Render LaTeX using your edited labels (generates model.tex)
```bash
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`](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](LICENSE).