GeneralCode Examples along with Results in Presentation

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ignasi
Posts: 20
Joined: Tue Jul 28, 2009 5:10 pm

Code Examples along with Results in Presentation

Post by ignasi »

Hi all,

I'm using beamer (CVS version) for slides and would like to use showexpl package to show LaTeX code examples and their results. The problem is that the LaTeX examples are processed like being into a presentation slide and not into an article or book. This means that some commands like \section (with special behaviour inside beamer) or \chapter cannot be used.

Let me show some examples:

Code: Select all

\RequirePackage{atbegshi} 
\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' because beamer has its own section behaviour, so it seems that \documentclass{article} inside the example doesn't have any effect. The resulting font is sans serif because beamer uses it.

A second example with article instead of beamer.

Code: Select all

\documentclass{article} 

\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} 

\begin{LTXexample} 
\section{Section 1} 
Text for section 1 
\end{LTXexample} 

\begin{LTXexample} 
\documentclass[12pt]{article} 
\begin{document} 
\section{Section 1} 
Text for section 1 
\end{document} 
\end{LTXexample} 

\end{document} 
Changing font size has no effect over result and first section on second example appears with number 2 because is the second section of the whole document.

Do you know if it's possible to fix a certain environment for the examples independent of the main document where they are declared? I could do it putting every example in its own file and including the result as a graphic file but it's no so comfortable like \LTXexample.

Do you know some other packages to show LaTeX code examples and results?


Thank you,
Ignasi

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply