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.

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
   {
     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:

enter image description here

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

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

2 Answers 2

up vote 6 down vote accepted

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}
    \advance\c@ltxexample\@ne \advance\c@lstlisting\@ne 
    \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}%
share|improve this answer
add comment

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}

enter image description here

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