Edson Valle recently wrote a style for the package listings from LaTeX. It allows you to format Gams code nicely in your LaTeX documents.
Here is a small example taken from his post to the Gams mailing list:
Scalar X /1/;
Scalar Y;
Y = 2*X;
Display “This is the famous Y”, Y;
In your LaTeX document this would look like:
The only thing you have to do is write a file gams.tex with the style and include this file in your LaTeX document before \begin{document}.
Information on the package Listings can be found here: listings
The gams.tex file should look like this:
\usepackage{listings}
%author Edson Cordeiro do Valle edsoncv at gmail dot com
\lstdefinelanguage{GAMS}{
morekeywords={
ABORT , ACRONYM , ACRONYMS , ALIAS , ALL , AND , ASSIGN , BINARY , CARD , DISPLAY , EPS , EQ , EQUATION , EQUATIONS , GE , GT , INF , INTEGER , LE , LOOP , LT , MAXIMIZING , MINIMIZING , MODEL , MODELS , NA , NE , NEGATIVE , NOT , OPTION , OPTIONS , OR , ORD , PARAMETER , PARAMETERS , POSITIVE , PROD , SCALAR , SCALARS , SET , SETS , SMAX , SMIN , SOS1 , SOS2 , SUM , SYSTEM , TABLE , USING , VARIABLE , VARIABLES , XOR , YES , REPEAT , UNTIL , WHILE , IF , THEN , ELSE , SEMICONT , SEMIINT , FILE , FILES , PUT , PUTPAGE , PUTTL , PUTCLOSE , FREE , NO , SOLVE , FOR , ELSEIF , ABS , ARCTAN , CEIL , COS , ERROR , EXP , FLOOR , LOG , LOG10 , MAP , MAPVAL , MAX , MIN , MOD , NORMAL , POWER , ROUND , SIGN , SIN , SQR , SQRT , TRUNC , UNIFORM , LO , UP , FX , SCALE , PRIOR , PC , PS , PW , TM , BM , CASE , DATE , IFILE , OFILE , PAGE , RDATE , RFILE , RTIME , SFILE , TIME , TITLE , TS , TL , TE , TF , LJ , NJ , SJ , TJ , LW , NW , SW , TW , ND , NR , NZ , CC , HDCC , TLCC , LL , HDLL , TLLL , LP , WS , /,PROD: },
sensitive = false,
morecomment=[f]*,%
morecomment=[s]{$ontext}{$offtext},
morecomment=[s][\color{green}]{/}{/},
morestring=[b]”,
morestring=[b]’
}
\lstset{
basicstyle=\fontfamily{pcr}\fontseries{m}\selectfont\footnotesize,
commentstyle=\color{gray}\itshape,
keywordstyle=\color{blue}\bfseries,
stringstyle=\color[rgb]{0.5,0,0.5}\itshape,
showstringspaces=false,
numbers=left,
numberstyle=\color[rgb]{0,0.5,0.5}\fontfamily{pcr}\fontseries{m}\selectfont\tiny,
numberblanklines=false,
showlines=false,
belowskip=\bigskipamount{},
breaklines=true,
%stepnumber=2,
tabsize=6,
%extendedchars=true,
%float=h,
frame=tb
}
I update the post, or just go to https://www.ctan.org/pkg/listings?lang=en
Cheers
Renger
Hi, thanks for sharing. I get similar errors as Juan above me – unfortunately the link ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf does not work… could you please share the contents? Thank you very much.
Anna
I don’t know, but perhaps the documentation to the package listings will give you the information.
This seems much more comfortable than converting the code to pdf from emacs (the way I insert gams code in latex currently). Since I prefer to use Lyx, I tried to define \input in the preamble, but texlive threw an error. Is it possible to use this method (comfortably) in Lyx instead of defining it in the .tex manually?
be sure to not include the listing package, because it is included in the gams.tex file.
gams.tex(1): Error: ! LaTeX Error: \usepackage before \documentclass.
gams.tex(4): Error: ! Undefined control sequence.
gams.tex(4): Error: ! LaTeX Error: Missing \begin{document}.
gams.tex(9): Error: ! Extra }, or forgotten $.
gams.tex(9): Error: ! Missing } inserted.
gams.tex(10): Error: ! Undefined control sequence.
gams.tex(14): Error: ! Undefined control sequence.
gams.tex(15): Error: ! Undefined control sequence.
gams.tex(16): Error: ! Undefined control sequence.
gams.tex(17): Error: ! Undefined control sequence.
gams.tex(18): Error: ! Undefined control sequence.
gams.tex(21): Error: ! Undefined control sequence.
gams.tex(21): Error: ! Undefined control sequence.
gams.tex(24): Error: ! Missing number, treated as zero.
gams.tex(24): Error: ! Illegal unit of measure (pt inserted).
gams.tex(2): Error: ! Undefined control sequence.
gams.tex(3): Error: ! LaTeX Error: The font size command \normalsize is not defined:
gams.tex(5): Error: ! LaTeX Error: The font size command \normalsize is not defined: