# whitespaces in alltt environment get merged

\begin{frame}{Beispiel Mergesort}
\begin{alltt}
mergesort :: (Ord a, Trans a) => [a] -> [a]

mergesort []   =  []

mergesort [x]  =  [x]

mergesort xs   =  sortmerge (process mergesort \# xs1)

(process mergesort \# xs2)

where (xs1,xs2) = unshuffle xs
\end{alltt}
\end{frame}


I'm doing a beamer presentation and try to display some source code, but I'm loosing all intendation, all whitespaces get merged into a single space. (not only at the beginning of the lines, but also around the '=' characters)

I don't know what I'm doing wrong.

Can someone help?

Cheers,

Lukas

-
Welcome to TeX.SX! I guess you want \begin{frame}[fragile]\frametitle{Beispiel Mergesort} –  egreg Jul 13 at 14:54
you, sir, are brilliant! thanks! –  Whadupapp Jul 13 at 14:59

Frames containing verbatim material should be declared fragile; also you don't really want that dramatic indentation, which will be kept in the listing.

\documentclass{beamer}
\usepackage{alltt}
\begin{document}
\begin{frame}[fragile]
\frametitle{Beispiel Mergesort}
\begin{alltt}
mergesort :: (Ord a, Trans a) => [a] -> [a]

mergesort []   =  []

mergesort [x]  =  [x]

mergesort xs   =  sortmerge (process mergesort \# xs1)

(process mergesort \# xs2)

where (xs1,xs2) = unshuffle xs
\end{alltt}
\end{frame}

\end{document}


I think it is better to use the \frametitle command rather than an additional argument to \begin{frame}.

Instead of alltt you can use the semiverbatim environment, which doesn't require an additional package, but still requires [fragile].

-
thanks! Actually the tabs in front of the line don't seem to matter, those get killed by tex, just the intendation using spaces is kept. So I keep my tabs and get a nice looking tex code ;-) Thank you =) –  Whadupapp Jul 13 at 15:01
@Whadupapp In order my files don't have any TAB character, my editor does exactly nothing when the TAB key is hit. –  egreg Jul 13 at 15:03