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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
|
% \iffalse
%%
%% File: manyfoot.dtx Copyright (C) 1998--2005 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}[1993/12/01]
%<package>\ProvidesPackage{manyfoot}
%<package> [2005/09/11 v1.10 Many Footnote Levels Package (NCC)]
%
% \changes{v1.0}{1998/11/09}{Initial version}
% \changes{v1.1}{1998/11/13}{Compatibility problems solved}
% \changes{v1.2}{1998/11/15}{Such footnotes may now appear in minipages!}
% \changes{v1.3}{1998/11/23}{Floating support bug fixed}
% \changes{v1.4}{1998/12/19}{Hand footnotes are moved to nccfoots package}
% \changes{v1.4}{1998/12/19}{Options |ruled| and |para*| added}
% \changes{v1.5}{2003/02/26}{|\DeclareNewFootnote| command introduced}
% \changes{v1.5}{2003/02/26}{Compatibility with footmisc added}
% \changes{v1.5}{2003/02/27}{More compatibility with footmisc}
% \changes{v1.5}{2003/03/03}{|\Footnote|\marg{suffix} and
% |\Footnotemark|\marg{suffix} added}
% \changes{v1.5}{2003/03/16}{Option |perpage| added}
% \changes{v1.5}{2003/03/26}{The |\MFL@footnoterule| introduced
% for more compatibility with footmisc}
% \changes{v1.5}{2003/04/02}{Custom footnote rules support added}
% \changes{v1.6}{2003/05/11}{Restore |\footnotemargin| support occasionally removed}
% \changes{v1.6}{2003/05/12}{Add support for |multiple| option from footmisc}
% \changes{v1.7}{2004/09/20}{The |\ExtraParaSkip| command introduced}
% \changes{v1.8}{2004/11/23}{Minor corrections of the documentation}
% \changes{v1.9}{2005/02/10}{|\NCC@makemark| replaced with |\NCC@makefnmark|}
% \changes{v1.9}{2005/05/11}{Introduce the |\SetFootnoteHook| command}
% \changes{v1.10}{2005/09/11}{Remove overflow in calculation the fudge factor}
%
%<*driver>
\let\makeindex\relax
\documentclass{ltxdoc}
\usepackage[para]{manyfoot}
\DeclareNewFootnote{A}
\DeclareNewFootnote[para]{B}[roman]
\GetFileInfo{manyfoot.sty}
\begin{document}
\title{The \textsf{manyfoot} package\thanks{This file
has version number \fileversion, last
revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{manyfoot.dtx}
\end{document}
%</driver>
% \fi
%
% This package implements a command, |\newfootnote|, that adds
% footnote levels to the standard \LaTeX's footnote mechanism. Footnotes
% of every additional level are automatically grouped together
% on a \LaTeXe{} output page and are separated from another levels
% by the special vertical space and rule.
% The |\newfootnote| command allows customization of the
% way footnotes of additional level are represented in \LaTeXe{}
% documents. Two
% customization styles are available now: the |plain| style is the
% ordinary \LaTeX's style of footnote representation; the |para| style
% causes footnotes to be typeset as a run-in paragraph (derived from
% Donald Knuth's \TeX book and from another sources such as the package
% |fnpara| by Dominik Wujastyk and Chris Rowley and the package
% |footmisc| by Robin Fairbairns).
%
% An additional |\DeclareNewFootnote| command is introduced since the
% version~1.5 of the package. It simplifies creation of new
% footnote levels with automatic enumeration. Thanks to Frank Mittelbach
% for this suggestion and for many other proposals for the package
% improvement.
%
% Since version 1.5, a new footnote rule selection method is
% introduced (thanks to Christian Tapp |<chr.tapp@gmx.de>|
% for the idea of this improvement). It allows a customization of
% footnote rules to be inserted before footnote levels.
%
% \tableofcontents
%
% \section{User Interface}
%
% \DescribeMacro\extrafootnoterule
% Footnotes of different levels are separated at the output page
% by the special footnote rule, |\extrafootnoterule|.
% By the default this command is empty. If you want to separate
% footnotes by a footnote rule you may redefine it
% or call the package with the |ruled| option:
% \begin{quote}
% |\usepackage[ruled]{manyfoot}|
% \end{quote}
% In this case, the |\extrafootnoterule| receives a value of the
% default footnote rule command.
%
% \DescribeMacro\defaultfootnoterule
% The default footnote rule is saved in the |\defaultfootnoterule| command
% at the beginning of document (we provide this for compatibility with
% the |splitrule| option of the \textbf{footmisc} package).
%
% The style |para| of footnotes typesetting needs many code. To save
% space, the support for this style is loaded with |para| or |para*| options.
% If you are going to use run-in paragraph footnotes indented as
% ordinary footnotes, use the package with the
% |para| option:
% \begin{quote}
% |\usepackage[para]{manyfoot}|
% \end{quote}
% To suppress indentation, use it with the |para*| option:
% \begin{quote}
% |\usepackage[para*]{manyfoot}|
% \end{quote}
% Note, that these options only \emph{allow} you to generate
% additional footnote levels in |para| style.
% But what style you prefer for every footnote level is up to you. For
% example, let as generate two footnote levels: the first---in ordinary
% style and the second---in |para| style. To do this we have to write
% the following code in the preamble of the document:
% \begin{quote}
% |\usepackage[para]{manyfoot}|\\
% |\newfootnote{A}|\\
% |\newfootnote[para]{B}|
% \end{quote}
% \DescribeMacro\newfootnote
% The mandatory parameter of |\newfootnote| is a \emph{suffix} to be added
% to the end of command names generated by |\newfootnote| command.
% The optional parameter is a customization
% style for generated footnote level (two styles now implemented, named
% |plain| and |para|; the default is |plain|).
%
% This example generates
% two commands, |\FootnotetextA| and |\FootnotetextB|, for insertion of
% a text into corresponding footnote levels. Their syntax
% is the following:
% \begin{quote}
% |\Footnotetext|\meta{suffix}\marg{marker}\marg{inserted
% text}
% \end{quote}
% They put the \meta{inserted text} marked with \meta{marker} into
% \TeX's insert register |\footins|\meta{suffix} (this insert is also
% generated by |\newfootnote| command). We use \emph{the hand} style of
% footnote marking, because the choice of how such footnotes have to be
% marked is user's one. Such a way simplifies the syntax of new commands
% and minimize a number of additional commands needed.
%
% \DescribeMacro\Footnotemark
% \DescribeMacro\Footnotetext
% \DescribeMacro\Footnote
% It is clear that accompany to |\Footnotetext|\meta{suffix} must
% present something like \emph{the hand footnote mark} command. Such
% commands are provided by |nccfoots| package which is automatically
% loaded in this package. Their syntax is the following:
% \begin{quote}
% |\Footnotemark|\marg{marker}\\
% |\Footnotetext|\marg{marker}\marg{inserted text}\\
% |\Footnote|\marg{marker}\marg{inserted text}
% \end{quote}
% The first command is useful for all footnote levels. Two last commands
% are the hand companions for \LaTeX's |\footnote...| commands.
%
% The question is what these commands have to do when \meta{marker} is
% empty? In such a case we leave the current marker unchanged.
% Therefore, |\Footnote| command is equal to
% \begin{quote}
% |\Footnotemark|\marg{marker}|\Footnotetext{}|\marg{inserted text}
% \end{quote}
% This is useful for |\Footnotetext|\meta{suffix} commands in
% |plain| style. For |para| style the empty \meta{marker} means
% the footnote without marker (this is the special case used for
% splitting long footnotes in |para| style; see below).
%
% Finally, we explain\footnoteA{This is the first A-level footnote.}
% on the previous example\footnoteB{This is the first B-level
% footnote.} how to automate\footnoteA{The second
% A-footnote.} enumeration of the
% additional\footnoteB{The second B-footnote.}
% footnote\footnoteA{The third A-footnote.}
% levels\footnoteB{The third very very very very very very very very very
% long B-footnote.} (we have used in this
% sentence a number of level's |A| and |B| footnotes to show how this
% package works). Let us enumerate the footnotes of |A|~level by arabic
% numbers and the footnotes of |B|~level by roman numbers. We allocate
% two new counters named |footnoteA| and |footnoteB| and define the
% corresponding |\footnote...| commands with automatic enumeration. The
% corresponding code is the following
% \begin{quote}
% |\newcounter{footnoteA}|\\
% |\newcommand{\footnoteA}{%|\\
% | \stepcounter{footnoteA}%|\\
% | \Footnotemark\thefootnoteA \FootnotetextA{}}|\\
% |\newcounter{footnoteB}|\\
% |\newcommand{\footnoteB}{%|\\
% | \stepcounter{footnoteB}%|\\
% | \Footnotemark\thefootnoteB \FootnotetextB\thefootnoteB}|\\
% |\renewcommand{\thefootnoteB}{\roman{footnoteB}}|
% \end{quote}
% To produce footnotes presented here, we have done the following
% \begin{verbatim}
% Finally, we explain\footnoteA{This is the first A-level
% footnote.} on the previous example\footnoteB{This is the first
% B-level footnote.} how to automate\footnoteA{The second
% A-footnote.} enumeration of the additional\footnoteB{The second
% B-footnote.} footnote\footnoteA{The third A-footnote.}
% levels\footnoteB{The third very very very very very very very
% very very long B-footnote.}\end{verbatim}
%
% \section{Declaring New Footnotes}
%
% \DescribeMacro\DeclareNewFootnote
% To create a new footnote level with automate enumeration, you need to
% type a bulk of code: create a new footnote level (e.g.~|\newfootnote{A}|),
% create a counter for automate enumeration (e.g.~|\newcounter{footnoteA}|),
% and create a footnote insertion command (e.g.~|\newcommand{\footnoteA}|).
% All these things can be automated with the |\DeclareNewFootnote| command
% used in the preamble only:
% \begin{quote}
% |\DeclareNewFootnote|\oarg{footnote style}\marg{suffix}\oarg{enumeration style}
% \end{quote}
% Here \meta{footnote style} is the customization style (|plain| is default) and
% \meta{enumeration style} is a style of numbering. This macro
% also prepares |\footnotemark|\meta{suffix}, |\footnotetext|\meta{suffix},
% |\Footnotemark|\meta{suffix}, and |\Footnote|\meta{suffix} commands for
% completeness.
% For example, the command |\DeclareNewFootnote{A}| creates the following:
% \begin{itemize}
% \item The new plain footnote level with \TeX's insert register |\footinsA|;
% \item The counter |footnoteA| with arabic numbering;
% \item The command |\FootnoteA|\marg{marker}\marg{inserted text};
% \item The command |\FootnotemarkA|\marg{marker};
% \item The command |\FootnotetextA|\marg{marker}\marg{inserted text};
% \item The command |\footnoteA|\oarg{number}\marg{inserted text};
% \item The command |\footnotemarkA|\oarg{number}; and
% \item The command |\footnotetextA|\oarg{number}\marg{inserted text}.
% \end{itemize}
% The first three |\Footnote...| commands work as their analogues without
% suffix, and the behavior of three last commands is just the same as for
% ordinary |\footnote|, |\footnotemark|, and |\footnotetext|.
% Examples of footnote controls shown in the previous section can be easy
% specified in the following two lines:
% \begin{quote}
% |\DeclareNewFootnote{A}|\\
% |\DeclareNewFootnote[para]{B}[roman]|
% \end{quote}
%
% \section{Custom Footnote Rules}
%
% \DescribeMacro\SelectFootnoteRule
% A custom footnote rule can be specified for every new footnote level.
% Just store the |\SelectFootnoteRule| command before a new footnote
% declaration. Its syntax is the following:
% \begin{quote}
% |\SelectFootnoteRule|\oarg{priority}\marg{rule name}\oarg{action}
% \end{quote}
% The \meta{priority} is a nonnegative integer number specifying an importance
% of the rule. It controls the process of a footnote rule selection while
% typeset (see more detail description below). The default priority is 0.
% The \meta{rule name} is a prefix of the footnote rule command to be used
% before the next footnote level. The command |\|\meta{rule name}|footnoterule|
% is used as a footnote rule. The \meta{action} parameter specifies an
% additional action to be applied just before the next footnote group if it
% is nonempty (for example, an action can produce a marginal mark near the
% footnote group). The default action is empty. A footnote rule and
% an action must insert a material of zero height in vertical mode.
%
% Two footnote rule commands are predefined:
% |\extrafootnoterule| and |\defaultfootnoterule|. The |\extrafootnoterule|
% is selected with zero priority before a new footnote level if no other
% footnote rule was selected with the |\SelectFootnoteRule| command. The
% |\defaultfootnoterule| is usually equal to the |\footnoterule|, but if
% the |\footnoterule| was redefined in the \textbf{footmisc} package with
% the |splitrule| option, the |\defaultfootnoterule| will save the
% original value of the footnote rule. So, if you want to select an ordinary
% footnote rule for the next footnote level, use the following command
% \begin{quote}
% |\SelectFootnoteRule{default}|
% \end{quote}
% The following example create four footnote levels with rule inserted between
% footnotes A,B and C,D:
% \begin{quote}
% |\DeclareNewFootnote{A}|\\
% |\DeclareNewFootnote[para]{B}[alph]|\\
% |\SelectFootnoteRule[1]{default}|\\
% |\DeclareNewFootnote{C}[roman]|\\
% |\DeclareNewFootnote{D}[Roman]|
% \end{quote}
% To use more custom footnote rules, you must create corresponding commands
% in some way.
%
% The algorithm of footnote rule insertion while a page output is the following:
% \begin{itemize}
% \item At first, we set the |\defaultfootnoterule| to be the current rule.
% Then we test the insert register of the standard footnote group.
% If it is empty, we set the priority of current rule to |1|,
% otherwise to |-1| (|-1| means that this rule is already played).
% \item After that, we do the following for every next footnote group.
% We compare the priority of current rule and the priority of rule
% linked with the next footnote group. If the current priority is less
% or equal to the next priority, the current rule is changed to the
% next rule and the current priority is set to the next priority.
% Then we test an insert register of the next footnote group.
% If this footnote group is nonempty, we insert the current rule
% before it and decrease the current priority to |-1| (played rule).
% \end{itemize}
%
% \DescribeMacro\footnoterulepriority
% The priority for the rule of standard footnote group is specified
% in the |\footnoterulepriority| command. Its default value is |1| (this means that
% the standard footnote rule is more important then every next rule of 0th priority).
% You can redefine this priority with the |\renewcommand|.
%
% \section{Add Hooks at the Beginning of Footnotes}
%
% \DescribeMacro\SetFootnoteHook
% Since version 1.9, a new command |\SetFootnoteHook|\marg{text} is introduced.
% This command is used before a new footnote declaration and specifies
% an action applied for such footnotes.
%
% If the new footnote level is plain, the hook is applied at the beginning of
% every its footnote. For example, the following declaration specifies
% A-footnotes with hang numbering:
% \begin{quote}
% |\SetFootnoteHook{\hangindent=1.8em\noindent}|\\
% |\DeclareNewFootnote{A}|
% \end{quote}
%
% For para-footnotes, the hook is applied in the output routine after
% merging all para-footnotes together. The following declaration specified
% B-footnotes starting with the word ``Cases:'' typeset in boldface:
% \begin{quote}
% |\SetFootnoteHook{\noindent\textbf{Cases:}\quad}|\\
% |\DeclareNewFootnote[para]{B}[alph]|\\
% \end{quote}
%
% \section{Per-page Footnotes Numbering}
%
% The per-page resetting of counters can be implemented with the |perpage|
% package by David Kastrup. For example, if you need to
% reset the |footnoteA| counter every page, just insert the following
% in the preamble of you document (after declaring the footnote level A of course):
% \begin{quote}
% |\usepackage{perpage}|\\
% |\MakePerPage{footnoteA}|
% \end{quote}
% If all new footnote levels declared with the |\DeclareNewFootnote| command
% must reset every page, use the |perpage| option:
% \begin{quote}
% |\usepackage[perpage]{manyfoot}|
% \end{quote}
% In this case, the |perpage| package is loaded automatically and the
% |\MakePerPage| command is applied to every counter created with the
% |\DeclareNewFootnote|.
%
% \section{Splitting of Para-Footnotes}
%
% The algorithm proposed by Donald Knuth for processing run-in
% paragraph footnotes has some shortages. Namely, small overfulls of
% output page frequently arise and the automatical splitting of long
% footnotes is impossible. First bug is corrected here (look at the
% implementation section below), but the second one couldn't be easily
% eliminated.
%
% \DescribeMacro\SplitNote
% To split a long footnote near the end of the output page we propose
% the following method. You should decide where the splitting have to be
% done. Then you split footnote ``by hands" into two parts. You leave
% \emph{the first part} at the same position in the text and complete its
% text by the command |\SplitNote|. You move \emph{the second part} down
% in the source file and attach it to any text corresponding to the next
% page via the |\Footnotetext...| command with \emph{the empty marker}.
% E.g. you source text will look as follows:
% \begin{verbatim}
% This text goes on the current
% page\footnoteB{This is the beginning of the long
% footnote ... the splitting must be here\SplitNote}
% ...
% This text goes on the next
% page\FootnotetextB{}{and the end of the split
% footnote is here ...}\end{verbatim}
% If both parts of split footnote get into the same output page, the
% splitting is ignored.
%
% \section{Footnotes within Minipages and Multicolumns}
%
% If you attach an additional level footnote to some text inside a
% minipage, it will appear at the bottom of the page nor the minipage.
%
% The package correctly works together with |multicol| package and
% gives good results when switching between one and two columns by
% \LaTeX's commands |\twocolumn| and |\onecolumn|.
%
% \section{Compatibility with footmisc}
%
% The |footmisc| package also provides the |para| option. You cannot
% use this option with |footmisc| if you plan to use it (or |para*|)
% with |manyfoot|.
%
% The footnote margins management from the |footmisc| package acts on the
% |manyfoot| also, but with some limitations concerning to footnotes
% in the |para| style:
% \begin{itemize}
% \item If the |manyfoot| package is loaded with the |para*| option,
% the margin management options of the |footmisc| package have no
% influence on additional footnotes of |manyfoot| in |para| style.
% \item If the |manyfoot| package is loaded with the |para| option,
% the margin management options |flushmargin| and |hang| of the
% |footmisc| package appropriately change the indentation of |para|
% footnotes created with the |manyfoot| package. More exactly, a
% nonnegative value of the |\footnotemargin| is taken into
% account in this case. But if a width of the starting footnote
% marker becomes greater than |0.8em|, the hang indentation of such
% footnote will exceed the value of |\footnotemargin|.
% \end{itemize}
% Footnotes having the |plain| style inherit all
% formatting specified in the |footmisc|, because they use the
% standard |\@makefntext| hook.
%
% \section{Add Extra Skip for Para-Footnotes}
%
% The algorithm used for calculation the vertical space occupied
% with para-footnotes has one serious disadvantage. It cannot exactly
% calculate how many vertical space the collected para-footnotes will
% occupy because the formatting of such footnotes in vertical box is
% applied in the output routine \textit{after} \TeX\ decides on page
% breaking. For example, if collected para-footnotes occupy 2.25 lines,
% the algorithm reserves the vertical space of |2.25\normalbaselineskip|
% for them, but when such footnotes will be formatted in vbox, 3 lines
% will be necessary of course. This is the reason why the use of
% para-footnotes can lead to page overfull. To compensate this
% overfull we use a special trick: we add a special space to
% a value of skip for all insert registers taking part with
% para-inserts.
% When the insertions are formatted in the output routine, the
% adjusted space is turned back. So, the additional space appears
% and the overfull disappears.
%
% The value of space to be adjusted is calculated as follows:
% \begin{center}
% |max(\footnotesep-\height\strut,0)+0.5\normalbaselineskip|
% \end{center}
% We take into account here that the
% value of |\footnotesep| can be larger than the height of |\strut|
% and the total height of para-footnotes is less than the required
% height by |0.5\baselineskip| on the average.
%
% \DescribeMacro\ExtraParaSkip
% Sometimes, the assumptions on the required extra space are wrong
% and footnotes can overlap on the text (this situation can occur
% in long tables). So, the new command, |\ExtraParaSkip|\marg{space},
% was introduced since version 1.7 (by the proposal of Uwe L\"uck
% |<ednotes.sty@web.de>| and Florian Kragl |<a9902976@unet.univie.ac.at>|)
% to adjust the default extra space.
% The command can be used in the preamble only.
% It can be used more than once. The later use of the command
% overrides the previous one.
%
% \StopEventually{}
%
% \section{The Implementation}
%
% First we load |nccfoots| package, containing hand footnote mark
% commands and the command |\NCC@makefnmark|\marg{marker} which
% generates marker in |\@thefnmark| command.
% \begin{macrocode}
%<*package>
\RequirePackage{nccfoots}
% \end{macrocode}
%
% \begin{macro}{\extrafootnoterule}
% Then we define the empty |\extrafootnoterule| command and implement |ruled|
% option that sets the |\extrafootnoterule| to be equal to the
% |\defaultfootnoterule|. The |\defaulfootnoterule| is later defined
% at the beginning
% of document. It is set to the |\pagefootnoterule| if the last is specified
% or to the |\footnoterule| if not.
% This trick provides the compatibility with the |splitrule| option of the
% \textbf{footmisc} package in which the default |\footnoterule| is saved
% in |\pagefootnoterule| and then redefined.
% \begin{macrocode}
\newcommand{\extrafootnoterule}{}
\DeclareOption{ruled}{\def\extrafootnoterule{\defaultfootnoterule}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@columnwidth}
% \begin{macro}{\MFL@floathook}
% We use the dimen |\MFL@columnwidth| instead of |\columnwidth| while
% producing the footnote for insertion. We set this dimen to be equal
% to |\columnwidth| at the beginning of document and within the
% |\@floatplacement| command. The command |\MFL@floathook| does this
% job. Later, in |para| option, we'll add to this hook the resetting of
% the fudge factor.
% \begin{macrocode}
\newdimen\MFL@columnwidth
\def\MFL@floathook{\MFL@columnwidth\columnwidth}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\MFL@insert}
% The command |\MFL@insert|\marg{insert register}\marg{text}
% inserts the text to the insert register and sets the standard
% splitting parameters. We let this command to be equal |\MFL@mpinsert|
% when go into a minipage. To use this command after a minipage we save
% its value in |\MFL@realinsert| command.
% To support |multiple| option from |footmisc| we add the
% |\FN@mf@prepare| command from |footmisc| (suggested by Frank Mittelbach).
% \begin{macrocode}
\long\def\MFL@insert#1#2{%
\insert#1{\splittopskip\footnotesep \splitmaxdepth \dp\strutbox
\floatingpenalty\@MM #2%
}%
\FN@mf@prepare
}
\providecommand\FN@mf@prepare{}
\let\MFL@realinsert\MFL@insert
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@applyhook}
% The command |\MFL@applyhook|\marg{insert register} applies a hook
% corresponding to the given insert register.
% \begin{macrocode}
\def\MFL@applyhook#1{\csname MFL@hook\string#1\endcsname}
% \end{macrocode}
% \end{macro}
%
% \subsection{Footnote Styles Support}
%
% \DescribeMacro{\MFL@start...}
% Every additional footnote level has deal with its own
% \emph{insert register}
% which is allocated by the |\newfootnote| command. This insert register is
% automatically initialized with the same values as the |\footins|
% register. You can modify its parameters and do something more in
% the command
% \begin{quote}
% |\MFL@start|\meta{style}\marg{insert register}
% \end{quote}
% You must do all modifications globally, because this command is called
% within the group. It is called at the beginning of the document for
% every
% footnote of such style and is needed in the preamble only.
%
% \DescribeMacro{\MFL@fnote...}
% To put footnote into the insert register the command
% \begin{quote}
% |\MFL@fnote|\meta{style}\marg{insert
% register}\marg{marker}\marg{inserted text}
% \end{quote}
% is used. Note that you have to define it with |\long| modifier if you
% allow footnotes consisting of a number of paragraphs. You have to use
% the macros |\MFL@insert| and |\MFL@columnwidth| instead of |\insert|
% and |\columnwidth|.
%
% \DescribeMacro{\MFL@process...}
% And the last style customization command
% \begin{quote}
% |\MFL@process|\meta{style}\marg{insert register}
% \end{quote}
% is called within the output routine to prepare the box of the
% \meta{insert register} for joining it with another footnote inserts.
%
% Do some comments on joining algorithm. It joins together all nonempty
% footnote insert boxes and puts the result into |\footins| box. Special
% vertical space and footnote rule are added between every
% two neighboring nonempty inserts. This space
% is defined by the skip value from the second neighbor. In other words the skip
% of the \meta{insert register} is the vertical space to be added
% between
% this insert and any nonempty footnote insert coming before it in the
% \emph{list of footnote inserts}. Note that this skip can be
% modified while processing of the document (the |multicol| package
% multiplies |\skip| and |\count| of |\footins| to the number of columns
% when goes into multicolumns mode; we do the same with these parameters
% of all another footnote inserts to provide the compatibility with
% |multicol| package).
%
% \DescribeMacro{\MFL@skip}
% This command adds the vertical space just before the
% |\MFL@process...| command. The value of this space is also calculated
% in |\@tempskipa|. Note that this command is inserted
% \emph{between} vertical boxes in joining procedure. If processed box
% is the first nonempty footnote box (|\footins| register and all
% registers going in footins list before the processed insert are
% empty), the command |\MFL@skip| is ignored.
%
% \subsection{Plain Footnote Style}
%
% \begin{macro}{\MFL@startplain}
% \begin{macro}{\MFL@fnoteplain}
% \begin{macro}{\MFL@processplain}
% It is very simple. The commands
% |\MFL@startplain| and |\MFL@processplain| do nothing
% \begin{macrocode}
\let\MFL@startplain\@gobble
\@onlypreamble\MFL@startplain
\let\MFL@processplain\@gobble
% \end{macrocode}
% and the command |\MFL@fnoteplain| does near the same as the usual
% \@footnotetext command.
% \begin{macrocode}
\long\def\MFL@fnoteplain#1#2#3{\NCC@makefnmark{#2}%
\MFL@insert#1{\reset@font\footnotesize
\interlinepenalty\interfootnotelinepenalty
\hsize\MFL@columnwidth \@parboxrestore
\protected@edef\@currentlabel{\@thefnmark}%
\color@begingroup
\MFL@applyhook{#1}%
\@makefntext{%
\rule\z@\footnotesep\ignorespaces#3\@finalstrut\strutbox}%
\color@endgroup
}%
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Para Footnote Style}
%
% \begin{macro}{\ifMFL@paraindent}
% This style is too complicated. We load its
% commands optionally. First we define |\ifMFL@paraindent| command to
% switch between indented and non-indented versions of |para| footnotes.
% \begin{macrocode}
\newif\ifMFL@paraindent \MFL@paraindenttrue
% \end{macrocode}
% \end{macro}
%
% Now we implement the |para| option.
% \begin{macrocode}
\DeclareOption{para}{%
% \end{macrocode}
%
% \begin{macro}{\footglue}
% The |\footglue| skip is the horizontal space between footnotes in
% run-in paragraph. It's name goes from \TeX book
% (Appendix D. Dirty Tricks) and we don't rename this
% register. This gives us an additional protection from the usage
% this package in the document where another package also provides
% footnotes in |para| style.
% \begin{macrocode}
\newskip\footglue
% \end{macrocode}
% Contrarily to |footmisc| package we initialize this skip in terms of
% the footnote size (nor the normal size).
% \begin{macrocode}
{\footnotesize \global\footglue=1em plus.3em minus.3em }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SplitNote}
% \begin{macro}{\ifMFL@split}
% The switch |MFL@split| provides footnote splitting and
% the command |\SplitNote| simply sets this switch to \emph{true}.
% \begin{macrocode}
\newif\ifMFL@split \MFL@splitfalse
\newcommand\SplitNote{\MFL@splittrue}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\MFL@startpara}
% Now we prepare |para| support routines. The first is the starting
% routine.
% \begin{macrocode}
\def\MFL@startpara#1{%
% \end{macrocode}
% It adds to insert's skip additional space |\MFL@paraskip| (it is
% non-stretchable and is calculated at the beginning of the document).
% \begin{macrocode}
\global\advance\skip#1\MFL@paraskip
% \end{macrocode}
% Then we define the command named |\MFL@split\footins|\meta{suffix}
% which saves splitting information for the corresponding footnote
% level. While processing the document this command will have the
% |\MFL@applyhook|\marg{insert register} value (without splitting) or
% |\noindent| value (with splitting).
% \begin{macrocode}
\MFL@setsplit{#1}{\MFL@applyhook{#1}}%
}
\@onlypreamble\MFL@startpara
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@fnotepara}
% The next command inserts footnote into \meta{insert register}.
% We use Knuth's trick to inform the output procedure how many
% horizontal space occupy the footnote by modifying its vertical size
% as \emph{fudgefactor}${}\times{}$\emph{footnotebaselineskip} where
% \emph{fudgefactor} is the ratio of \emph{footnotebaselineskip} to
% |\columnwidth|. The real vertical size of such footnote is not needed
% because the footnote is save in |\hbox| nor |\vbox| and
% while processing to the run-in paragraph will be unboxed.
%
% This footnote command is not |\long| because the |\par| command cannot
% be used in |\hbox|. At the beginning we make footnote mark and
% set current label only if footnote mark was nonempty. We use below the
% temporary switch |@tempswa| to select the case of nonempty footnote
% mark.
% \begin{macrocode}
\def\MFL@fnotepara#1#2#3{\let\@thefnmark\@empty
\NCC@makefnmark{#2}%
\MFL@insert#1{\reset@font\footnotesize
\ifx\@thefnmark\@empty \@tempswafalse \else
\@tempswatrue
\protected@edef\@currentlabel{\@thefnmark}%
\fi
\color@begingroup
% \end{macrocode}
% Now we test the width of the footnote mark and if\/ it less than
% |0.8em| we calculate in |\@tempdima| the difference between |0.8em|
% and the natural width of the marker. This horizontal space is
% inserted before the footnote mark. Why it is needed? While the
% processing of |para| insert we set |\parindent| to |1em|. And taking
% into account that the marker width is at least |0.8em| we obtain the
% distance at least |1.8em| between the footnote text and the left
% margin. It is exactly the same distance as for footnotes in |plain|
% style. Why we add this space using |\hskip|? It should be removed
% when line will be broken at this point.
% We add this space when the switch |MFL@paraindent| is true.
% \begin{macrocode}
\if@tempswa
\setbox\@tempboxa\hbox{\@makefnmark}%
\ifMFL@paraindent
\@tempdima.8em \advance\@tempdima-\wd\@tempboxa
\ifdim \@tempdima<\z@ \@tempdima\z@ \fi
\else
\@tempdima\z@
\fi
\fi
\setbox\@tempboxa\hbox{%
\if@tempswa
\hskip\@tempdima\unhbox\@tempboxa\nobreak
\fi
% \end{macrocode}
% Well. Now we insert the footnote text into hbox and test the
% |MFL@split| switch.
% If it is true (splitting needed) we add at the end of text the special
% small penalty |-1|. It will indicate us where the splitting needed.
% In false case we set penalty |-10| and insert |\footglue| space.
% \begin{macrocode}
\ignorespaces#3\unskip\strut
\ifMFL@split \penalty\m@ne\space \else
\penalty-10 \hskip\footglue
\fi
}%
% \end{macrocode}
% And finally we use Knuth's trick.
% \begin{macrocode}
\dp\@tempboxa\z@ \ht\@tempboxa\MFL@fudgefactor\wd\@tempboxa
\box\@tempboxa
\color@endgroup
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@processpara}
% This is the last procedure of |para| style which is called in the
% output routine. We must reorganize the box of the \meta{insert
% register} which is the ``vbox of hboxes".
% \begin{macrocode}
\def\MFL@processpara#1{%
% \end{macrocode}
% Firstly we redefine |\MFL@skip| command decreasing its skip by
% |\MFL@paraskip|.
% \begin{macrocode}
\advance\@tempskipa -\MFL@paraskip
\edef\MFL@skip{\vskip\the\@tempskipa\relax}%
\setbox#1\vbox{%
% \end{macrocode}
% Now we execute the first step of Knuth's algorithm: convert the ``vbox
% of hboxes" to ``hbox of hboxes".
% \begin{macrocode}
\unvbox#1\setbox\@tempboxa\hbox{}\MFL@makehhbox
% \end{macrocode}
% The second step is unhboxing of all first level hboxes. After that we
% have the normal hbox which can be easily converted to paragraph vbox.
% \begin{macrocode}
\setbox\@tempboxa\hbox{\unhbox\@tempboxa\MFL@removehboxes}%
% \end{macrocode}
% Now we set all needed parameters to prepare run-in paragraph.
% When we set a |\parindent|, we do test on the compatibility with
% |footmisc| package. If this package is in use, the |\footnotemargin|
% register is specified. To provide just the same indent of the first line
% for para footnotes as for ordinary footnotes, we calculate the par indent
% as |\footnotemargin-0.8em| (|0.8em| is the width of marker going after).
% This calculation is executed in the only case of nonnegative
% |\footnotemargin| value.
% \begin{macrocode}
\footnotesize
\hsize\MFL@columnwidth \@parboxrestore
\ifMFL@paraindent
\@ifundefined{footnotemargin}%
{\parindent\footglue}%
{\parindent\footnotemargin\relax
\ifdim\parindent<\z@ \parindent\footglue
\else \advance\parindent -0.8em \fi}%
\fi
% \end{macrocode}
% Then we call |\MFL@split\footins|\meta{suffix} macro to set |\noindent|
% if\/ it is needed (this case occurs when the footnote was splitted at
% the previous page) or apply its hook otherwise.
% \begin{macrocode}
\csname MFL@split\string#1\endcsname
% \end{macrocode}
% Here is the right place where |\footnotesep| rule have to be inserted.
% \begin{macrocode}
\rule\z@\footnotesep
% \end{macrocode}
% Finally, we convert prepared hbox to vbox and test the last penalty
% (it is
% the penalty of the last |para| footnote inserted into this vbox). This
% penalty is |-10| or |-1|. The case |-1| means that the last
% footnote continues onto the next page (splitting case; see the
% command |\MFL@fnotepara|). In this case we adjust the last line of
% paragraph to the right margin and set |\MFL@split\footins|\meta{suffix}
% macro to |\noindent|. Otherwise, we apply the hook as its default value.
% \begin{macrocode}
\unhbox\@tempboxa\unskip
\ifnum\lastpenalty=\m@ne \parfillskip\z@
\MFL@setsplit{#1}{\noindent}%
\else
\MFL@setsplit{#1}{\MFL@applyhook{#1}}%
\fi
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@makehhbox}
% This procedure converts ``vbox of hboxes" to ``hbox of hboxes".
% Its implementation has minimal distinctions from the original code
% described in \TeX book. We removed from it the initialization of
% the accumulating box (|\@tempboxa|) and added a possibility some boxes
% in the list to be vboxes nor hboxes. Such vboxes arises because
% while processing a minipage we put all internal footnotes
% into vbox to prevent their splitting.
% We use the box 0 as the temporary box here.
% \begin{macrocode}
\def\MFL@makehhbox{%
\loop\setbox\z@\lastbox \ifhbox\z@
\setbox\@tempboxa\hbox{\box\z@\unhbox\@tempboxa}%
\repeat
\ifvbox\z@ \unvbox\z@ \MFL@makehhbox \fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@removehboxes}
% This is an internal procedure described in \TeX book to unboxing ``hbox
% of hboxes".
% \begin{macrocode}
\def\MFL@removehboxes{\setbox\@tempboxa\lastbox
\ifhbox\@tempboxa{\MFL@removehboxes}\unhbox\@tempboxa\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@setsplit}
% This macro sets the value of |\MFL@split\footins|\meta{suffix} macro.
% \begin{macrocode}
\def\MFL@setsplit#1#2{%
\expandafter\gdef\csname MFL@split\string#1\endcsname{#2}%
}
% \end{macrocode}
% \end{macro}
%
% Finally, we have to prepare something for work.
% We add to |\MFL@floathook| the calculation of the fudge factor.
% Such a calculation is needed when we switch between one and two
% columns by the standard \LaTeX{} commands. The original Knuth's
% version of the algorithm produces an overflow if |\normalbaselineskip|
% greater or equal to |16pt|. In version 1.10, the calculation
% was improved to remove overflow. Now overflow appears when
% |\normalbaselineskip| is |64pt|. I think it will be enough for
% all applications. By the way, in ordinary cases the new version
% calculates the fudge factor two times more accurate than the
% Knuth's one.
% \begin{macrocode}
\g@addto@macro\MFL@floathook{%
\begingroup
\footnotesize \@tempdima\normalbaselineskip
\multiply \@tempdima \@cclvi
\@tempdimb \columnwidth
\divide \@tempdimb \@cclvi
\divide \@tempdima \@tempdimb
\xdef\MFL@fudgefactor{\strip@pt\@tempdima}%
\endgroup
}
% \end{macrocode}
%
% \begin{macro}{\MFL@paraskip}
% The last trick is the calculation of |\MFL@paraskip|~--- the skip
% which has to be added to the skip of all |para| style footnote
% inserts and then ``turned back" while preparing of run-in paragraph.
% Why it is needed? Two reasons. The first, the
% value of |\footnotesep| may be larger than the height of |\strut|.
% And we nowhere take into account this exceeding. The second, the
% total height of |para| footnotes is less then the real height of
% the prepared run-in paragraph by |0.5\baselineskip| on the average.
% So we have to add it to the |\skip| register for the compensation.
%
% \begin{macro}{\ExtraParaSkip}
% I new command, |\ExtraParaSkip|\marg{space}, is introduced here
% by the proposal of Uwe L\"uck |<ednotes.sty@web.de>|. Using it,
% everyone can adjust a value of skip to be added to all |\skip|
% registers of para-inserts.
% \begin{macrocode}
\newcommand*\ExtraParaSkip[1]{%
\def\MFL@xparaskip{\advance\@tempdima#1\relax}%
}
\let\MFL@xparaskip\relax
\@onlypreamble\ExtraParaSkip
\@onlypreamble\MFL@xparaskip
% \end{macrocode}
% \end{macro}
%
% We do calculations of the |\MFL@paraskip| at the beginning of
% the document.
% \begin{macrocode}
\AtBeginDocument{%
\begingroup
\footnotesize
\@tempdima\footnotesep
\advance\@tempdima -\ht\strutbox
\ifdim\@tempdima<\z@ \@tempdima\z@ \fi
\advance\@tempdima.5\normalbaselineskip
\MFL@xparaskip % Add extra para skip
\xdef\MFL@paraskip{\the\@tempdima\relax}%
\endgroup
}
}
% \end{macrocode}
% \end{macro}
%
% Finally, we implement |para*| option which suppresses indentation of
% |para| footnotes.
% \begin{macrocode}
\DeclareOption{para*}{%
\@ifundefined{MFL@startpara}{\ExecuteOptions{para}}{}%
\MFL@paraindentfalse
}
% \end{macrocode}
%
% \subsection{Perpage Option}
%
% The |perpage| option just sets the true value for the |MFL@perpage|:
% \begin{macrocode}
\newif\ifMFL@perpage \MFL@perpagefalse
\DeclareOption{perpage}{\MFL@perpagetrue}
% \end{macrocode}
% Now we can process the package options:
% \begin{macrocode}
\ProcessOptions\relax
% \end{macrocode}
% After that, we test the |MFL@perpage| and load the |perpage| package
% on demand:
% \begin{macrocode}
\ifMFL@perpage \RequirePackage{perpage}\fi
% \end{macrocode}
%
% \subsection{Additional Footnotes Support}
%
% \begin{macro}{\MFL@list}
% We initialize the list of all additional footnote levels to be empty.
% \begin{macrocode}
\def\MFL@list{}
% \end{macrocode}
% Its items will have the form |\@elt|\marg{style}\meta{insert register}
% \end{macro}
%
% \begin{macro}{\SelectFootnoteRule}
% Next we implement the footnote rule selection command.
% It defines the |\MFL@rule| command that is later used in the
% |\MFL@newinsert| command to specify accompany footnote level rule.
% \begin{macrocode}
\newcommand*{\SelectFootnoteRule}[2][0]{%
\edef\@tempa{\noexpand\MFL@selectrule{#1}{%
\expandafter\noexpand\csname #2footnoterule\endcsname}}%
\@ifnextchar[{\@tempa}{\@tempa[]}%
}
\def\MFL@selectrule#1#2[#3]{\def\MFL@rule{\MFL@joinrule{#1}{#2}{#3}}}
\SelectFootnoteRule{extra}% Set the default footnote rule
\@onlypreamble\SelectFootnoteRule
\@onlypreamble\MFL@selectrule
\@onlypreamble\MFL@rule
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SetFootnoteHook}
% |\SetFootnoteHook|\marg{hook} saves a hook in the internal command.
% When a new footnote is created, this hook is applied to it.
% \begin{macrocode}
\newcommand{\SetFootnoteHook}[1]{\def\MFL@footnotehook{\MFL@fhook{#1}}}
\@onlypreamble\SetFootnoteHook
\@onlypreamble\MFL@footnotehook
\SetFootnoteHook{}% Empty hook by default
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@fhook}
% |\MFL@fhook|\marg{hook}\marg{insert register} associates a hook with
% the given insert register and resets the current hook.
% \begin{macrocode}
\long\def\MFL@fhook#1#2{%
\expandafter\def\csname MFL@hook\string#2\endcsname{#1}%
\SetFootnoteHook{}%
}
\@onlypreamble\MFL@fhook
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newfootnote}
% Then we implement the basic command which generates additional
% footnote levels.
% \begin{macrocode}
\newcommand*{\newfootnote}[2][plain]{%
% \end{macrocode}
% Firstly, we test the \meta{style} to be valid.
% \begin{macrocode}
\@ifundefined{MFL@fnote#1}{%
\PackageError{manyfoot}{Unknown footnote style #1}%
{Known styles are `plain' and `para'\MessageBreak
(if the package was loaded with the para or para* option)}}{}%
% \end{macrocode}
% Then we allocate and initialize a new insert
% \begin{macrocode}
\expandafter\MFL@newinsert\csname footins#2\endcsname
% \end{macrocode}
% generate |\Footnotetext|\meta{suffix} and its hook
% \begin{macrocode}
\edef\@tempa{\noexpand\newcommand
\expandafter\noexpand\csname Footnotetext#2\endcsname
{\expandafter\noexpand\csname MFL@fnote#1\endcsname{%
\expandafter\noexpand\csname footins#2\endcsname}}%
\noexpand\MFL@footnotehook{%
\expandafter\noexpand\csname footins#2\endcsname}%
}%
\@tempa
% \end{macrocode}
% and finally add the description of this insert to the list of
% additional footnote inserts.
% \begin{macrocode}
\@cons\MFL@list{{#1}\csname footins#2\endcsname}%
}
\@onlypreamble\newfootnote
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@newinsert}
% The initialization of a new insert. A current rule selection command
% is linked with the new insert by the insert count number.
% \begin{macrocode}
\def\MFL@newinsert#1{\newinsert#1%
\expandafter\let\csname MFL@join\number #1\endcsname \MFL@rule
\SelectFootnoteRule{extra}% Reset to default rule again
\skip#1\skip\footins \dimen#1\dimen\footins \count#1\count\footins
}
\@onlypreamble\MFL@newinsert
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@makemark}
% All additional footnote mark commands with automatic numbering are based
% on the following command:
% \begin{quote}
% |\MFL@makemark|\marg{counter}\marg{stepcounter}\marg{command}\oarg{number}
% \end{quote}
% This command tests an optional parameter and, if it exists, prepares the marker
% using the specified number. Otherwise, it at first executes the
% \meta{stepcounter}\marg{counter} command (it is either |\stepcounter| or |\@gobble|)
% and then makes a mark. Finally, it executes the \meta{command} parameter.
% Check for |multiple| footnotes added as suggested by Frank Mittelbach.
% \begin{macrocode}
\def\MFL@makemark#1#2#3{%
\FN@mf@check
\@ifnextchar[{\MFL@xmkmark{#1}{#3}}{#2{#1}\MFL@mkmark{#1}{#3}}%
}
\providecommand\FN@mf@check{}
\def\MFL@xmkmark#1#2[#3]{%
\begingroup
\csname c@#1\endcsname #3\relax
\unrestored@protected@xdef\@thefnmark{\csname the#1\endcsname}%
\endgroup
#2%
}
\def\MFL@mkmark#1#2{\protected@xdef\@thefnmark{\csname the#1\endcsname}%
#2%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareNewFootnote}
% Now we define the service command simplifying creation of footnotes
% in almost all cases.
% \begin{macrocode}
\newcommand*{\DeclareNewFootnote}[2][plain]{%
\@ifnextchar[{\MFL@declare{#1}{#2}}{\MFL@declare{#1}{#2}[arabic]}%
}
\def\MFL@declare#1#2[#3]{%
% \end{macrocode}
% We start from creation a new footnote level:
% \begin{macrocode}
\newfootnote[#1]{#2}%
% \end{macrocode}
% Now we prepare the |\@tempa| command which will create other commands
% at the end of macro. A counter creation command is prepared at first:
% \begin{macrocode}
\edef\@tempa{\noexpand\newcounter{footnote#2}%
% \end{macrocode}
% After that we prepare the redefinition of the enumeration style
% \begin{macrocode}
\noexpand\renewcommand
\expandafter\noexpand\csname thefootnote#2\endcsname{%
\expandafter\noexpand\csname @#3\endcsname
\expandafter\noexpand\csname c@footnote#2\endcsname
}%
% \end{macrocode}
% and specify the per-page resetting if necessary:
% \begin{macrocode}
\ifMFL@perpage \noexpand\MakePerPage{footnote#2}\fi
% \end{macrocode}
% Next we prepare the |\footnote|\meta{suffix} command:
% \begin{macrocode}
\noexpand\newcommand
\expandafter\noexpand\csname footnote#2\endcsname{%
\noexpand\MFL@makemark{footnote#2}{\noexpand\stepcounter}{%
\noexpand\@footnotemark
\noexpand\let\noexpand\@tempb\noexpand\@thefnmark
\expandafter\noexpand\csname Footnotetext#2\endcsname{%
\noexpand\@tempb
}%
}%
}%
% \end{macrocode}
% After that we prepare the |\footnotemark|\meta{suffix} command:
% \begin{macrocode}
\noexpand\newcommand
\expandafter\noexpand\csname footnotemark#2\endcsname{%
\noexpand\MFL@makemark{footnote#2}{\noexpand\stepcounter}{%
\noexpand\@footnotemark
}%
}%
% \end{macrocode}
% Then we prepare the |\footnotetext|\meta{suffix} command:
% \begin{macrocode}
\noexpand\newcommand
\expandafter\noexpand\csname footnotetext#2\endcsname{%
\noexpand\MFL@makemark{footnote#2}{\noexpand\@gobble}{%
\noexpand\let\noexpand\@tempb\noexpand\@thefnmark
\expandafter\noexpand\csname Footnotetext#2\endcsname{%
\noexpand\@tempb
}%
}%
}%
% \end{macrocode}
% Finally, we provide suffixed equivalents for |\Footnotemark|
% and |\Footnote| commands:
% \begin{macrocode}
\noexpand\newcommand
\expandafter\noexpand\csname Footnotemark#2\endcsname{%
\noexpand\Footnotemark
}%
\noexpand\newcommand
\expandafter\noexpand\csname Footnote#2\endcsname[1]{%
\noexpand\Footnotemark{####1}%
\expandafter\noexpand\csname Footnotetext#2\endcsname{####1}%
}%
}%
% \end{macrocode}
% And now all prepared commands are created:
% \begin{macrocode}
\@tempa
}
\@onlypreamble\DeclareNewFootnote
\@onlypreamble\MFL@declare
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@start}
% This command executes the |\MFL@start|\meta{suffix} command.
% It works at the preamble of the document only once for every
% additional footnote level.
% \begin{macrocode}
\def\MFL@start#1{\csname MFL@start#1\endcsname}
\@onlypreamble\MFL@start
% \end{macrocode}
% \end{macro}
%
% \subsection{The Basic Implementation Part}
%
% Now we have to build into \LaTeXe{} the support for additional
% footnote levels. There are a number of points where the modifications
% should be done. We do all real modifications at the beginning of the
% document. Here we prepare macros needed.
%
% \subsubsection{Modifications of Output Routine}
%
% \begin{macro}{\MFL@joinnotes}
% First point of modifications is the output routine. We choose the
% strategy of joining of the additional footnotes with |\footins|
% at the points where it is really needed. The procedure
% |\MFL@joinnotes| implements this job. It will be added later to the
% beginning of |\@makecol| and |\@doclearpage| macros.\footnote{The
% version 1.2 of this package added this procedure to the beginning of
% \texttt{\bslash @specialoutput} instead of \texttt{\bslash
% @doclearpage}. It was incorrect because
% the special output routine is often called to add the next float to
% the output page without ejecting it. As a result the additional
% footnotes disappeared before floats. Thanks to Fran\c cois Patte who
% found this bug.}
%
% Since version 1.5, the |\MFL@joinnotes| has a parameter~---
% a command the joining procedure is called before. We add a protection
% from double attempt for joining and restore the |\footnoterule| after
% execution of the parameter command. The |MFL@joined| conditional command
% is used for this purpose. Another improvement is concerned with the
% footnote rule customization procedure introduced. We now manage
% the footnote rule to be inserted before levels using the priorities.
% The default priority for the standard |\footnoterule| is defined
% with the |\footnoterulepriority| command.
% \begin{macrocode}
\newcommand{\footnoterulepriority}{1}
\newif\ifMFL@joined \MFL@joinedfalse
\def\MFL@joinnotes#1{%
\ifMFL@joined #1%
\else
\let\MFL@savedrule \footnoterule
% \end{macrocode}
% After saving a footnote rule we test the standard footnote insert,
% and prepare the current footnote rule for additional levels.
% \begin{macrocode}
\let\MFL@currule \defaultfootnoterule
\ifvoid \footins
\let\MFL@curpriority \footnoterulepriority
\else
\let\MFL@curpriority \m@ne
\fi
% \end{macrocode}
% Now we join inserts.
% \begin{macrocode}
\let\MFL@elt\@elt
\let\@elt\MFL@join \MFL@list
\let\@elt\MFL@elt
% \end{macrocode}
% And finally, we process the parameter command and restore the |\footnoterule|.
% \begin{macrocode}
\MFL@joinedtrue #1\MFL@joinedfalse
\let\footnoterule \MFL@savedrule
\fi
}
% \end{macrocode}
% The insert joining procedure simply calls the numbered join command
% linked with the insert.
% \begin{macrocode}
\def\MFL@join#1#2{\csname MFL@join\number #2\endcsname{#1}{#2}}
% \end{macrocode}
% The last one calls the |\MFL@joinrule| command with 5 parameters:
% \begin{quote}
% |\MFL@joinrule|\marg{priority}\marg{rule}\marg{action}\marg{style}\marg{register}
% \end{quote}
% First we select the rule comparing the priority of current rule and
% the new one.
% \begin{macrocode}
\def\MFL@joinrule#1#2#3#4#5{%
\ifnum #1<\MFL@curpriority \else
\let\MFL@currule#2%
\def\MFL@curpriority{#1}%
\fi
\ifvoid#5\else
% \end{macrocode}
% Well. The current insert is nonempty. At first, we calculate the skip
% of insert. Within |multicols| environment it has the size multiplied
% in |\col@number| times matching to its natural size. Therefore, we
% have to divide it by |\col@number| in such a case.
% \begin{macrocode}
\@tempskipa\skip#5%
\MFL@ifmcol{\divide\@tempskipa\col@number}{}%
\edef\MFL@skip{\vskip\the\@tempskipa\relax}%
% \end{macrocode}
% Now we process the current insert by the style processing driver
% \begin{macrocode}
\csname MFL@process#4\endcsname #5%
% \end{macrocode}
% and finally we join it with |\footins| insert and decrease the
% current priority to |-1|.
% \begin{macrocode}
\ifvoid\footins
\let\footnoterule\MFL@currule
\setbox\footins\vbox{#3\unvbox#5}%
\else
\setbox\footins\vbox{%
\unvbox\footins\MFL@skip\MFL@currule#3\unvbox#5%
}%
\fi
\let\MFL@curpriority \m@ne
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@reinsout}
% When the special output is called to process float insertion, all
% accumulated footnotes should be reinserted after the output box.
% This job carries out |\@reinserts| command. We will add to it
% the reinsertion of all additional footnotes with the help of
% |\MFL@reinsout| macro. Note that |\@reinserts| command is called at
% two points: when the float is the marginal note
% (|\count\@currbox|~=~0) or when it is the real float. At the second
% case we must take into account the height of all additional footnotes
% by adding it to the |\@pageht| value.
% \begin{macrocode}
\def\MFL@reinsout#1#2{\ifvoid#2\else
\ifnum\count\@currbox>\z@
\advance\@pageht \ht#2%
\advance\@pageht \skip#2%
\advance\@pageht \dp#2%
\fi
\insert#2{\unvbox#2}%
\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Minipages Support}
%
% \begin{macro}{\MFL@reinsert}
% The command reinserts all additional footins by adding if\/
% necessary the empty insertion (such a way is used in |multicol|).
% It is used in |minipage| and |multicols| environments.
% The point of using it at a minipage is the beginning of the minipage.
% Using this command we release the additional footnote boxes to
% accumulate footnotes inside the minipage.
% \begin{macrocode}
\def\MFL@reinsert{{\let\@elt\MFL@reins \MFL@list}}
\def\MFL@reins#1#2{\ifvoid#2\else\insert#2{}\fi}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@mpinsert}
% Here we define the minipage insertion command which manually adds
% vbox to the insertion box. The last footnote within minipage can
% split. So, we specially enclose it into vbox and unvbox the
% previous last footnote.
% \begin{macrocode}
\long\def\MFL@mpinsert#1#2{%
\global\setbox#1\vbox{%
\unvbox#1\setbox\@tempboxa\lastbox
\ifvbox\@tempboxa \unvbox\@tempboxa \fi
\vbox{#2}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@mpreinsert}
% This macro is useful when we really insert footnotes at the end of the
% minipage. We suppress splitting of all minipage insertions except
% the last one. To do this we extract the last box from the insertion
% box, then put another footnotes into the insert enclosing them into
% vbox, and then put the last unvboxed footnote.
% \begin{macrocode}
\def\MFL@mpreinsert#1#2{%
\ifvoid#2\else
\setbox\@tempboxa\vbox{\unvbox#2\global\setbox#2\lastbox}%
\setbox\z@\box#2%
\ifdim\ht\@tempboxa>\z@ \MFL@realinsert#2{\box\@tempboxa}\fi
\MFL@realinsert#2{\unvbox\z@}%
\fi
}
% \end{macrocode}
% Then we define two hooks which will be added to the beginning and to
% the end of a minipage. We do them in not inner mode only (for
% the first level minipages).
% \end{macro}
%
% \begin{macro}{\MFL@minipage}
% We release all box registers of the additional inserts at the
% beginning of\/ minipage to use
% them inside the minipage to accumulate inner inserts.
% \begin{macrocode}
\def\MFL@minipage{%
\ifinner\else
\MFL@reinsert \let\MFL@insert\MFL@mpinsert
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@endminipage}
% We simply reinsert all footnotes at the end of the first level
% minipage.
% \begin{macrocode}
\def\MFL@endminipage{%
\ifinner\else
{\let\@elt\MFL@mpreinsert \MFL@list}%
\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Multicol Package Support}
%
% \begin{macro}{\MFL@mult}
% The command modifies parameters of the insert register.
% It is useful in the scope of |multicol| package only.
% \begin{macrocode}
\def\MFL@mult#1#2{%
\multiply\count#2\col@number
\multiply\skip#2\col@number
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MFL@ifmcol}
% The next macro tests the multicolumn mode. There are two
% conditions which have to be satisfied if we are in the multicolumn
% mode: the value of |\col@number| should be greater then 1 and the
% value of |\footins| count should be at least 2000.
% \begin{macrocode}
\def\MFL@ifmcol#1#2{\@tempswafalse
\ifnum\col@number>\@ne
\ifnum\count\footins>1999 \@tempswatrue \fi
\fi
\if@tempswa #1\else #2\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsection{What Do We Do at the Beginning of Document?}
%
% \begin{macrocode}
\AtBeginDocument{%
% \end{macrocode}
% Firstly, we process starting commands for every level
% \begin{macrocode}
{\let\@elt\MFL@start \MFL@list}
% \end{macrocode}
% Then we define the |\defaultfootnoterule| to provide compatibility
% with \textbf{footmisc}. We set it equal to |\pagefootnoterule|
% or |\footnoterule|.
% \begin{macrocode}
\@ifundefined{defaultfootnoterule}{%
\@ifundefined{pagefootnoterule}%
{\let\defaultfootnoterule\footnoterule}%
{\let\defaultfootnoterule\pagefootnoterule}%
}{}%
% \end{macrocode}
% Then we modify |\@doclearpage| and |\@makecol| commands by added
% the joining algorithm at their beginning.
% \begin{macrocode}
\let\MFL@doclearpage\@doclearpage
\def\@doclearpage{\MFL@joinnotes\MFL@doclearpage}
\let\MFL@makecol\@makecol
\def\@makecol{\MFL@joinnotes\MFL@makecol}
% \end{macrocode}
% Then we modify |\@reinserts| command of the output routine to
% process reinsertion of all additional footnotes.
% \begin{macrocode}
\g@addto@macro\@reinserts{%
\let\MFL@elt\@elt
\let\@elt\MFL@reinsout \MFL@list
\let\@elt\MFL@elt
}
% \end{macrocode}
% Then we execute |\MFL@floathook| and add it into |\@floatplacement|
% command which is called when the column mode is
% changed. One important note: in the multicolumn mode of |multicol|
% package the width of footnotes is unchanged. So, we test
% this case by the command |\MFL@ifmcol|.
% \begin{macrocode}
\MFL@floathook
\g@addto@macro\@floatplacement{\MFL@ifmcol{}{\MFL@floathook}}
% \end{macrocode}
%
% The next is the |minipage| environment. We modify |\@iiiminipage| and
% |\endminipage| adding to them hooks describe earlier.
% \begin{macrocode}
\let\MFL@iminipage\@iiiminipage
\def\@iiiminipage{\MFL@minipage\MFL@iminipage}
\g@addto@macro\endminipage\MFL@endminipage
% \end{macrocode}
%
% Finally, we do some tricks to provide the compatibility with
% |multicol| package. If this package is loaded, the command
% |\multi@column@out| should be defined
% \begin{macrocode}
\@ifundefined{multi@column@out}
% \end{macrocode}
% If it is undefined, the |multicol| specific commands are not useful.
% So, we delete |\MFL@mult| command and modify |\MFL@ifmcol| command to
% choose the second case every time.
% \begin{macrocode}
{\@onlypreamble\MFL@mult \let\MFL@ifmcol\@secondoftwo}
% \end{macrocode}
% If |multicol| package presents, we add the joining algorithm to the
% beginning of |\multi@column@out| command
% \begin{macrocode}
{\let\MFL@mcolout\multi@column@out
\def\multi@column@out{\MFL@joinnotes\MFL@mcolout}
% \end{macrocode}
% and add the multiplication of additional footins parameters
% by the number of columns to the end of |\init@mult@footins| command.
% We can't do this globally. So, we save the previous value of |\@elt|
% command and then restore it after the calculation.
% We also modify |\reinsert@footnotes| command.
% \begin{macrocode}
\g@addto@macro\init@mult@footins{%
\let\MFL@elt\@elt
\let\@elt\MFL@mult \MFL@list
\let\@elt\MFL@elt
}
\g@addto@macro\reinsert@footnotes{\MFL@reinsert}
}
}
%</package>
% \end{macrocode}
\endinput
|