Lstlisting stops file from compiling

listings

I'm writing a Latex file. But when I try to add the following code to the file, it just can't compile anymore:

\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}

I get these errors:

Illegal parameter number in definition of \lst@insertargs.

<to be read again> 
}
l.241 }
     
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
Illegal parameter number in definition of \lst@arg.

<to be read again> 
}
l.241 }
     
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
Runaway argument?

! Paragraph ended before \lst@next was complete.
<to be read again> 
\par 
l.241 }
     
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.

Here is the file:

\documentclass[ngerman, openany]{scrbook}
\usepackage[utf8]{inputenc}
\input{../shared/expl-cfg}
\input{expl/switch-cfg}
\begin{document}

\ifthenelse{\boolean{isPresentation}}{
    \chapter{Wirtschaft von Kryptowährungen}        
}{
\chapter{Analyse}\label{sec:analyse}

\section{Struktur des Lightning Network}
insert something here
\section{Funktionsweise des Lightning Networks}
insert something here
\section{Implementierung eines Lightning Networks in einem privaten Blockchain}
insert something here
\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}
}
\end{document}

here is the ../shared/expl-cfg:

\typeout{This is twp-cfg, the common configuration file (JHf)}
\makeatletter

\usepackage{ifthen}
\usepackage{iftex}
\usepackage{listings}                 

Edit: Here is the switch-cfg file.

\csname SwitchCfgLoaded\endcsname
\let\SwitchCfgLoaded\endinput

\newboolean{isBook}            
\newboolean{isPresentation}
\makeatletter                   
\@ifclassloaded{scrbook}{       
  \setboolean{isBook}{true}
}{                              
      \@ifclassloaded{beamer}{  
        \setboolean{isPresentation}{true}
      }{}                      
}

\ifthenelse{\boolean{isBook}}{
}{
  \let\frontmatter\relax
  \let\mainmatter\relax
  \let\backmatter\relax
  
    \let\chapter\section
    \let\section\subsection
    \let\subsection\subsubsection
      \ifthenelse{\boolean{isPresentation}}{
        \AtBeginSubsection[]{
          \begin{frame}<beamer|handout>%
              \begin{block}{}
                  \insertsubsectionhead
              \end{block}
          \end{frame}
        }{}
      }{}
}

How can I solve this issue? I get the same problem when using verbatim.
I am using Overleaf and LuaLaTeX as compiler.

Best Answer

I believe you are encountering an issue with the listings package described here and here. This is preventing you from using the listing inside the \ifthenelse construction.

It does work however, if you revert to the plain TeX style conditionals:

\ifisPresentation%
    \chapter{Wirtschaft von Kryptowährungen}        
\else%
\chapter{Analyse}\label{sec:analyse}

\section{Struktur des Lightning Network}
insert something here
\section{Funktionsweise des Lightning Networks}
insert something here
\section{Implementierung eines Lightning Networks in einem privaten Blockchain}
insert something here
\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}
\fi
\end{document}

Other things that also work include using \listinline instead:

\lstinline[language=bash,caption={bash version}]{btcd --txindex --simnet --rpcuser=kek --rpcpass=kek}

Or you could save the bash to a separate file (bashcmd.sh) and use:

\lstinputlisting[language=bash,caption={bash version}]{bashcmd.sh}

There may be other solutions in the answers to the questions at the links given above.

In the future, please don't break up your code into three separate files when there is no reason to do so in order to demonstrate your problem. All you did is make it harder for us to help you.

Related Question