1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
% Rolf Niepraschk, 2005-07-16, Rolf.Niepraschk@ptb.de
\listfiles\errorcontextlines=100
\documentclass[a4paper,draft,twoside]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[textwidth=12cm,marginparwidth=4cm]{geometry}
\usepackage[final]{showexpl}
\usepackage[T1]{fontenc}
\IfFileExists{luximono.sty}%
{%
\usepackage[scaled]{luximono}%
}
{%
\IfFileExists{beramono.sty}%
{%
\usepackage[scaled]{beramono}%
}{}
}
\lstset{%
basicstyle=\ttfamily\small,
commentstyle=\itshape\ttfamily\small,
showspaces=false,
showstringspaces=false,
breaklines=true,
backgroundcolor=\color{lightgray},
breakautoindent=true,
captionpos=t
}
\iftrue
\lstset{explpreset={numbers=left,numberstyle=\tiny,numbersep=.3em,
xleftmargin=1em,columns=flexible,language={}}}
\fi
\usepackage[font=small,labelfont=bf,justification=raggedright,%
singlelinecheck=false]{caption}
\usepackage{amsmath}
\AtBeginDocument{%
\renewcommand*\lstlistlistingname{Examples}
\renewcommand*\lstlistingname{Example}
}
\newcommand*{\MARKER}%
{\noindent\strut\vrule
\hrulefill~half text area~\hrulefill\vrule
\hrulefill~half text area~\hrulefill\vrule
\marginpar{\strut\vrule\hrulefill~margin area~\hrulefill\vrule}}
\begin{filecontents*}{ex1.tex}
Line 1 \par
Line 2 \par
Line 3 \par
Line 4 \par
Line 5 \par
Line 6 \par
Line 7 \par
Line 8 \par
Line 9 \par
Line 10 \par
Line 11 \par
Line 12 \par
Line 13
\end{filecontents*}
\begin{document}
\section*{The \LaTeX\ package \textsf{showexpl}}
\bigskip
\lstlistoflistings
\subsection*{The \textsf{listings} parameters still works}
\begin{LTXexample}[pos=t,numbers=none,
codefile=\jobname-\theltxexample.tex]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\subsection*{The \texttt{pos}, \texttt{overhang}, and
\texttt{caption} parameters}
\begin{LTXexample}[pos=b,overhang=.5\marginparwidth+.5\marginparsep,%
caption={The \texttt{overhang} parameter}]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=l,hsep=50pt,width=55mm]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\subsection*{The \texttt{wide} parameter with inner and outer position}
\begin{LTXexample}[pos=o,wide,caption={The \texttt{wide} parameter},%
label=ex:Gustav]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=i,wide]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
%--------------
\newpage
\subsection*{More examples on an even (left) page}
\begin{LTXexample}[pos=t]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=b,overhang=.5\marginparwidth+.5\marginparsep,%
captionpos=b,caption={The \texttt{overhang} parameter again},%
label=ex:Fridolin]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=l,hsep=50pt,width=55mm]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=o,wide,captionpos=b,%
caption={The \texttt{wide} parameter again}]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\MARKER
\begin{LTXexample}[pos=i,wide]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
%--------------
\newpage
\subsection*{Whole \LaTeX{} documents as example code and
the para\-meters \texttt{preset}, \texttt{rframe}, and \texttt{rangeaccept}}
\begin{LTXexample}[pos=r,wide,width=.65,preset=\LARGE,rframe={}]
\documentclass[a4paper,twoside]{article}
\begin{document}
\begin{equation}
\sigma(t)=\frac{1}{\sqrt{2\pi}}
\int^t_0 e^{-x^2/2} dx
\end{equation}
\end{document}
\end{LTXexample}
\MARKER
\begin{LTXexample}[wide,width=.75,preset=\footnotesize,rframe=single,%
codefile=\jobname-\theltxexample.tex]
\documentclass[a4paper,twoside]{article}
\usepackage{amsmath}
% enhancements for mathematical formulas
\begin{document}
\begin{equation}\label{eq:barwq}
\begin{split}
H_c&=\frac{1}{2n}
\sum^n_{l=0}(-1)^{l}(n-{l})^{p-2}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1}
\binom{n_i}{l _i}\\
&\quad\cdot[(n-l )-(n_i-l _i)]^{n_i-l _i}\cdot
\Bigl[(n-l )^2-\sum^p_{j=1}(n_i-l _i)^2\Bigr].
\end{split}
\end{equation}
\end{document}
\end{LTXexample}
\LTXinputExample[%
pos=r,backgroundcolor=\color{Goldenrod!50},%
%firstline=3,lastline=6,%
linerange={3-6,8-10},%
float=tb,rangeaccept=true,%
caption={[Floating Example]%
This is a floating Example (parameter \texttt{rangeaccept=true})}]{ex1}
\newpage
\MARKER
\subsection*{Using a graphic as the result}
\begin{LTXexample}[pos=i,wide]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\begin{LTXexample}[pos=i,wide,rframe={},%
graphic=result-picture]% graphic=\jobname-\theltxexample
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\begin{LTXexample}[caption={The \texttt{graphic} parameter},captionpos=b,%
pos=i,wide,graphic={[width=.5\linewidth]result-picture}]
\Large\LaTeX{} \LaTeX{}
\LaTeX{} \LaTeX{}
\end{LTXexample}
\newpage
\subsection*{The parameter \texttt{varwidth}}
\bigskip
\MARKER
\begin{LTXexample}[caption={Fix width of the result
(side-by-side default: \texttt{0.5\textbackslash linewidth})},%
captionpos=b]
\setlength{\unitlength}{1cm}
\begin{picture}(2,2) \thicklines
\thicklines
\put(0,0){\line(1,1){2}}
\put(0,2){\line(1,-1){2}}
\end{picture}
\end{LTXexample}
\medskip
\begin{LTXexample}[caption={[The \texttt{varwidth} parameter]%
Width of the result reduced to the ``natural''
width (\texttt{varwidth=true})},varwidth,captionpos=b]
\setlength{\unitlength}{1cm}
\begin{picture}(2,2) \thicklines
\put(0,0){\line(1,1){2}}
\put(0,2){\line(1,-1){2}}
\end{picture}
\end{LTXexample}
\medskip
\begin{LTXexample}[caption={Fix width of the result
(default: \texttt{\textbackslash linewidth})},%
pos=t,captionpos=b]
\setlength{\unitlength}{1cm}
\begin{picture}(2,2) \thicklines
\put(0,0){\line(1,1){2}}
\put(0,2){\line(1,-1){2}}
\end{picture}
\end{LTXexample}
\medskip
\begin{LTXexample}[caption={[The \texttt{justification} parameter]%
Result is centered (\texttt{varwidth=true})},%
varwidth,captionpos=b,pos=t,justification=\centering]
\setlength{\unitlength}{1cm}
\begin{picture}(2,2)
\thicklines
\put(0,0){\line(1,1){2}}
\put(0,2){\line(1,-1){2}}
\end{picture}
\end{LTXexample}
\end{document}
|