# What is explpreset actually for?

showexpl package is intended to show (La)TeX, TikZ, PSTricks codes and their coressponding rendered outputs at the same time (either horizontally or vertically).

Note that it cannot be used to show C# or C++ or Mathematica or others and their outputs because these language use different compilers or render engines.

showexpl is derived from listings package so options defined in listings can be used in showexpl either by using \lstset{...} or \lstset{explpreset={...}} as follows.

\lstset
{
backgroundcolor=\color{pink}
}


or

\lstset
{
explpreset=% I add the missing = here!
{
backgroundcolor=\color{pink}
}
}


I have read the showexpl package and the source code of its example document, but I am still confused what explpreset is actually for--because \lstset{} already exists and it can do what explpreset wants to do. The following is a short description of explpreset:

Do you have idea, what is explpreset is actually for?

-
Thanks for those who answered this question. All of them have been given a plus one for their good answers. However I have only one green check mark and it was given to Martin for the technical details. :-) –  xport Aug 7 '11 at 22:59

The explpreset key simply stores its value into the \SX@explpreset macro which is later used inside a local \lstset. This allows to define listings settings only for showexpl listings but not for other ones.

The exact usage is as follows:

showexpl.dtx, 2007/02/03 v0.3h, line 251:

\lst@Key{explpreset}\relax{\def\SX@explpreset{#1}}


by default it is empty: (line 285)

\newcommand*\SX@explpreset{}


It is then used by the LTXexample environment to set local \lstset settings: (starting from line 423)

\lstnewenvironment{LTXexample}[1][]
{%
\@temptokena{#1}%
\begingroup
%    \end{macrocode}
% For "codefile=..."/"graphic=..." if \cmd{\theltxexample} or
% \cmd{\thelstlisting} is part of the filename.
%    \begin{macrocode}
\expandafter\lstset\expandafter{\SX@explpreset,#1}%


This environment writes the code into an external file and calls the \SX@put@code@result macro afterwards to typeset it. This macro again uses the same settings: (line 457-)

\newcommand*\SX@put@code@result{%
\begingroup
\expandafter\lstset\expandafter{\SX@explpreset}%

-

Using the explpreset key inside lstset, you can customize only the attributes for the LTXexampe environments, and this gives you the possibility to define different attributes for the lstlisting environment. A simple example illustrating this:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{showexpl}

\lstset{
explpreset={backgroundcolor=\color{yellow!30}},
backgroundcolor=\color{lightgray}
}

\begin{document}

\begin{lstlisting}
\LaTeX
\end{lstlisting}

\begin{LTXexample}
\LaTeX
\end{LTXexample}

\end{document}


-