# How can I put a code listing in a tikzposter \block?

I'm trying to put a code listing in my poster, but I get the following error:

TeX capacity exceeded, sorry [input stack size=5000]

What am I doing wrong?

\documentclass[portrait, a0paper, 25pt]{tikzposter}
\title{title}
\author{}
\institute{}
\usepackage{color}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{redstrings}{rgb}{0.9,0,0}
\usepackage{listings}
\lstset{language=[Sharp]C,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
escapeinside={(*@}{@*)},
keywordstyle=\color{bluekeywords}\bfseries,
stringstyle=\color{redstrings},
basicstyle=\ttfamily
}
\begin{document}
\maketitle
\block{Block title}{
\begin{lstlisting}
%some code
\end{lstlisting}
}
\end{document}
\endinput

• The contents of the lstlisting environment is treated verbatim, which means you cannot have such an environment inside the argument of a command (\block, here). A common workaround is to use \lstinputlisting instead of lstlisting. – jub0bs Feb 17 '15 at 19:24

No... code format-... formatting... what..so...ever... I'm gonna... die...

More seriously, the problem is that the contents of the lstlisting environment is treated verbatim, which means you cannot have such an environment inside the argument of a command (\block, here).

A common workaround is to write the listing in an external file (with or without the filecontents package) and insert it with the \lstinputlisting command, instead of embedding the listing inside an lstlisting environment.

\documentclass[portrait, a0paper, 25pt]{tikzposter}

\title{title}
\author{}
\institute{}

\usepackage{color}
\definecolor{bluekeywords} {rgb}{0.13, 0.13, 1}
\definecolor{redstrings}   {rgb}{0.9 , 0,    0}

\usepackage{listings}
\lstset{
language          = [Sharp]C,
showspaces        = false,
showtabs          = false,
breaklines        = true,
showstringspaces  = false,
breakatwhitespace = true,
escapeinside      = {(*@}{@*)},
keywordstyle      = \color{bluekeywords}\bfseries,
stringstyle       = \color{redstrings},
basicstyle        = \ttfamily,
}

% -----
% the following writes to an external file called 'foo.hs'
\usepackage{filecontents}
\begin{filecontents*}{foo.hs}
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
\end{filecontents*}
% -----

\begin{document}
\maketitle
\block{Block title}{%
\lstinputlisting{foo.hs}
}
\end{document}