GeneralHow to define a new environment encapsulating LTXexample?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
latexian
Posts: 19
Joined: Wed Aug 05, 2009 7:57 am

How to define a new environment encapsulating LTXexample?

Post by latexian »

Hi all,

My objective is to create a new environment that encapsulates LTXexample environment.

Here is my minimal code:

Code: Select all

\documentclass{article}
\usepackage{showexpl}
\usepackage{lipsum}

\lstset{%
captionpos=b,
explpreset={pos=b}}

\newenvironment{ExampleWithAboveCaption}[1]
{%
	\newcommand{\tempargs}{#1}%
	\newsavebox{\ewac}%
	\begin{lrbox}{\ewac}%
}%
{%
	\end{lrbox}%
	\begin{LTXexample}[aboveskip=3\fboxsep,caption={\tempargs}]%
		\usebox{\ewac}%
	\end{LTXexample}%	
}%


\begin{document}

\begin{ExampleWithAboveCaption}{This is an example.}
\lipsum[1]
\end{ExampleWithAboveCaption}

\end{document}

Unfortunately it cannot be compiled successfully.

Any suggestion is appreciated.

Thank you in advance.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ignasi
Posts: 20
Joined: Tue Jul 28, 2009 5:10 pm

How to define a new environment encapsulating LTXexample?

Post by ignasi »

In this thread you will find a partial solution

http://www.latex-community.org/forum/vi ... f=5&t=3900

There a 'example' environment id defined, you will have to add the caption.

Hope it helps.

Ignasi
Post Reply