summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/7_1/fancyvrb.rc
blob: 2806e27628a0e8db2bbe05fe1fa5cf753f81818e (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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
\def\filedate{1996/11/24}
\def\filedate{1996/11/28 FMi}
\def\filedate{1996/12/03 FMi}
\def\filedate{1996/12/06 FMi}
\def\filedate{1996/12/07a FMi}
\def\filedate{1996/12/10 FMi}
\def\filedate{1996/12/15 FMi}
\def\filedate{1996/12/13 FMi}
\def\filedate{1996/12/26 FMi}
\def\filedate{1997/01/02 FMi}
\def\filedate{1997/01/07 FMi}
\def\filedate{1997/01/11 FMi}
\ProvidesFile{fancyvrb.rc}[\filedate\space fancyvrb customization
    by Sebastian Rahtz and Frank Mittelbach for LaTeX Graphics Companion]
% 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   - Rendered as PS, like original, side by side
%  Example*  - Rendered as PS, one above other
%  MPExample - Metapost example, side by side
%  MPExample* - Metapost example, one above another
%  MPEscape - Metapost exaple, just PS
%  InlineEscape - for use inline
%  Escape - Rendered as PS, with *no* verbatim text
% The example environments have the following step 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 \EX@dir directory
% (this needs a trailing / as part of the definition)
%

% bug fix for fancyvrb: missing percent sign results in issued \par!

\begingroup
\catcode`\^^M=\active
  \gdef\FV@BeginScanning#1^^M{%
    \def\@tempa{#1}\ifx\@tempa\@empty\else\FV@BadBeginError\fi%  <------
    \FV@GetLine}%
\endgroup



\RequirePackage{ifthen}
\RequirePackage{graphicx}
\RequirePackage{calc}
\newdimen\ExampleWidth
\newdimen\CodeWidth
\@ifundefined{fullwidth}{\let\fullwidth\textwidth}{}
\setlength\ExampleWidth{.5\fullwidth - 6pt}            % 12pt separation
% variable features
\def\EX@dir{}
\def\EX@prefix{}
\def\EX@class{article}
\def\PreambleCommands{}
\def\HiddenPreambleCommands{}
\def\EscapeParameters{}
\def\index@vals{}		% index entries etc passed on

%
\@ifundefined{thechapter}{\newcounter{chapter}}{}
%
\newcounter{EX@ct}[section]
\renewcommand\theEX@ct{%
 \arabic{chapter}-\arabic{section}-\arabic{EX@ct}}
\newcounter{side@count}

\newcommand\EPSinput[2][]{%
  \IfFileExists{\EX@dir\EX@prefix#2.eps}%
    {\ifx\\#1\\\else\typeout{Change EPS input to #1}\fi
     \includegraphics[#1,type=mps]{\EX@dir\EX@prefix#2.eps}}%
    {%
     \IfFileExists{\EX@dir\EX@prefix#2.eps.bb}%
       {\includegraphics[#1]{\EX@dir\EX@prefix#2}}%
       {\underline{\EX@dir\EX@prefix#2}}%
    }%
}

% added by Sean K. Harbour

\renewcommand\EPSinput[2][]{%
  \IfFileExists{\EX@dir\EX@prefix#2.eps}%
    {\ifx\\#1\\\else\typeout{Change EPS input to #1}\fi
     \includegraphics{\EX@dir\EX@prefix#2.eps}}%
    {%
     \IfFileExists{\EX@dir\EX@prefix#2.eps.bb}%
       {\includegraphics{\EX@dir\EX@prefix#2}}%
       {\underline{\EX@dir\EX@prefix#2}}%
    }%
}

\def\IdentifyOddExample#1{}
\def\IdentifyEvenExample#1{}
\def\IdentifyExample#1{}




\def\SideBySideEx#1#2{% final picture, verbatim code
\bgroup\def\baselinestretch{1}%
\trivlist\item[]%
 \leavevmode
  \global\advance\c@side@count\@ne
  \setlength\CodeWidth{\fullwidth -12pt -\ExampleWidth}%
  \label{\thechapter:\theside@count}%
  \index@vals
  \ifthenelse{\isodd{\pageref{\thechapter:\theside@count}}}{%
   \IdentifyOddExample{-6pt,0}%
%%D   \typeout{Odd Example <\theEX@ct, \theside@count>
%%D       <code: \the\CodeWidth>+<picture: 
%%D       \the\ExampleWidth>/\the\fullwidth}%
    \makebox[\textwidth][l]{\@@Display{#1}\hspace{12pt}%
                            \@@VDisplay{#2}}%
  }{%
%%D   \typeout{Even Example <\theEX@ct, \theside@count>
%%D       <code: \the\CodeWidth>+<picture: 
%%D       \the\ExampleWidth>/\the\fullwidth}%
    \makebox[\textwidth][r]{%
      \@@Display{#1}%
      \hspace{12pt}%
      \@@VDisplay{#2}}%
   \IdentifyEvenExample{6pt,0}%
  }%
  \endtrivlist
  \egroup
}
\def\EX@input#1{\input{#1}}
\newsavebox{\@display}

\def\@@Display#1{%
 \sbox\@display{%
  \begin{minipage}[b]{\ExampleWidth}\centering#1\end{minipage}%
 }\raisebox{\depth}{\usebox{\@display}}%
}

\def\@@VDisplay#1{%
 \sbox\@display{%
  \begin{minipage}[b]{\CodeWidth}%
     \BVerbatimInput[fontsize=\small]{#1}\end{minipage}}%
% \raisebox{\depth}{\usebox{\@display}}%
 \usebox{\@display}%
}

\def\@@WideDisplay#1{%
 \sbox\@display{#1}%
 \setlength\ExampleWidth\columnwidth
   \global\advance\c@side@count\@ne
   \label{\thechapter:\theside@count}\nobreak
   \ifthenelse{\isodd{\pageref{\thechapter:\theside@count}}}{%
    \IdentifyOddExample{-6pt,0}%
%%D    \typeout{Odd Wide Example <\theEX@ct, \theside@count>
%%D       <picture: \the\wd\@display>/\the\ExampleWidth}%
    \makebox[\textwidth][l]{\@@Display{#1}}%
  }{%
%%D   \typeout{Even Wide Example <\theEX@ct, \theside@count>
%%D       <picture: \the\wd\@display>/\the\ExampleWidth}%
    \makebox[\textwidth][r]{\@@Display{#1}}%
    \IdentifyEvenExample{6pt,0}%
  }%
}



\def\BeginExample{%
  \refstepcounter{EX@ct}%
  \nobreak
  \VerbatimEnvironment
  \catcode`\<=12
  \begin{VerbatimOut}{\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
}

\newcommand{\EndExample}{\end{VerbatimOut}%
% after parsing the verb code we have to change some
% start/stop strings for the secnd parsing phase:
      \init@post@extension@code\EX@suffix}



\def\FVE@VerbatimOut{%
   \Write@Postamble
   \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\Write@ExOne#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@Preamble
    \let\FV@FontScanPrep\relax
    \FV@Scan}


\def\Write@Preamble@LaTeX{%
    \Write@Ex{\string\documentclass{\EX@class}}%
    \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
%
% order is important Hidden ones first to allow setting things up for
% the other ones! FMi
%
 \ifx\HiddenPreambleCommands\@empty\else
    \Write@OneEx{\HiddenPreambleCommands}%
 \fi
    \Write@OneEx{\PreambleCommands}%
    \Write@Ex{\string\pagestyle{empty}}%
    \Write@Ex{\EX@width@spec}%
    \Write@Ex{\string\begin{document}}%
    \Write@Ex{\string\ResetPreambleCommands}%
    \Write@Ex{\string\ReadyForTheFray}%
    \Write@ExOne{\PreambleCommands}%
}
\def\Write@Preamble@MP{%
  \Write@OneEx{\PreambleCommands}%
  \Write@Ex{defaultfont:="ptmr8r";} % force Times for labels
  \Write@Ex{warningcheck:=0;}% this is to correct a known bug in MP
  \Write@Ex{beginfig(1)}%
}
%
% 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
}


% side by side LaTeX from external file
\newcommand{\Preexample}[1]{%
 \PrepareExampleWidth
 \SideBySideEx{\EX@input{\EX@dir#1}}{\EX@dir#1}%
}

% 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 specified.
\def\EX@width@spec{}
\def\PrepareExampleWidth{%
 \def\EX@width@spec{\string\setlength\string\textwidth{\the\ExampleWidth}}}

%%% don't think so FMi: \string\addtolength{\string\textwidth}{-6mm}}}


%
% 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,xleftmargin=\parindent]{#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=\small,xleftmargin=\parindent}
%
\DefineVerbatimEnvironment{ssverbatim}{Verbatim}{fontsize=\scriptsize}
\DefineVerbatimEnvironment{fverbatim}{Verbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{tverbatim}{Verbatim}{fontsize=\tiny}
\DefineVerbatimEnvironment{sverbatim}{Verbatim}
                          {fontsize=\small}
% numbered
\DefineVerbatimEnvironment{nverbatim}{Verbatim}
  {fontsize=\small,numbers=left,xleftmargin=\parindent}
\DefineVerbatimEnvironment{continueverbatim}{Verbatim}{fontsize=\small,%
  firstnumber=continue,numbers=left,xleftmargin=\parindent}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example type definitions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newcommand\ExampleType[5]{%
   \@namedef{#1@init}{%
     \def\EX@suffix{#1}%      
     \def\Write@Preamble{#2}%
     \def\Write@Postamble{#3}}%
   \@namedef{#1@init2}{%
     \edef\FancyVerbStartString{#4}%
     \edef\FancyVerbStopString{#5}%
   }}


\ExampleType{ltx}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\end{document}}


\ExampleType{pic}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\usebox\string\graph}%
   \Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\usebox\string\graph}



\ExampleType{m4}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\end{document}}



\ExampleType{abc}
  {\Write@Ex{X:1}%
   \Write@Ex{T:}}
  {}
  {T:}
  {}


%\ExampleType{mpp}  {} {} {} {}

\ExampleType{mpp}
  {\Write@Ex{\string\verb{\string\hsize=\the\ExampleWidth}}%
   \Write@Ex{\string\verb{}}} 
  {} {\string\verb{}} {}

\ExampleType{ptx}	% plain TeX source
  {} {} {} {}

\ExampleType{inl}            % inline
 {\Write@Preamble@LaTeX} {} {} {}

\ExampleType{mp}
  {\Write@Preamble@MP}
  {\Write@Ex{endfig;}%
   \Write@Ex{end;}%
  }
  {beginfig(1)}
  {endfig;}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\init@extension@code#1#2{%
    \def\index@vals{#2}%
    \sbox\@tempboxa{\index@vals}%
    \ifdim\wd\@tempboxa>0pt\relax\errmessage{index arg problem}\fi
    \expandafter\ifx\csname #1@init\endcsname\relax 
        \errmessage{Example Type #1 unknown}%
    \else
        \csname #1@init\endcsname
%%D        \typeout{Example Type \EX@suffix}%
    \fi
}

\def\init@post@extension@code#1{%
   \csname #1@init2\endcsname
   \ifx\FancyVerbStartString\@empty
       \let\FancyVerbStartString\relax \fi
   \ifx\FancyVerbStopString\@empty
       \let\FancyVerbStopString\relax  \fi
}

\newcommand\ExtendExampleWidth[1]{%
   \addtolength\ExampleWidth{24pt*#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% side by side generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment{GenExample}[2]
   {\init@extension@code{#1}{#2}%
    \PrepareExampleWidth
    \BeginExample}
 {\EndExample
  \SideBySideEx{\EPSinput{\theEX@ct}}%
               {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
 }


% side by side
\newenvironment{genexample}[2]
   {\init@extension@code{#1}{#2}%
%   \def\Write@OneEx##1{}%
    \def\Write@ExOne##1{}%
    \def\Write@Ex##1{}%
    \BeginExample}
   {\EndExample
    \let\FancyVerbStartString\relax 
    \let\FancyVerbStopString\relax
    \SideBySideEx{\EX@input{\EX@dir\theEX@ct.\EX@suffix}}%
                 {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}}





%%%%%%%%%%%%%%%%%%%%%%%%%%%
% on top of each other generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% first verbatimcode, then actual example
\newenvironment{GenExamplestar}[3][]
  {\init@extension@code{#2}{#3}%
   \def\verb@opts{#1}\BeginExample}
  {\EndExample
   \begin{center}
    \def\baselinestretch{1}%
    \index@vals
    \expandafter\VerbatimInput\expandafter[\verb@opts 
            gobble=0,fontsize=\small]%
      {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
    \EPSinput{\theEX@ct}%
   \end{center}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%
% inline on above the other generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% one above the other
\newenvironment{genexamplestar}[3][]
  {\def\Write@Ex##1{}\def\Write@ExOne##1{}%
   \init@extension@code{#2}{#3}\def\verb@opts{#1}\BeginExample}
  {\EndExample
   \let\FancyVerbStartString\relax 
   \let\FancyVerbStopString\relax
   \index@vals
   \expandafter\VerbatimInput\expandafter[\verb@opts 
                   gobble=0,fontsize=\small]%
      {\EX@dir\theEX@ct.\EX@suffix}%
   \begin{center}%
      \@@WideDisplay{\EX@input{\EX@dir\theEX@ct.\EX@suffix}}%
%
% the line above replaced the following:
%
%      \leavevmode\EX@input{\EX@dir\theEX@ct.\EX@suffix}\par
   \end{center}%
%   \IdentifyExample{-2,1}%
}




%%%%%%%%%%%%%%%%%%%%%%%%%%%
% only results generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% no verbatim text at all, just to run the thing separately

\newenvironment{GenEscape}[2]
  {\init@extension@code{#1}{#2}\BeginExample}
  {\EndExample
%
% that will probably *not* work, but the alternative isn't better either
%
   \IdentifyOddExample{-6pt,0}%
%
%  \par\noindent     % i fear that is necessary
%  \@@WideDisplay{%
   \index@vals
   \expandafter\EPSinput\expandafter
                [\EscapeParameters]{\theEX@ct}%
%    }%
  }

\newenvironment{InlineEscape}{\ERRORreplaceInlineEscape
  \GenEscape{ltx}{}}{\endGenEscape}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% special environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newenvironment{example}[1]   {\genexample{inl}{#1}} {\endgenexample}

\newenvironment{example*}[1] {\genexamplestar{inl}{#1}} {\endgenexamplestar}

\newenvironment{numexample*}[1]{%
    \genexamplestar[numbers=left,xleftmargin=18pt,]{inl}{#1}}
                            {\endgenexamplestar}

\newenvironment{Escape}[1]   {\GenEscape{ltx}{#1}}  {\endGenEscape}
\newenvironment{MPEscape}[1] {\GenEscape{mp}{#1}}   {\endGenEscape}

\newenvironment{Example}[1]  {\GenExample{ltx}{#1}} {\endGenExample}
\newenvironment{ABCExample}[1]{\GenExample{abc}{#1}} {\endGenExample}
\newenvironment{MPExample}[1]{\GenExample{mp}{#1}}  {\endGenExample}

\newenvironment{MPPExample}[1]{\GenExample{mpp}{#1}}  {\endGenExample}


\newenvironment{NExample}[1] {\GenExample%
                 [firstnumber=0,numbers=left,xleftmargin=18pt,]{ltx}{#1}} {\endGenExample}

\newenvironment{NExample*}[1] {\GenExamplestar%
                 [firstnumber=0,numbers=left,xleftmargin=18pt,]{ltx}{#1}} {\endGenExamplestar}

\newenvironment{Example*}[1]  {\GenExamplestar{ltx}{#1}}{\endGenExamplestar}
\newenvironment{MPExample*}[1]{\GenExamplestar{mp}{#1}} {\endGenExamplestar}
\newenvironment{MPExampleSmall*}[1]
         {\GenExamplestar[fontsize=scriptsize]{mp}{#1}} {\endGenExamplestar}

\newenvironment{MPPExample*}[1]{\setlength\ExampleWidth{\textwidth-2pt}%
               \GenExamplestar{mpp}{#1}}{\endGenExamplestar}


\endinput