I'm building beamer slides with code set using listings and I want to draw arrows to parts of the code. To achieve that I have a zero width command that defines a named PGF coordinate (given as the argument), here called libraryCommand.
Now the problem: I want to have a pretty syntax, so I use escapeinside, which should allow me to write QhereW to create a coordinate called here. Instead of writing the full command.
The argument that's passed to libraryCommand has to be wrapped between two commands, I use the environment for that. It works outside the lstlisting. But inside, I get Missing \endcsname inserted: \end{^lstlisting}.
\documentclass{scrartcl}
\usepackage{listings}
\lstset{
% escapeinside={Q}{W}, % uncommenting this fails.
escapebegin=\begin{wrapThat},
escapeend=\end{wrapThat}
}
\newcommand{\libraryCommand}[1]{((#1))}
\newenvironment{wrapThat}{\wrapToEnd}{}
\long\def\wrapToEnd#1\end{\libraryCommand{#1}\end}
\begin{document}
foo \begin{wrapThat}bar\end{wrapThat} baz
\begin{lstlisting}
foo QbarW baz
\end{lstlisting}
\end{document}
So, how could I get this to work? I can't see what special thing they do in the DTX...
wrapThatenvironment: Have a look at theenvironpackage which allows the definition of (pseudo-)environments which collect the body and provide it as\BODYin the end-code. Also using a plainTeX style envrionment like\wrap ... \endwrapwould be better. – Martin Scharrer♦ Jun 24 '11 at 17:56\NewEnviron{wrapThat}{\libraryCommand{\BODY}}it fails with\begin{wrapThat} ended by \end{lstlisting}.(but works outsidelstlisting) – pascal Jun 24 '11 at 18:05\def\wrapThat#1\endWrapThat{\libraryCommand{#1}}it fails withFile ended while scanning use of \wrapThat. – pascal Jun 24 '11 at 18:14listings. Rather theQandWare probably active and expand to theescapebeginandescapeendcodes. Therefore\wrapThatnever finds\endWrapThatbecauseWisn't expanded yet. With your initial code the\endit finds would be then the\end{lstlisting}! – Martin Scharrer♦ Jun 24 '11 at 19:37\begingroup\catcodeW=\active\gdef\wrapThat#1W{\libraryCommand{#1}}\endgroup`. Thenescapeendcan actually be empty. Or you simply addWafter\libraryCommand{#1}. – Martin Scharrer♦ Jun 24 '11 at 21:25