# Emphasizing a string in code example using showexpl

I am writing documentation for a package using the showexpl package which in turn uses the listings package. When using listing I can highlight a portion of the code like this:

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\lstset{
moredelim=[is][\color{red}]{<}{>}
}

\begin{document}

\begin{lstlisting}
This is an <emphasized string>.
\end{lstlisting}

\end{document}


But passing the moredelim option to a LTXexample environment does not have the desired effect, the code remains black.

\documentclass{article}

\usepackage{xcolor}
\usepackage{showexpl}

\lstset{
basicstyle=\ttfamily\small,
moredelim=[is][\color{red}]{<}{>}
}

\begin{document}

\begin{LTXexample}
This is an <emphasized string>.
\end{LTXexample}

\end{document}


Is there something I am missing about passing the moredelim option to the LTXexample environment correctly?

-

When you use moredelim the delimiter are stripped already from the code when showexpl writes the code to a temporary file. (Check the tmp-file). So when the listing is printed the delimiters are simply not there. You can avoid it by using explpreset (don't use both moredelim and explpreset this leads to confusion.)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{showexpl}
\lstset{
% moredelim=[is][\color{red}]{:}{.}
explpreset={moredelim={[is][\color{red}]{:}{.}}}
}

\begin{document}

\begin{lstlisting}
This is an :emphasized string.
\end{lstlisting}

\begin{LTXexample}
This is an :emphasized string.
\end{LTXexample}

\end{document}

-

you'll get problems with frames when using a different color:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{showexpl}
\lstset{
basicstyle=\ttfamily\small,
explpreset={moredelim=[is][\color{red}]{<}{>}}}

\begin{document}

\begingroup
\catcode\<=\active \def<{}
\catcode\>=\active \def>{}
\begin{LTXexample}
This is an <emphasized string>.
\end{LTXexample}
\endgroup
\end{document}


-
Is there a way to remove the brackets from the compiled example? –  Nickolay Kolev Jul 6 '11 at 8:51
no, showexpl shows the LaTeX output and not the one from listings –  Herbert Jul 6 '11 at 9:20
Are there any other options, save for having the code appear twice in the document (once in a listing and once typeset)? –  Nickolay Kolev Jul 6 '11 at 9:27
@Nickolay: To remove the brackets from the output you can make them active and define them to do nothing: \catcode\<=\active \def<{}`. Do it before the example and put a group around this definition and the example. –  Ulrike Fischer Jul 6 '11 at 9:42
@Ulrike: I added it to the example –  Herbert Jul 6 '11 at 10:35