I want to use the showexpl
, but define a new environment with predefined settings. But all I get is an emergency stop.
\documentclass{scrbook}
\RequirePackage{showexpl}
\lstdefinestyle{demoLatexStyle}{
basicstyle=\small\ttfamily, % Standardschrift
numbers=none, % Ort der Zeilennummern
frame=none,
}
\begin{document}
\newenvironment{showdemo}[1][]{\LTXexample[style=demoLatexStyle,#1]}{\endLTXexample}
\begin{LTXexample}[style=demoLatexStyle]
\LaTeX{} \LaTeX{}
\end{LTXexample}
\begin{showdemo}
\LaTeX{} \LaTeX{}
\end{showdemo}
\end{document}
\openout3 = `testdemo.tmp'. Package Listings Warning: Text dropped
after begin of listing on input line 24. ! Emergency stop. <>
testdemo.tex
** (job aborted, no legal \end found)
Any hint what I am doing wrong?
Best Answer
Section 4.16 of the
listings
package specifies that to define new environments you need to use the following with syntax similar to LaTeX's\newenvironment
.So, if you replace the
\newenvironment
with the following:you get the desired result:
Update
You could also use
LTXinputExample
and add the necessary code in separate files, or use thefilecontents
package. Since you asked for an environment below I have definedshowdemoEnv
, but I think the macro versionshowdemo
is probably better in this case:Note that the starred version
filecontents*
was used. This prevents the header comments thatfilecontents
would normally add to the file.