All my ideas on how to do clever things with code examples and listings results further or later in 'Emergency Stop' errors.
Let me briefly review what I am doing now and what I actually wanted to achieve:
I have provided for some years now a LaTeX template which includes a demo.tex which shows all the possibilities of the template. For me it is used mainly for testing purposes (and I found many bugs in packages using it). For the users it is a great 'howto manual' provided with their template.
Currently the users have to look into the code to see how the example worked. For the upcoming release I want to change that by providing the source in the pdf. Also it would have been great if it was possible to provide everything as a style file, and not just a .tex file. The idea was to provide \AddDemo and \PrintDemo, so that these could be defined wherever and printed on request. Especially this would allow not only me, but also package writers to provide their own example code. However from the answers of related questions posted here in the last few days I have given up on this idea.
Still there is the idea to show code and results side by side (or top/bottom). Here the showexpl package provides something useful.
BUT: it fails if placed in a command. This makes it unusable, since I must test if the example can be executed. The code below demonstrates this:
\documentclass{scrbook}
\usepackage{showexpl}
\usepackage{soul}
\providecommand{\IfDefined}[2]{%
\ifcsname #1\endcsname
#2 %
\else
% do nothing
\fi
}
\begin{document}
\IfDefined{so}{
\begin{LTXexample}
\so{letterspacing}, \ul{underlining}
\st{overstriking} and \hl{highlighting}.
\end{LTXexample}
}
\end{document}
Any other \ifdef command would probably result in the same error.
If there is no way to use verbatim material in any kind of command I will have to fall back to simple lstlisting environments and placing every code twice.
Any improvement for my code related to my idea of providing general example code is welcome.