Code: Select all
\begin{example}
LaTeX code
\end{example}
Thanks in advance,
-Calder Coalson
Code: Select all
\begin{example}
LaTeX code
\end{example}
NEW: TikZ book now 40% off at Amazon.com for a short time.
Code: Select all
\documentclass{article}
\usepackage{showexpl}
\usepackage{amsmath}
\usepackage{xcolor}
\lstset{%
basicstyle=\ttfamily\small,
commentstyle=\itshape\ttfamily\small,
showspaces=false,
showstringspaces=false,
breaklines=true,
backgroundcolor=\color{lightgray},
breakautoindent=true,
captionpos=t
}
\begin{document}
\begin{LTXexample}[wide,width=.75,preset=\footnotesize,rframe=single]
\documentclass[a4paper,twoside]{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}\label{eq:barwq}
\begin{split}
H_c&=\frac{1}{2n}\sum^n_{l=0}(1)^{l}(n{l})^{p2}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1}\binom{n_i}{l _i}\\ &\quad
\cdot[(nl)(n_il_i)]^{n_il_i}\cdot\Bigl[(nl)^2\sum^p_{j=1}(n_il_i)^2\Bigr].
\end{split}
\end{equation}
\end{document}
\end{LTXexample}
\end{document}
Code: Select all
\newcommand{example}[1]{
\begin{LTXexample}[bunch-o'-options]
#1
\end{LTXexample}
}
Code: Select all
\example{blablabla}
Code: Select all
\begin{LTXexample}[bunch-o'-options]
#1
\end{LTXexample}
Code: Select all
\newenvironment{example}{\LTXexample[options]}{\endLTXexample}
No. That will not work.phi wrote:...but it should be possible to use a custom environment:Code: Select all
\newenvironment{example}{\LTXexample[options]}{\endLTXexample}
Code: Select all
\makeatletter
\def\my@expl@ptions{wide,width=.75,preset=\footnotesize,rframe=single}
\lstnewenvironment{example}{%
\begingroup
\advance\c@ltxexample\@ne
\advance\c@lstlisting\@ne
\edef\x{%
\noexpand\lstset{\unexpanded\expandafter{\SX@explpreset},\unexpanded\expandafter{\my@expl@ptions}}%
\endgroup
\def\noexpand\SX@codefile{\SX@codefile}%
\def\noexpand\SX@graphicname{\SX@graphicname}%
\def\noexpand\SX@graphicparam{\SX@graphicparam}%
}%
\x
\xdef\SX@@explpreset{%
\unexpanded\expandafter{\my@expl@ptions},%
codefile=\SX@codefile,%
graphic={[\SX@graphicparam]{\SX@graphicname}}%
}%
\setbox\@tempboxa=\hbox\bgroup
\lst@BeginWriteFile{\SX@codefile}%
}{%
\lst@EndWriteFile\egroup
\SX@put@code@result
}
\makeatother
NEW: TikZ book now 40% off at Amazon.com for a short time.