# How can I color braces in showexpl?

I want to use showexpl and have the LaTeX code printed with colored braces. I can do this within a lstlisting environment by adding a literate option like in the example below, but not within a LTXexample environment (it produces an error). Is there a way to have the braces colored in the code block of a LTXexample environment?

\documentclass{article}
\usepackage{xcolor}
\usepackage{showexpl}
\lstset{language=[LaTeX]Tex,texcsstyle=*\color{red}}

\begin{document}
\begin{LTXexample}
\textit{Test}
\end{LTXexample}

\begin{lstlisting}[
literate=
*{\{}{{\textcolor{blue}{\{}}}{1}
{\}}{{\textcolor{blue}{\}}}}{1}
]
\textit{Test}
\end{lstlisting}
\end{document}


-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – Jubobs Sep 16 '14 at 18:21

Because showexpl is based on the listings package, most of the latter's features, including the literate key should, in theory, work out of the box. For some reason, though, defining the literal replacements globally, like so

\lstset
{
literate=
*{\{}{{\textcolor{blue}{\{}}}{1}
{\}}{{\textcolor{blue}{\}}}}{1},
}


seems to break showexpl, which complains about an Undefined control sequence \textitTest. I don't know the innards of showexpl well enough to have a good explanation for that error, but it seems that the braces get dropped when they shouldn't. It looks like a bug in showexpl to me, especially because the the inception of the literate key in listings (1999) predates the first release of showexpl (2004).

One workaround is to define those literate replacements, not globally, but within a custom style; you shouldn't get any error, then.

\documentclass{article}

\usepackage{xcolor}
\usepackage{showexpl}

%% returns an error!
%\lstset
%{
%  literate=
%    *{\{}{{\textcolor{blue}{\{}}}{1}
%     {\}}{{\textcolor{blue}{\}}}}{1},
%}

\lstdefinestyle{myLaTeX}
{
language=[LaTeX]Tex,
texcsstyle=*\color{red},
literate=
*{\{}{{\textcolor{blue}{\{}}}{1}
{\}}{{\textcolor{blue}{\}}}}{1},
}

\begin{document}

\begin{LTXexample}[style=myLaTeX]
\textit{Test}
\end{LTXexample}

\begin{lstlisting}[style=myLaTeX]
\textit{Test}
\end{lstlisting}

\end{document}

-