summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/verbasef/verbasef.sty
blob: 9daf21e999a60bee5dc3a628448e61696d6370e9 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% verbasef.sty
%
% This stands for VERBatim Automatic Splitting of External Files.
%
% Copyright (c) 1994 by Paul A. Thompson, All Rights Reserved.
% Copy freely as per the GNU Copyleft.
%
% Requires:
%   The New Font Selection Scheme (NFSS) as implemented in LaTeX2e
%   VERBATIM.STY  :::  Rainer Schoepf
%   VRBEXIN.STY   :::  You 
%                      However, it is based on vrbinput.sty, a style by 
%                      Bernd Raichle which must be revised as discussed below
%                      in the section labeled IMPORTANT
%   HERE.STY      :::  David Carlisle
%
% verbasef allows you to input (subsections of a) file, print them in
% verbatim mode, while automatically breaking up the inputted lines into
% pieces of a given length, which are output as figures.  These figures are
% posted using the [H] specification, which forces LaTeX to place the figure
% at the spot of invocation, rather than floating the figures to the top of
% the next page.
% 
% Options for the verbasef specification include:
%  o numbering of input lines
%  o differential number of lines for the first page
%  o specification of the font for the verbatim output
%  o specification of the font for the optional line numbering
%  o specification of line numbers as labels 
%    To use the labelling feature, non-standard approaches must be used.
%    A line number will be inserted into the main .aux file with label foo,
%    if the specification 
%   
%    Vzzlabel|foo|
%
%    is inserted AFTER the line which is to be indicated.  Thus, if we have 
%    a file with the following
%    
%    a line
%    b line
%    Vzzlabel|fooa|
%    c line
%    Vzzlabel|foob|
%    d line
%    Vzzlabel|fooc|
%    e line
%    f line
%    Vzzlabel|food|
% 
%    these lines will be found in the .aux file.
%    \newlabel{fooa}{{2}{1}}
%    \newlabel{foob}{{3}{1}}
%    \newlabel{fooc}{{4}{1}}
%    \newlabel{food}{{6}{1}}
%
%    They can be used as any other label, for instance 
%
%    Using the labeling feature, pay attention to Line \ref{food} (found on
%    Page \pageref{food}) to understand this radically new method.
%
%    Any lines with the Vzzlabel specification will be ignored in the 
%    line counts.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% USING THE styLE 
%
% verbasef is an adaptation of VRBSUBFILE, from Norman Walsh.  
% I fully acknowledge Mr./Dr. Walsh as the imprimature of the code ensconced
% herein, but have included other features as indicated above.
%
% Comments and suggestions always welcome.
%   Paul A. Thompson
%   Department of Psychiatry, Data Analysis and Statistics Section
%   Case Western Reserve University
%   Cleveland, OH    44106
%
%   AudioNet: (216) 844-8946
%   InterNet: pat@po.cwru.edu
%
% User interface:
%   VautoSubF[#1]#2#3#4#5#6
%     Input lines #2 to #3 of file #4.  If present, #1 indicates which lines
%     should be numbered.  For example, if #1 is 5, lines 5, 10, 15, etc.
%     will be numbered.  By default, lines are not numbered at all.
%     #5 is figure caption, and #6 is figure label.
%
%   VautoSfFont[#1]#2
%     Use font #2 for verbatim input lines and, if present, use font #1 for
%     line numbers.  By default, #2 is \tt and #1 is \rm\tiny.
%   
%   VautoPl#1
%     Placement of the figure (either H or some other placement character)
%     By default, placement is H (immediate here, here.sty) 
%     (This currently does not function.  All placement is done using the 
%     H specification.)
%
%   VautoLines[#1]{#2}
%     #2 is number of lines per page.  If #1 is included, it is the number of
%     lines for the first page.  If not, #1=#2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In order to use the verbasef.sty file, VRBINPUT.STY must be MODIFIED
% and given a NEW NAME.  Here are instructions for modification:
%
% You must do EITHER 1-4 below OR 5 below to get verbasef to run properly.
%
% 1. Obtain vrbinput.sty from the standard distribution channels.  The file 
%    should have the following characteristics:
%
%    \fileversion{v1.0b}
%    \filedate{91/06/30}
%    \docdate{91/08/05}
%
% 2. Copy vrbinput.sty to a file vrbexin.sty.  THIS MUST BE DONE PRIOR TO
%    EDITING ANY FILE.
% 
% 3. Edit the file vrbexin.sty.  Please don't edit the file vrbinput.sty.
%    Change Line 90 from 
%    \verbatim@startline 
%    to 
%    \verbatim@start 
%    as shown in the fragment of code from Lines 89-92 below.
%
%  \def\verbatim@readfile#1{%
%     \verbatim@start
%     \openin\verbatim@in@stream #1\relax
%     \ifeof\verbatim@in@stream
%
%
% 4. VERY IMPORTANT.  CHANGE ALL OCCURRANCES of vrbinput, in titles, typeout
%    sections and credits to vrbexin.  Remove all references to the original
%    author, Bernd Raichle, as he is not the author of the style file vrbexin.
%    You may substitute my name for Mr. Raichle if you wish.
%
% 5. Obtain vrbexin.sty directly from the same subdirectory that verbasef was
%    found in.
%
% 6. Place this .sty file in a place searched by TeX, on the TEXINPUT path.
%
% After I can figure out the docstrip utility, I will do this stuff myself.
%
% Note: As is standard practice in the TeX community, any modifications in 
% .sty files must be given new names.  Thus, it is certainly vitally important
% that the modifications in vrbinput.sty be done in the file named
% vrbexin.sty, not in the original which I did not write.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
% IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT    IMPORTANT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}%                                        
\RequirePackage{vrbexin}%
\RequirePackage{verbatim}%
\RequirePackage{here}%
\def\fileversion{v1.1}%
\def\filedate{95/01/20}%
\typeout{Style-Option: `verbasef' \fileversion \space <\filedate>  (ndw)}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcounter{g@nu}
\newcommand{\incr@macv}[2]{
\setcounter{g@nu}{#1}\addtocounter{g@nu}{#2}%
\global\edef#1{\theg@nu}%
}
\gdef\Vauto@LinePage{0}%      % lines/page counter
\gdef\Vauto@NP{0}%            % Number of pages
\gdef\Vauto@Fignum{0}%        % Figure number - retain over figures
\gdef\Vauto@Pagea{0}%         % # lines page 1
\gdef\Vauto@LineNo{0}%        % current line number
\gdef\Vauto@LineMod{0}%       % modulo to print on
\gdef\Vauto@LineLoop{0}%      % loop count in line number (1..Mod)
\gdef\Vauto@LineStart{0}%     % first line to print
\gdef\Vauto@LineCount{0}%     % number of lines to print
\gdef\Vauto@NotLabel{0}%      % Printable - not a label
\gdef\Vauto@PFlag{0}%         % print this line?
%
%%%% Default table placement, and macros to change table placement
\def\Vauto@Plx{H}\def\Vauto@Pl#1{\def\Vauto@Plx{#1}}\def\VautoPl{\Vauto@Pl}%
%%%% Default verbatim font and verbatim line number font
\def\Vauto@sfFont{\tt}\def\Vauto@sfLNF{\rm\tiny}%
%
%%%% Macros to change fonts
\def\Vauto@sbf[#1]#2{\def\Vauto@sfFont{#2}\def\Vauto@sfLNF{#1}}%
\def\Vauto@svf#1{\def\Vauto@sfFont{#1}}%
\def\VautoSfFont{%
  \@ifnextchar[{\Vauto@sbf}{\Vauto@svf}%]    % This is for bracket match 
}%                                           % ] has no effect on code     
%%%% Macros to set number of lines per figure
\def\Vauto@LPP{46}\def\Vauto@LPPa{46}%
\def\Vauto@TwoLPP[#1]#2{\def\Vauto@LPP{#2}\def\Vauto@LPPa{#1}}%
\def\Vauto@OneLPP#1{\def\Vauto@LPP{#1}\def\Vauto@LPPa{#1}}%
\def\VautoLines{%
  \@ifnextchar[{\Vauto@TwoLPP}{\Vauto@OneLPP}%] % Bracket match
}%
\def\VautoSubFF{\@ifnextchar[{\Vauto@sbf}{\Vauto@svf}%]
}%
\def\xxparse Vzzlabel|#1|{%
\immediate\write\@mainaux{\string\newlabel{#1}{{\Vauto@LineNo}{\thepage}}}%
}%
\def\ifsubstr#1#2#3#4%% #1=string #2=substring, #3=yes, #4=no 
{%
  \def\tempa##1#2##2\over_##3\end{%
  \ifx##3%                                      % can't parse
  \gdef\Vauto@NotLabel{1}%
  \else% can parse
  \gdef\Vauto@NotLabel{0}%
  \xxparse #1%
  \fi%
}%
\tempa#1\over_\over#2\over___\end%
}%
%
%%Macro which sets beginfigure and endfigure constructions
%
\def\Vauto@etab#1#2#3{%  {caption}{label}{prtype}%
  \ifnum#3<3% 1 or 2 qualifies here
    \begingroup \normalsize\rm\selectfont%
      \ifnum\Vauto@NP=1 \caption{#1}\label{#2}%
        \global\edef\Vauto@Fignum{\thefigure}%
      \else \vspace{2em}%
          \centerline{Figure \Vauto@Fignum: #1 (cont.)}%
      \fi%
    \endgroup%
    \end{figure}% 
    \def\Vauto@PrCnt{\Vauto@LPP}%
    \ifnum#3=2 \setcounter{figure}{\Vauto@Fignum}\fi%
  \fi%
  \ifnum#3>1% 2 or 3 qualifies here
    \begin{figure}[H]%
%   \begin{figure}[\theVauto@Plx]%
    \incr@macv{\Vauto@NP}{1}%
    \gdef\Vauto@LinePage{0}%
    \gdef\Vauto@PFlag{1}%
  \fi%
  \catcode`\^^M9%
}%
%
%%%% Internal macro that does the work...
\def\Vauto@sf#1#2#3{\begingroup%
  \def\verbatim@start{\Vauto@etab{#2}{#3}{3}}%
  \def\verbatim@finish{\Vauto@etab{#2}{#3}{1}}%
  \def\verbatim@font{\Vauto@sfFont\selectfont}%
  \gdef\Vauto@LineNo{0}%
  \gdef\Vauto@LineLoop{0}%
  \parskip=0pt%
  \def\verbatim@processline{%
    \edef\subz{\noexpand\ifsubstr{\the\verbatim@line}{Vzzlabel}{1}{0}}\subz%
    \ifnum\Vauto@NotLabel=1%
      \incr@macv{\Vauto@LineNo}{1}%
      \incr@macv{\Vauto@LineLoop}{1}%
      \gdef\Vauto@PFlag{1}%
      \ifnum\Vauto@LineStart>0% we haven't reached the first line yet...
        \gdef\Vauto@PFlag{0}%
        \incr@macv{\Vauto@LineStart}{-1}%
      \else%
        \ifnum\Vauto@LineCount=0% we're out of the "printable" region
          \gdef\Vauto@PFlag{0}%
        \else%
          \incr@macv{\Vauto@LineCount}{-1}% decrease the line count
        \fi%
      \fi%
      % debugging...
      %\typeout{Start: \theVauto@LineStart, Count: \theVauto@LineCount,
      %  Print: \theVauto@PrintFlag, Loop: \theVauto@LineLoop,
      %  Mod: \theVauto@LineMod}%
      \ifnum\Vauto@PFlag=1%
        \leavevmode%
        \ifnum\Vauto@LineLoop=\Vauto@LineMod%
        \llap{{\Vauto@sfLNF\selectfont \Vauto@LineNo}%
            \ \hskip\@totalleftmargin}%
          \gdef\Vauto@LineLoop{0}%
          \else%
          \llap{\phantom{\Vauto@sfLNF\selectfont 0}\ %
                \hskip\@totalleftmargin}%
          \fi%
        \the\verbatim@line\par%
        \incr@macv{\Vauto@LinePage}{1}%
      \else%
        \ifnum\Vauto@LineLoop=\Vauto@LineMod%
          \gdef\Vauto@LineLoop{0}%
        \fi%
      \fi%
      \ifnum\Vauto@LinePage=\Vauto@PrCnt \Vauto@etab{#2}{#3}{2}\fi%
    \fi% End of the loop printing non-labels
  }%
  \verbatiminput{#1} \endgroup}%
%
\def\Vauto@sfP#1#2#3#4#5{%
\begingroup%
  \gdef\Vauto@PrCnt{\Vauto@LPPa}%
  \gdef\Vauto@NP{0}%    % Number of pages
  \gdef\Vauto@LineMod{-1}%
  \gdef\Vauto@LineStart{#1}%
  \gdef\Vauto@LineCount{#2}%
  \incr@macv{\Vauto@LineCount}{-\Vauto@LineStart}%
  \incr@macv{\Vauto@LineCount}{1}%
  \incr@macv{\Vauto@LineStart}{-1}%
  \Vauto@sf{#3}{#4}{#5}%
  \catcode`\^^M`\^^M%
\endgroup%
}%
\def\Vauto@sfN[#1]#2#3#4#5#6{%
\begingroup%
  \gdef\Vauto@PrCnt{\Vauto@LPPa}%
  \gdef\Vauto@NP{0}%    % Number of pages
  \gdef\Vauto@LineMod{#1}%
  \gdef\Vauto@LineStart{#2}%
  \gdef\Vauto@LineCount{#3}%
  \incr@macv{\Vauto@LineCount}{-\Vauto@LineStart}%
  \incr@macv{\Vauto@LineCount}{1}%
  \incr@macv{\Vauto@LineStart}{-1}%
  \Vauto@sf{#4}{#5}{#6}%
  \catcode`\^^M`\^^M%
\endgroup%
}%
\def\VautoSubF{%
  \@ifnextchar[{\Vauto@sfN}{\Vauto@sfP}%]
}%
\endinput%
%%%% EOF