summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/6_6/fancyvrb.rc
blob: 8fd06a54a808a2408714662a94f626d9ce01673a (plain)
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
\def\filedate{1996/09/23}
\ProvidesFile{fancyvrb.rc}[\filedate\space fancyvrb customization
by Sebastian Rahtz]
% Define verbatim and example environments:
%  Verbatim  - indented like quote environment, \small font.
%  nVerbatim - Like "Verbatim", but numbered.
%  example   - code and output, side by side
%  example*  - one above other
%  example** - one above other, with frames
%  Example   - Rendered as PS, like original, side by side
%  Example*  - Rendered as PS, one above other
%  Example** - Rendered as PS, one above other, with frames
%  Escape - Rendered as PS, with *no* verbatim text
%  PSTExample   - PSTricks picture, like original, side by side
%  GridPSTExample   - PSTricks (gridded) picture, like original, side by side
% The example environments have the following steps in common:
% 1. Save example verbatim to numbered example file
% 2. Input file verbatim  or EPS file
% 3. Input again 
% All of them save their text as files in the \EXdir directory
% (this needs a trailing / as part of the definition)
%
\RequirePackage{ifthen}
\RequirePackage{graphicx}
\RequirePackage{calc}
\def\ExampleFraction{.5}
\def\CodeFraction{.5}
% variable features
%
\def\EXdir{}
\def\EXprefix{}
\def\EXclass{article}
\def\PreambleCommands{}
\def\EscapeParameters{}
%
\@ifundefined{fullwidth}{\let\fullwidth\textwidth}{}
\@ifundefined{thechapter}{\newcounter{chapter}}{}
%
\newcounter{eps@counter}[section]
\renewcommand\theeps@counter{%
 \arabic{chapter}-\arabic{section}-\arabic{eps@counter}}
\newcounter{side@count}
%\newwrite\exepsfile
%\immediate\openout\exepsfile \EXdir\jobname.expslist\relax

\def\EPSinput{\@ifnextchar[{\@EPSinput}{\@EPSinput[]}}
\def\@EPSinput[#1]#2{%
\IfFileExists{\EXdir\EXprefix#2.eps}%
 {\ifx\\#1\\\else\typeout{Change EPS input to #1}\fi
   \includegraphics[#1]{\EXdir\EXprefix#2.eps}}
 {\underline{\EXdir\EXprefix#2}}%
}


\def\SideBySideEx#1{% 
\bgroup\def\baselinestretch{1}%
\trivlist\item[]%
  \leavevmode
   \global\advance\c@side@count by 1
   \label{\thechapter.\theside@count}%
   \IdentifyExample{-1,0}%
   \ifthenelse{\isodd{\pageref{\thechapter.\theside@count}}}{%
   \makebox[\fullwidth][l]{\@@Display{#1}\hspace{5mm}
    \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
      }{%
   \makebox[\fullwidth][r]{\@@Display{#1}\hspace{5mm}
     \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
    }%
  \endtrivlist
  \egroup
}
\newsavebox{\@display}
\def\@@Display#1{%
 \savebox{\@display}{%
\begin{minipage}[b]{\CodeFraction\fullwidth}#1\end{minipage}%
}
 \raisebox{\depth}{\usebox{\@display}}%
}

\newcommand{\BeginExample}{%
  \multiply\topsep by 2
  \global\advance\c@eps@counter\@ne
  \edef\@tempa{%
    \write\@auxout{\string
      \newlabel{ex-\theeps@counter}{{\theeps@counter}{\noexpand\the\c@page}}}}
  \@tempa
  \nobreak
  \VerbatimEnvironment
  \catcode`\<=12
  \begin{VerbatimOut}{\EXdir\EXprefix\theeps@counter.tex}%
}
\newcommand{\EndExample}{%
  \end{VerbatimOut}%
}

\def\IdentifyExample#1{%
  %\typeout{Here is example \theeps@counter}%
  \rput[b]{0}(#1){\psframebox[linecolor=gray]{{\small\theeps@counter}}}%
}
\def\EndRuleExample{\vskip 7pt \hrule height 1.5pt\relax}



\def\FVE@VerbatimOut{\Write@Ex{\string\end{document}}%
\immediate\closeout\FV@OutFile\endgroup\@esphack}

\def\Write@Ex#1{%
      \begingroup
       \let\protect\@unexpandable@protect
       \edef\reserved@a{\immediate\write\FV@OutFile{#1}}
       \reserved@a
      \endgroup
}

\def\Write@OneEx#1{%
    {\@temptokena\expandafter{#1}%
     \immediate\write\FV@OutFile{\the\@temptokena}%
    }%
}

\def\FVB@VerbatimOut#1{%
  \@bsphack
  \begingroup
    \FV@UseKeyValues
    \FV@DefineWhiteSpace
    \def\FV@Space{\space}%
    \FV@DefineTabOut
    \def\FV@ProcessLine{\immediate\write\FV@OutFile}%
    \immediate\openout\FV@OutFile #1\relax
    \Write@Ex{\string\documentclass{\EXclass}}%
    \Write@Ex{\string\nonstopmode}%
% notice that this different command to write the preamble
% commands means that all verbatim code gets the current
% preamble commands printed out
    \Write@OneEx{\PreambleCommands}%
    \Write@Ex{\string\pagestyle{empty}}%
    \Write@Ex{\EX@extra}%
    \Write@Ex{\string\begin{document}}%
    \let\FV@FontScanPrep\relax
    \FV@Scan}

%
% allows for numbered verbatim carrying on where the last
% ended
%
\define@key{FV}{firstnumber}[auto]{%
  \def\@tempa{#1}\def\@tempb{auto}%
  \ifx\@tempa\@tempb
    \def\FV@SetLineNo{%
      \c@FancyVerbLine\FV@CodeLineNo
      \advance\c@FancyVerbLine\m@ne}%
  \else
    \def\@tempb{continue}%
    \ifx\@tempa\@tempb
       \def\FV@SetLineNo{}%
    \else
     \def\@tempb{last}%
     \ifx\@tempa\@tempb
       \let\FV@SetLineNo\relax
     \else
       \def\FV@SetLineNo{\c@FancyVerbLine#1}%
     \fi
  \fi
\fi
}

\newif\ifgrid
\gridfalse
%--------------------------------------------------------
% here are the environment definitions
%--------------------------------------------------------
\def\PSTExample(#1,#2)(#3,#4){%
    \def\PictureSize{(#1,#2)(#3,#4)}%
    \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample
   }
\def\endPSTExample{%
  \EndExample
  \SideBySideEx{%
    %\ifgrid\vskip 8pt \else\relax\fi
    \expandafter\pspicture\PictureSize
    \ifgrid\usergrid\else\relax\fi
    \input{\EXdir\theeps@counter}%
    \endpspicture
    %\ifgrid\vskip 8pt \fi
 }%
}

\newenvironment{GridPSTExample}{\gridtrue\PSTExample}{\endPSTExample}

\def\PSTInlineExample(#1,#2){%
    \def\PictureSize{(-.2,-.5)(#1,#2)}%
    \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample
   }
\def\endPSTInlineExample{%
  \EndExample
  \expandafter\pspicture\PictureSize
  \usergrid
  \input{\EXdir\theeps@counter}%
  \endpspicture
 \hspace{16pt}%
 \BVerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
}
% side by side
\newenvironment{example}{%
  \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample}%
  {\EndExample\SideBySideEx{\input{\EXdir\theeps@counter}}}

% one above the other
\newenvironment{example*}%
  {\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
    \IdentifyExample{-1,0}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}
% one above the other, line numbered
\newenvironment{numexample*}%
  {\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,numbers=left,
        fontsize=\small]{\EXdir\theeps@counter}%
     \IdentifyExample{-1,0}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}

% with a frame, one above the other
\newenvironment{example**}%
{\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
{%
\EndExample
\VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\theeps@counter}%
    \IdentifyExample{-1,0}%
\begin{center}
\input{\EXdir\theeps@counter}
        \EndRuleExample
\end{center}
}

% now the ones which write stuff for an EPS file
% for side by side examples, the text width of the separate file
% needs to be half the normal width.
\def\EX@extra{}
\def\HalfWidth{%
 \def\EX@extra{%
 \string\makeatletter
 \string\@tempdima\string\textwidth
 \string\textwidth\ExampleFraction\string\@tempdima
 \string\addtolength{\string\textwidth}{-6mm}
 \string\makeatother}
}
\def\Setup@Escape{%
 \edef\FancyVerbStopString{\string\end{document}}%
 \edef\FancyVerbStartString{\string\begin{document}}%
}
% side by side
\newenvironment{Example}{%
 \HalfWidth
 \BeginExample} %
 {\EndExample
\Setup@Escape
\SideBySideEx{\EPSinput{\theeps@counter}}}

% first verbatimcode, then actual example
\newenvironment{Example*}{\BeginExample}%
  {\EndExample
  \Setup@Escape
    \IdentifyExample{-1,0}%
  \begin{center}\leavevmode\def\baselinestretch{1}%
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\EXprefix\theeps@counter}%
 \EPSinput{\theeps@counter}%
 \end{center}%
}

% one above the other, framed
\newenvironment{Example**}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
    \IdentifyExample{-1,0}%
    \VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\EXprefix\theeps@counter}%
\EPSinput{\theeps@counter}
\EndRuleExample
}

% no verbatim text at all, just to run the thing separately
\newenvironment{Escape}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
    \IdentifyExample{-1,0}%
\expandafter\EPSinput\expandafter
                [\EscapeParameters]{\theeps@counter}
}
%
% compatibility with Michel, with moreverb, and verbatim package
%
\def\SixPt{\fontsize{6}{7\p@}\selectfont}
%
% input files verbatim, numbered and unnumbered
%
\def\verbfile#1{\VerbatimInput[fontsize=\small]{#1}}
\let\verbatiminput\verbfile
\def\listinginput#1#2{\VerbatimInput[fontsize=\small,firstnumber=#1,numbers=left]{#2}}
%
% verbatim in various sizes; these are all Verbatim, ie flush left,
% not LVerbatim, which uses a list, and is indented
\DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\normalsize}
%
\DefineVerbatimEnvironment{sssverbatim}{Verbatim}{fontsize=\SixPt}
\DefineVerbatimEnvironment{ssverbatim}{Verbatim}{fontsize=\scriptsize}
\DefineVerbatimEnvironment{fverbatim}{Verbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{sverbatim}{Verbatim}{fontsize=\small}
\DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\normalsize}
% numbered
\DefineVerbatimEnvironment{nverbatim}{Verbatim}{fontsize=\small,numbers=left}
\DefineVerbatimEnvironment{continueverbatim}{Verbatim}{fontsize=\small,
  firstnumber=continue,numbers=left}
\endinput