Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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}
share|improve this answer
add comment

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}

enter image description here

share|improve this answer
    
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
1  
@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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.