我在网上搜索可以放置 GAP(组、算法、编程)代码的可能环境。我看到的最有希望的是“listings”包。但令我失望的是,它不能自然识别 GAP 代码。
还有其他建议吗?谢谢!
PS 这是我第一次用 LaTeX 编写代码。
答案1
包listings
提供了一个添加新语言的接口。作为起点,您可以使用以下示例,这是我快速浏览后构建的参考手册的差距。GAP 代码示例取自缩短的文档示例菲舍尔 23。
\documentclass{article}
\usepackage{listings}
% http://www.gap-system.org/Manuals/doc/ref/chap4.html
\lstdefinelanguage{GAP}{%
morekeywords={%
Assert,Info,IsBound,QUIT,%
TryNextMethod,Unbind,and,break,%
continue,do,elif,%
else,end,false,fi,for,%
function,if,in,local,%
mod,not,od,or,%
quit,rec,repeat,return,%
then,true,until,while%
},%
sensitive,%
morecomment=[l]\#,%
morestring=[b]",%
morestring=[b]',%
}[keywords,comments,strings]
\usepackage[T1]{fontenc}
\usepackage[variablett]{lmodern}
\usepackage{xcolor}
\lstset{
basicstyle=\ttfamily,
keywordstyle=\color{red},
stringstyle=\color{blue},
commentstyle=\color{green!70!black},
columns=fullflexible,
}
\begin{document}
\begin{lstlisting}[language=GAP]
# http://www.gap-system.org/Doc/Examples/fischer.in
LoadPackage( "ctbllib" );
ct := CharacterTable( "Fi23" );;
permchar := Sum( Irr( ct ){[1,2,6]} );;
permchar[1];
nccl := NrConjugacyClasses( ct );;
ord3 := Filtered( [ 1 .. nccl ],
i -> OrdersClassRepresentatives( ct )[i] = 3 );
permchar{ ord3 };
roots := [ 6 ];;
for i in [ 1 .. nccl ] do
if ForAny( Set( Factors( Size( ct ) ) ),
p -> PowerMap( ct, p )[i] in roots ) then
AddSet( roots, i );
fi;
od;
roots;
prop := Sum( roots, i -> 1 / SizesCentralizers( ct )[i] );
Int( 100 * prop );
LoadPackage( "atlasrep" );
gens := OneAtlasGeneratingSet( "Fi23", NrMovedPoints, 31671 );;
Fi23 := Group( gens.generators );;
SetSize( Fi23, Size( ct ) );
opdom := MovedPoints( Fi23 );;
found := false;;
repeat
g := Random( Fi23 );
ord := Order( g );
if ord mod 3 = 0 then
h := g^( ord / 3 );
if Number( opdom, i -> i^h = i ) = 324 then
found := true;
fi;
fi;
until found;
N := Normalizer( Fi23, SubgroupNC( Fi23, [ h ] ) );;
# [...]
sct := CharacterTable( A );;
# To complete the next command you need to start GAP
# with at least -o 400M option
# During the computation of Irr(sct) you will get two info
# messages about computing class matrix for class of size >10^6
Irr( sct );;
Maximum( List( Irr( sct ), i -> i[1] ) );
# [...]
PermCharInfo( ct, ind ).ATLAS;
quit;
\end{lstlisting}
\end{document}
更新
新的维护者 Jobst Hoffmann 现在已经将 GAL 的语言定义添加到listings
2013/08/05 v1.5a。
和
\usepackage{listings}[2013/08/05]
语言定义\lstdefinelanguage{GAP}{...}[...]
不再是必要的。