6

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{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}
\usepackage{listings}
\lstset{language=[Sharp]C,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
escapeinside={(*@}{@*)},
commentstyle=\color{greencomments},
keywordstyle=\color{bluekeywords}\bfseries,
stringstyle=\color{redstrings},
basicstyle=\ttfamily
}
\begin{document}
\maketitle
\block{Block title}{
\begin{lstlisting}
%some code
\end{lstlisting}
}
\end{document}
\endinput
  • 1
    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
6

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.

enter image description here

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

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

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

\usepackage{listings}
\lstset{
  language          = [Sharp]C,
  showspaces        = false,
  showtabs          = false,
  breaklines        = true,
  showstringspaces  = false,
  breakatwhitespace = true,
  escapeinside      = {(*@}{@*)},
  commentstyle      = \color{greencomments},
  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}

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.