4

I'm using SLaTeX to typeset some Racket source code. I would like to have line numbers along the left edge, so that I can refer to them in my document. However, I haven't yet discovered the option for turning line numbers on.

I suspect I should just switch over to the listings package and be done with it, but before I do, I wanted to check with the other LaTeX experts here.

2
  • 3
    You could try the lineno pacakge.But for typesetting source code the listings package is the one to use. Mar 3, 2012 at 5:19
  • 1
    Personally I use listings, but an alternative that seems to be gaining some popularity is minted, which uses pygments. That may be worth a look for you. I do recommend moving away from SLaTeX, whichever route you take.
    – qubyte
    Mar 3, 2012 at 10:15

1 Answer 1

5

From the listings documentation:

SLaTeX is a pretty-printing Scheme program (which invokes LaTeX automatically) especially designed for Scheme and other Lisp dialects. It supports stand alone files, text and display listings, and you can even nest the commands/environments if you use LATEX code in comments, for example. Keywords, constants, variables, and symbols are definable and use of different styles is possible. No line numbers.

Your best bet, is to use listings or pygments. Here is a MWE for listings to get you going.

\documentclass{article} 
\usepackage{xcolor,listings}
\begin{document} 
\lstloadlanguages{Lisp}
\newcommand\emphasis[2][red]{\lstset{emph={#2,},
   emphstyle={\ttfamily\textcolor{#1}}}}%
\emphasis{x,a}
\lstset{%
        language={[Auto]Lisp},  
        framesep=0pt,
        numbers=left,numberstyle=\normalsize,stepnumber=1,numbersep=5pt,
        breaklines=true,
    basicstyle=\normalsize\ttfamily,
    showstringspaces=false,
    keywordstyle=\ttfamily\color{blue},
    identifierstyle=\ttfamily,
    stringstyle=\color{maroon},
    commentstyle=\color{black},
    rulecolor=\color{gray!10},
    xleftmargin=5pt,
    xrightmargin=5pt,
    aboveskip=\bigskipamount,
    belowskip=\bigskipamount,
        backgroundcolor=\color{gray!5}
}
\begin{lstlisting} 
(define-syntax setq 
  (syntax-rules () 
    [(setq x a) 
     (begin (set! x a) 
            x)])) 
\end{lstlisting} 
\end{document}

enter image description here

What I particularly like about listings (especially if you writing tutorials), is that you can highlight specific key words (see the \emphasis macro in the code).

If you actually and absolutely insist that you use SLaTeX, yo can try the following code, which will number the full page.

\documentclass[10pt]{article}
\usepackage{fancyhdr,lipsum}
\makeatletter
 \newsavebox{\@linebox}
 \savebox{\@linebox}[3em][t]{\parbox[t]{3em}{%
   \@tempcnta\@ne\relax
   \loop{\underline{\scriptsize\the\@tempcnta}}\\
     \advance\@tempcnta by \@ne\ifnum\@tempcnta<48\repeat}}
 \pagestyle{fancy}
 \fancyhead{}
 \fancyfoot{}
 \fancyhead[CO]{\scriptsize How to Count Lines}
 \fancyhead[RO,LE]{\footnotesize\thepage}
%% insert this block within a conditional
 \fancyhead[LE]{\footnotesize\thepage\begin{picture}(0,0)%
      \put(-26,-25){\usebox{\@linebox}}%
      \end{picture}}
 \fancyhead[LO]{%
    \begin{picture}(0,0)%
      \put(-18,-25){\usebox{\@linebox}}%
     \end{picture}}
\fancyfoot[C]{\scriptsize Draft copy}
%% end conditional
\makeatother
\begin{document}
\section*{Lorem Ipsum}
\lipsum[1]
$$f_{nk}=\sum\,{\frac{n!}{
1!^{k_1}\,k_1!\,2!^{k_2}\,k_2!\,3!^{k_3}\,k_3!\,\ldots}}\; 
f_1^{k_1}f_2^{k_2}f_3^{k_3}\ldots\;,$$
summed over all $k_1,k_2,k_3,\ldots\geq 0$ 
\lipsum[3]
$$f_{nk}=\sum\,{\frac{n!}{
1!^{k_1}\,k_1!\,2!^{k_2}\,k_2!\,3!^{k_3}\,k_3!\,\ldots}}\; 
f_1^{k_1}f_2^{k_2}f_3^{k_3}\ldots\;,$$
summed over all $k_1,k_2,k_3,\ldots\geq 0$ 
\lipsum[5-7]
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .