5

I was searching the web for a possible environment where I can put my GAP (Groups, Algorithms, Programming) codes. The most promising I saw was the "listings" package. But to my disappointment, this doesn't naturally recognize GAP codes.

Any other suggestions on this? Thanks!

P.S. This is my first time to write my codes in LaTeX.

10

Package listings provides an interface to add new languages. As starting point you can use the following example, that I constructed with a quick look at the reference manual of GAP. The GAP code example is taken from the shortened documentation example Fischer 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}  

Result

Update

The new maintainer Jobst Hoffmann has now added the language definition for GAL to listings 2013/08/05 v1.5a.

With

\usepackage{listings}[2013/08/05]

the language definition \lstdefinelanguage{GAP}{...}[...] is no longer necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.