latex插入lingo代码
时间: 2023-09-14 11:05:07 浏览: 251
你可以使用`listings`宏包来插入Lingo代码。首先需要在导言区添加以下代码:
```
\usepackage{listings}
\lstdefinelanguage{Lingo}
{morekeywords={Set, Minimize, Maximize, Subject to, By, S.t., Sum},
sensitive=false,
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
}
\lstset{
language=Lingo,
basicstyle=\small\ttfamily,
keywordstyle=\bfseries,
commentstyle=\itshape,
stringstyle=\ttfamily,
showstringspaces=false,
breaklines=true,
frame=tb
}
```
然后,在正文中插入代码的方法如下:
```
\begin{lstlisting}
Set I := 1..5;
Set J := 1..4;
Param c{i in I, j in J} := i*j;
Var x{i in I, j in J} >= 0;
Var y{j in J} binary;
Minimize cost: sum{i in I, j in J} c[i,j]*x[i,j];
Subject to capacity {i in I}:
sum{j in J} x[i,j] <= 1;
Subject to assignment {i in I, j in J}:
x[i,j] <= y[j];
By row {i in I}:
sum{j in J} x[i,j] = 1;
S.t. the {j in J}:
sum{i in I} y[j] = 1;
\end{lstlisting}
```
其中,`lstlisting`环境中的代码即为Lingo代码。你可以根据需要调整`\lstset`中的参数,比如`basicstyle`控制代码字体,`frame`控制代码框架等。
阅读全文