Tell me more ×
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 defines LTXexample environment which allows to define a latex code and shows its result side by side. The problem is that it uses the same documentclass where the latex code is defined and I would like to define which class to use for examples. Do you know if it's possible?

Here you have an examples. It's a beamer presentation with some LTXexamples.

\documentclass{beamer} 
\usepackage{showexpl} 
\lstloadlanguages{[LaTeX]Tex} 
\lstset{% 
    basicstyle=\ttfamily\small, 
    commentstyle=\itshape\ttfamily\small, 
    showspaces=false, 
    showstringspaces=false, 
    breaklines=true, 
    breakautoindent=true, 
    captionpos=t 
} 

\begin{document} 
\frame[containsverbatim]{ 
  \frametitle{First slide} 
  \begin{LTXexample} 
    \begin{itemize} 
       \item a 
       \item b 
       \item c 
    \end{itemize} 
  \end{LTXexample} 

  \begin{LTXexample} 
    \begin{equation} 
       a^2+b^2=\sqrt{\frac{c^2}{1}} 
    \end{equation} 
  \end{LTXexample} 
} 

\frame[containsverbatim]{ 
  \frametitle{Second slide} 
  \begin{LTXexample} 
     \documentclass{article} 
     \begin{document} 
     \section{Section 1} 
        Text for section 1 
     \end{document} 
  \end{LTXexample} 
} 
\end{document}

Second slide doesn't show 'section title' beacuse beamer has its own section behaviour, so it seems that \documentclass{article} inside the example doesn't have any effect. The resulting font is sansserif because beamer uses it.

I know I can use several external documents and insert code and results, but with LTXexample or a similar environment would be easier. Do you know a better solution?

share|improve this question
+1 for introducing me to showexpl, I spent hours this week more or less doing this by hand... Sigh. – Seamus Nov 26 '10 at 15:35

1 Answer

up vote 4 down vote accepted

The code must be compiled externally. Loading the code of article.cls and all sorts of packages in the beamer run would lead to chaos. But theoretically if --shell-escape is active it is possible to trigger this external run on-the-fly during the compilation of the beamer run and then to include the resulting pdf with the graphic-option of showexpl. The main problem I see is that you probably don't want to include a complete page but only a part of it (e.g. to show the section). I think it would be difficult to write a good and flexible interface to choose this part.

share|improve this answer
2  
The LaTeX team had to do something like this for The LaTeX Companion, as a lot of the example packages cannot be mixed. I believe the way it was done was using some special markers in the example .tex files ('start included preamble', 'start included body', etc.), plus a Makefile set up. There is some detail toward the end of the book. – Joseph Wright Nov 26 '10 at 22:27
@JosephWright I know this question is three years old, but could you elaborate on your comment, perhaps post your own answer, please? I find Ulrike's answer a bit too handwavy and I'm not sure what to do... – Jubobs May 29 at 13:28
1  
@Jubobs: You can find some information about the process mentioned by Joseph in CTAN. All LC2 examples and classes used to make them are there. – Ignasi May 29 at 17:08
@Ignasi Thanks. I will look into that. – Jubobs May 30 at 8:59

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.