Debian Codegraph @

texmf-dist/doc/latex/footnpag/footnpag.doc

raw
1 % $StyleId: footnpag.doc,v 2.6 1995/11/10 18:21:26 schrod Exp $
2 %----------------------------------------------------------------------
3 % Written by Joachim Schrod <[email protected]>.
4 % Copyright conditions see below.
5
6 %
7 % LaTeX package footnpag
8 % numbers footnotes subsequently per page
9 %
10 % [LaTeX in MAKEPROG]
11 % (history at end)
12
13 % If you have received this style file without the user manual (in the
14 % file footnpag-user.tex or the respective DVI file), it's incomplete and
15 % near to useless. If it was given to you as something that you shall
16 % use as an author -- complain bitterly to your provider. You need the
17 % documentation and you have a right on it! (Below you can find info
18 % where to get the reference version.)
19
20
21
22
23 \documentclass{progltx}
24
25 \usepackage{footnpag-doc} % document-specific markup
26 \usepackage{fullpage}
27
28
29 \nofiles % no cross references
30
31
32 \RCS $StyleDate: 1995/11/10 18:21:26 $
33
34
35 \begin{document}
36
37
38 \title{The \texttt{footnpag} Package\\
39 {\large (Implementation)}%
40 }
41 \author{% % LaTeX does not discard unnecessary glue...
42 Joachim Schrod%
43 \thanks{%
44 \protect\raggedright
45 TU~Darmstadt, Computer Science Department, WG Systems Programming,
46 Alexanderstr.~10, D-64283~Darmstadt, Germany.
47 Email: \texttt{[email protected]}.%
48 }%
49 }
50 \date{%
51 Revision \RCSStyleRevision\\
52 (as of \RCSStyleDate)%
53 }
54
55 \maketitle
56
57
58 % doesn't work with progltx yet
59 %\tableofcontents
60
61
62
63 % ------------------------------------------------------------
64 %
65 % subdocument: The user interface of footnpag.sty
66 %
67
68 \input{footnpag-user}
69
70 %
71 % ------------------------------------------------------------
72 %
73 % subdocument: The internal interface
74 %
75
76 %\input{footnpag-conf}
77
78 %
79 % ------------------------------------------------------------
80
81
82
83 \chap Implementation.
84
85 Please note, that this package was originally written for plain
86 \TeX{}. The original version is still available. This version will
87 evolve, and will finally be full \LaTeX{} code.
88
89 This module reserves the namespace |fnpp|. Due to the age of the code
90 it does not obey the namespace throughout, this has to be changed in a
91 future revision.
92
93 \beginprog
94 \ifx \fnpp@loaded\undefined
95 \def\fnpp@loaded{$StyleRevision: 2.6 $}
96 \else
97 \PackageWarningNoLine{footnpag}%
98 {Some other package already uses namespace `fnpp'}
99 \fi
100 \endprog
101
102
103 \sect Let's identify this package.
104
105 The code below is explained in the implementation documentation of the
106 |rcs| package.
107
108 \beginprog
109 \begingroup
110 \def\RCSPackage#1#2 $#3: #4 #5\endRCS $#6: #7 #8\endRCS{%
111 \def\date{#4}\def\id{v#7}%
112 \ProvidesPackage{#1}[\date\space\id\space #2]%
113 }
114
115 \RCSPackage{footnpag}{numbering footnotes per page}
116 $StyleDate: 1995/11/10 18:21:26 $: 9999/00/00 \endRCS
117 $StyleRevision: 2.6 $: 0.0 \endRCS
118 \endgroup
119 \endprog
120
121
122 \sect This module is supported. Send bug reports, comments and
123 repairs.
124
125 The reference version may be retrieved via anonymous ftp from
126 |ftp.th-darmstadt.de| [130.83.47.112], directory |pub/tex/latex|. It's
127 placed there as a gzipped tar file. (The information on the IP~number
128 is dated August~3,~1995.
129 It might have changed, although this is very unlikely. Use your
130 friendly nameserver.)
131
132
133 \sect This is freely distributable software; you can redistribute it
134 and/or modify it under the terms of the GNU General Public License as
135 published by the Free Software Foundation; either version~2 of the
136 License, or (at your option) any later version.
137
138 This software is distributed in the hope that it will be useful, but
139 \textbf{without any warranty}; without even the implied warranty of
140 \textbf{merchantability} or \textbf{fitness for a particular purpose}.
141 See the GNU General Public License for more details.
142
143 You should have received a copy of the GNU General Public License in
144 the file |License| along with this package; if not, write to the Free
145 Software Foundation, Inc., 675~Mass Ave, Cambridge, MA~02139,~USA.
146
147
148 \sect Before we start we declare some shorthands for category codes.
149 By declaring the underscore~`(|_|)' as letter we can use it in our
150 macros. (I agree with \textsc{D.~Knuth} that
151 |\identifier_several_words_long| is more readable than
152 |\IdentifierSeveralWordsLong| and in every case better than |\p@@@s|.)
153
154 As this is a \LaTeX{} module the at sign is a letter anyhow; so
155 we can use the ``private'' \LaTeX{} macros; and with the underscore we
156 can make our own macros more readable. But as we have to restore this
157 category code at the end of this macro file we store its former value
158 in the control sequence |\CatUsCode|. This method is better than to
159 use a group because not all macros have to be defined global this way.
160
161 Since somebody might use more modules from me, this cseqs might be
162 defined already.
163
164 \beginprog
165 \ifx \CatEscape\undefined
166 \chardef\CatEscape=0
167 \chardef\CatOpen=1
168 \chardef\CatClose=2
169 \chardef\CatIgnore=9
170 \chardef\CatLetter=11
171 \chardef\CatOther=12
172 \chardef\CatActive=13 % is defined in Plain already
173
174 \chardef\CatUsCode=\catcode`\_
175 \fi
176
177 \catcode`\_=\CatLetter % top level macro file
178 \endprog
179
180
181 \sect Let's regard the implementation strategy. Because
182 the contents of one page is determined at (nearly) random places
183 with an asynchronous invogation of the output routine, we can not
184 give numbers to every footnote subsequently between output and
185 output: a footnote at the top of a page will perhaps get a number
186 before the output is triggered and there is no way to change this
187 number. The problem is like forward references to text places and it
188 is solved in a similar fashion. We need two \TeX{} runs to get the
189 numbering right but this is acceptable (who's got a finished text
190 after one run?!). In the first run we gather up in a file the
191 information where the footnotes are standing and in the second run
192 we use this information.
193
194 We must identify all footnotes if we write their numbers to the
195 footnote file, so each footnote gets an unary name built with the
196 counter |\foot_name_no|. The name is `|f@|\<nameno>', where \<nameno>
197 is the footnote name number. This name building scheme has several
198 disadvantages, e.g.\ the insertion of a new footnote destroys the
199 knowledge of the former run about the following footnotes. If we would
200 have some knowledge about the document type we are using and the macro
201 set which is in effect we could insert other counters (e.g.\ the
202 chapter numbers) as well.
203
204
205
206 \chap Determing the footnote numbers.
207
208 Let's start with the initialization of the macro
209 set. We need a file descriptor, |\foot_file|, which we use for the
210 file interaction. The name of the file is built from the job name and
211 the suffix `|.fot|' (I hope that no macro package uses this suffix).
212 The |\init_footnote| macro reads the contents
213 of the footnote file if it exists (|\ifeof| returns true if the file
214 doesn't exist). The description of the reading of this file
215 (|\read_foot_file|) is deferred until we know the structure of the
216 contents. After reading, the file is closed and we can open it for
217 writing. For security, i.e.\ to have a defined minimal contents, we
218 immediately write |\relax| to the file. In the end the macro defines
219 itself to |\relax| to allow calling it again.
220
221 \beginprog
222 \newread\old_foot_file
223 \newwrite\foot_file
224 \def\foot_file_name{\jobname.fot\relax}
225 \def\init_footnote{%
226 \openin\old_foot_file\foot_file_name
227 \ifeof\old_foot_file \closein\old_foot_file
228 \else \closein\old_foot_file
229 \read_foot_file
230 \fi
231 \immediate\openout\foot_file\foot_file_name
232 \immediate\write\foot_file{\relax}%
233 \global\let\init_footnote\relax
234 }
235 \endprog
236
237
238 \sect Remember, that we use |\foot_name_no| for the generation of a
239 name for each footnote. The actual number of the footnote mark is
240 stored in |\c@footnote|, the \LaTeX{} footnote counter.
241
242 In the beginning of every footnote |\init_footnote| is called to
243 guarantee that the handling is initialized (this especially means
244 that the footnote numbers are read in by the first footnote).
245
246 \beginprog
247 \newcount\foot_name_no % for generating footnote mark names
248 \endprog
249
250
251 \sect It remains an open problem how to get the numbers there. The
252 footnote numbering must be initialized to zero in the output routine
253 and every footnote must increment this footnote number. The only
254 thing that is expanded during the output process is the output
255 routine itself and the |\write|'s, but the expanded tokens of
256 |\write| are written out, not interpreted. Well, the idea is simple:
257 We defer the counting to the second run and write the instructions
258 that do this to the file. The counting is then done while reading
259 the footnote file.
260
261 \noindent That means that the output routine adds entries like
262 %
263 \begin{quote}
264 |\c@footnote = 0|
265 \end{quote}
266 %
267 and every footnote adds an entry that looks like
268 %
269 \begin{quote}
270 |\advance\c@footnote by 1|\\
271 |\xdef\csname f@|\<nameno> |\endcsname{\number\c@footnote}|
272 \end{quote}
273 %
274 where \<nameno> is replaced by the current footnote name number.
275
276
277 \sect The macro |\fnpp_next_footnote| determines the next footnote
278 number and stores it in |\c@footnote|, the official \LaTeX{} footnote
279 counter. This counter is used since |\footnotetext| constructs the
280 mark in the footnote text from it. One can say that
281 |\fnpp_next_footnote| is a non-typical way to step this counter, it's
282 a series iterator instead of an incrementer like |\stepcounter|.
283
284 The expansion of |\foot_name_no| must not be postponed until |\output|
285 time because there may be more footnotes coming on this page that'll
286 increase this number.
287 Therefore we first define the macro |\do_write| which contains the
288 |\write| and the expanded tokens which are to be put out. Every token
289 that should not be expanded is prefixed by |\string| (resulting in
290 character tokens that represent the token name). A |\space| must be
291 inserted to separate |\csname| from |f|. The |\xdef| in the (written)
292 definition code of |f@|\<nameno> is needed because the footnote file
293 will be read in within a group.
294
295 After writing the entry to the footnote file the number for this
296 footnote is set to~0 if it is not already defined (from a previous
297 run).
298
299 \beginprog
300 \def\fnpp_next_footnote{%
301 \init_footnote
302 \global\advance\foot_name_no\@ne
303 \edef\do_write{%
304 \write\foot_file{%
305 \string\advance\c@footnote\@ne
306 \string\expandafter\xdef
307 \string\csname\space f@\number\foot_name_no \endcsname{%
308 \string\number\c@footnote
309 }%
310 }%
311 }%
312 \do_write
313 \global\c@footnote 0\csname f@\number\foot_name_no \endcsname \relax
314 }
315 \endprog
316
317
318 \sect It remains the reading of the footnote file. We have to read in
319 macros with names containing `|@|' characters. This will be done in
320 horizontal mode, so we ignore lineends to discard undesired spaces.
321
322 \beginprog
323 \def\read_foot_file{%
324 \begingroup
325 \catcode`\@\CatLetter \catcode`\^^M\CatIgnore
326 \input \foot_file_name
327 \endgroup
328 }
329 \endprog
330
331
332
333
334 \chap Connection to the output routine.
335
336 We must write the footnote number reset code at the start of each new
337 page. The most easy way to do this is to add an |\immediate\write|
338 to the output routine.
339
340 The output routine has no associated hook. (It should, of course. This
341 is no exotic wish.) So we have to add our code to it by redefining
342 some cseq. In a former version we really rebound |\output|, but that
343 was a leftover from the plain \TeX{} version. Then we had to check for
344 special |\output| invocations, which column we're in, etc. Now we rely
345 on some internals of \LaTeX{}: |\@outputpage| does the real ship out,
346 we just prepend our write to the front.
347
348 The reset code must not be written when no footnote was given by now.
349 We can check for the binding of |\init_footnote| to detect this, it's
350 |\relax| after the first footnote.
351
352 \beginprog
353 \let\fnpp_orig_outputpage=\@outputpage
354 \def\@outputpage{%
355 \ifx \init_footnote\relax
356 \immediate\write\foot_file{\c@footnote\z@}%
357 \fi
358 \fnpp_orig_outputpage
359 }
360 \endprog
361
362
363
364
365 \chap The user interface.
366
367 Footnotes may be produced by |\footnote|, or by |\footnotemark| and
368 |\footnotetext| (the former creates the mark, the latter the text with
369 the last mark). All these tags have an optional argument, a number
370 that shall be used to create the mark for this specific invocation.
371
372 We redefine only the handling of macro invocations without optional
373 arguments. The original bindings are made available in the protected
374 interface, in case footnotes are used for unusual things. (See the
375 chunk on title matters below, for an example.)
376
377 \beginprog
378 \let\FnppOrigFootnote=\footnote % save original bindings
379 \let\FnppOrigFootnotemark=\footnotemark
380
381 \def\footnote{%
382 \@ifnextchar[% % ] (Emacs)
383 \@xfootnote
384 {\fnpp_next_footnote \@xfootnote[\the\c@footnote]}%
385 }
386 \def\footnotemark{%
387 \@ifnextchar[% % ] (Emacs)
388 \@xfootnotemark
389 {\fnpp_next_footnote \@xfootnotemark[\the\c@footnote]}%
390 }
391 \endprog
392
393
394 \sect Footnote tags in minipages behave a bit differently: There
395 |\footnote| and |\footnotetext| create minipage-local footnotes,
396 whereas |\footnotemark| creates a `global' footnote mark. I.e., if one
397 wants to make a footnote in a minipage that shall go on the page, one
398 has to specify |\footnotemark| in the minipage and |\footnotetext|
399 thereafter. |\footnotetext| uses the current value of the footnote
400 counter, since we set it by |\fnpp_next_footnote|, everything will
401 work.
402
403 \LaTeX{} makes a hook available to setup the minipage enviroment. But
404 the hook is initialized in a way that their own hook-enhancement
405 function does not work, we have to repair it first. No comment\,\dots
406
407 \beginprog
408 \ifx \@minipagerestore\relax
409 \let\@minipagerestore\@empty
410 \fi
411
412 \g@addto@macro\@minipagerestore{%
413 \let\footnote\FnppOrigFootnote
414 }
415 \endprog
416
417
418 \sect But footnotes are used for other things, too. E.g., to mention
419 affiliation or acknowledgements in title matters. This is done by
420 |\thanks| that uses |\footnotemark| to construct the respective marks.
421 The expansion of |\thanks| is done by |\maketitle| that resets the
422 footnote counter afterwards. But that reset does not work with this
423 package, as the footnote counter value is not used to determine the
424 next one.
425
426 The most simple solution is to reset |\footnotemark| during the
427 evaluation of |\maketitle|. We can do that in a group since all
428 side-effects of |\maketitle| should be global anyhow.
429
430 \beginprog
431 \let\fnpp_orig_maketitle=\maketitle
432 \def\maketitle{%
433 \begingroup
434 \let\footnotemark\FnppOrigFootnotemark
435 \fnpp_orig_maketitle
436 \endgroup
437 }
438 \endprog
439
440
441
442
443
444 \chap The end.
445
446 Well, after all we're finished with this module. We must not forget to
447 restore the underscore catcode.
448
449 \beginprog
450 \catcode`\_=\CatUsCode
451
452 \endinput
453 \endprog
454
455
456 \sect I would like to thank those who helped me to improve this style.
457 % In particular, XXX provided XXXsubstantial parts of the code.
458
459 \textsc{Chris Thompson} sent change proposals that made the code more
460 robust.
461
462 \textsc{Frank Mittelbach} gave the impulse to make real \LaTeX{}
463 code out of the former plain \TeX{} code. (Actually, that's not as
464 drastic as it sounds. I threw half the code away and used stuff
465 already supplied by the \LaTeX{} kernel, then I added a few lines to
466 take care of minipages and front matter.)
467
468 \textsc{John Lu},
469 \textsc{Sebastian Rahtz},
470 and
471 \textsc{Frank Thomas}
472 provided error and problem reports.
473
474
475
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477
478 \vskip\PltxPreSectSkip
479
480 \begin{rcslog}
481 $StyleLog: footnpag.doc,v $
482 \Revision 2.6 1995/11/10 18:21:26 schrod
483 Make |\footnotetext| usable in |minipage| environment, again.\\
484 Problem reported by Sebastian Rahtz \path|<[email protected]>|.
485
486 \Revision 2.5 1995/08/04 00:18:34 schrod
487 Made a \LaTeXe{} package from this style option.
488
489 User manual is a separate document now, that's better for
490 installation. Started to change the distribution into one that
491 conforms to the `supported bundle guidelines.'
492
493 \Revision 2.4 1995/01/01 18:54:00 schrod
494 Optional arguments are supported now, |\footnotemark| may be used,
495 footnotes in minipages and title matter are handled correctly.\\
496 (Enhancements requested by Frank Mittelbach
497 \path|<[email protected]>|.)
498
499 Started rewrite to a \LaTeXe{} package. Rearranged the code, used
500 \LaTeX{} internals. In particular, |\@outputpage| is now redefined,
501 instead of |\output|. I can throw away all checks for special output
502 invocations, which column we're in, etc., this way. Still,
503 documentation changes and some minor details are missing for the next
504 official release.
505
506 \Revision 2.3 1994/12/31 13:26:31 schrod
507 Spurious messages were produced on pages without footnotes before the
508 first footnote. I had to check if the footnote handling is initialized.\\
509 (Bug reported at 25 Dec 93 by Frank Thomas \path|<[email protected]>|.
510 Actually repaired at 14 Jan 94, but change was not committed until now.)
511
512 \Revision 2.2 1993/02/02 11:04:18 schrod
513 If the first footnote was within a group, the footnote mechanism
514 was initialized a second time by the first footnote outside the group.
515 With this second initialization all information about previous
516 footnotes was discarded.\\
517 (Bug reported on 01 Feb 93 by John Lu \path|<[email protected]>|.)
518
519 \Revision 2.1 1991/11/07 19:58:34 schrod
520 Set up for a new distribution, documentation is now in LaTeX.
521 Added first chapter where user interface and problems are explained.
522
523 \Revision 1.2 1989/04/21 00:00:00 schrod
524 Advances the usability in LaTeX (|\twocolumn|),
525 uses an own stream for reading,
526 resets the counter with |\immediate\write|.
527 (Improvements pointed out by Chris Thompson [CET].)
528
529 \end{rcslog}
530
531
532 \bigskip
533
534 \noindent \textsl{Pre-RCS version history}.
535
536 \medskip
537
538 \noindent Version 1.1 removed a |\begingroup| (88-10-20).
539
540 \smallskip
541
542 \noindent Version 1.0 was released in August, 1987. Actually, it was a
543 posting to \TeX{}hax.
544
545
546
547 \end{document}
548
549
550
551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552 Local Variables:
553 mode: LaTeX
554 TeX-brace-indent-level: 4
555 indent-tabs-mode: t
556 TeX-auto-untabify: nil
557 TeX-auto-regexp-list: LaTeX-auto-regexp-list
558 compile-command: "make footnpag.sty"
559 End: