I have a library that contains code snippets formatted with the listings package. This library is used in two different documents, with slight variations depending on the document. I've been using conditionals to achieve these document-specific changes.
However, when I try to combine the listings-formatted snippets with a conditional, the LaTeX compiler (xelatex) outputs the following warning and the text is swallowed up:
"Package Listings Warning: Text dropped after begin of listing on input line XYZ."
Why am I getting this error/what do I need to do to be able to use listings inside a condition?
I've included an MWE below that shows what I'm trying to do (the filename is MWE.tex):
\documentclass[a4paper]{article}
\usepackage{listings}
\usepackage{xstring}
\lstset{basicstyle=\ttfamily,breaklines=true}
\begin{document}
Here is lstlisting without condition:
\begin{lstlisting}
This is sample code.
\end{lstlisting}
Here is lstlisting within a conditional:
\IfSubStr{\jobname}{\detokenize{MWE}}%
{\begin{lstlisting}
This is sample code.
\end{lstlisting}}%true
{FALSE}%false
\end{document}