Special thanks to Ingmar Schlecht for supporting us and sharing his gamsToLatex implementation.
MODEL2TEX is a tool to generate a documentation from GAMS source code in LaTeX format. This LaTeX output can then be further processed in order to generate pretty output files like PDF. The tool can be found in the root directory of GAMS. The tool allows to document one specific model symbol inside of a GAMS program. The resulting documentation contains two parts. The first part shows a list of symbols that are used by the model. The second part shows the actual algebra of the used equations and information about the types of used variables. An optional third part can contain additional notes.
MODEL2TEX is a command line tool. The general command line usage is as follows:
Since it operates on output files generated by GAMS, the first step is to generate the required files using the docfile option. In order to to that, execute the following command line:
The second step is to call
MODEL2TEX: On Windows the tool is shipped as an executable file. On Linux, the original Python source code is distributed. Therefore the usage differs and requires a Python 2 installation on Linux.
The output file
myModel.tex can be further processed for example by calling
pdflatex in order to generate a PDF file.
The following parameters can be used when calling
|Use this name for the generated TeX file instead of the base name.|
|Specify a different encoding. Default encoding is latin.|
MODEL2TEX automatically creates a JSON file that can be modified in order to customize the output. If you want to get the default settings back, just delete the generated JSON file and let
MODEL2TEX create it again. The following list shows the available options in the JSON file:
|11||The size of the used font|
|true||Horizontal rules are added between equations.|
|black||Specifies the used colors in equations for variables, parameters, and sets.|
|false||Allows to change the page format to landscape.|
|false||Beside a power operator, GAMS offers several power functions. Setting this option to true will replace all power functions with the power operator.|
|false||Try to resolve unbalanced fractions. This means that fractions with an unbalanced length of denominator and numerator will be changed in order to shrink the fraction.|
|5.0||This number has only effect when |
|false||Explanatory text for symbols is expected to be arbitrary text. In order to display the text correctly in LaTeX, some automatic adjustments are applied. If all explanatory text already contains valid LaTeX strings, this option can be enabled.|
|the original names||This map allows to specify alternative names for symbols.|
|empty list||On default, only the required symbols in a GAMS model symbol are contained in the generated LaTeX file. This list can be used in order to specify further symbols that should be included as well.|
|empty list||Allows to specify additional notes for the documentation. Each list element will result in a new line.|
This example creates a PDF file for the pump model from the GAMS Model Library.
- Retrieve model pump from GAMS Model Library gamslib pump
- Generate required doc files gams pump.gms docfile=pump
- Generate the LaTex files model2tex pump -m=pump
- Generate PDF documentation The following pictures show snippets from the resulting PDF file:pdflatex pump.tex
- Customizing the JSON style file In order to change the appearance of the PDF file, the generated JSON file
pump.jsoncan be modified. Changing the options in
pump.jsonaccording to the picture and executing the commands from step 3 and 4 again will result in a customized PDF output.