Print a model as math#
Turn a model file into the math a paper would print, from the file alone, and keep the document current as the file changes.
- Print Markdown first and read it. It is the quickest way to see that the YAML says what you meant:
- Give the symbols their conventional spelling with a symbol table beside
the model,
model.symbols.yaml. Without one,loadprints as \(\mathrm{load}_t\); with one it prints as whatever you write:
notation: latex
dimensions:
snapshot: { index: s, set: "\\mathcal{S}" }
generator: { index: g, set: "\\mathcal{G}" }
names:
cost: c
load: "\\ell"
capacity: "\\bar p"
A key naming nothing in the model is an error.
- Emit a document that compiles.
--standalonewraps the fragment in a preamble, so the output builds on its own:
python -m math_spec latex model.yaml --symbols model.symbols.yaml --standalone -o model.tex
python -m math_spec typst model.yaml --standalone -o model.typ
Then tectonic model.tex or typst compile model.typ. A symbol table is
written for one notation, so the Typst render takes a table with
notation: typst or none. Without --standalone the output is a fragment
to \input or #include into a paper.
- Print the rows a solver holds with
--expand, where the model states a curve or a set and the reader wants the formulation rather than the construct:
The same table serves both renders: a name the expansion emits, such as
cost_curve_lam, may be spelled in it.
- Keep it current with a rule in the paper's build:
model.tex: model.yaml model.symbols.yaml
python -m math_spec latex $< --symbols model.symbols.yaml --standalone -o $@
The options each renderer takes, what a symbol table may say, and how one declaration is printed on its own are under typeset the math.