-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
latex-lab-footnotes.dtx
2537 lines (2479 loc) · 80.1 KB
/
latex-lab-footnotes.dtx
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
% \iffalse meta-comment
%
%% File: latex-lab-footnotes.dtx
% Copyright (C) 2022 The LaTeX Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
%
% The development version of the bundle can be found below
%
% https://github.com/latex3/latex2e/required/latex-lab
%
% for those people who are interested or want to report an issue.
%
%<*driver>
\documentclass{l3doc}
\EnableCrossrefs
\CodelineIndex
\begin{document}
\DocInput{latex-lab-footnotes.dtx}
\end{document}
%</driver>
%
% \fi
%
%
% \title{The \texttt{latex-lab-footnotes} code\thanks{}}
% \author{Frank Mittelbach, \LaTeX{} Project}
%
% \maketitle
%
% \newcommand\fmi[1]{\begin{quote} TODO: \itshape #1\end{quote}}
% \newcommand\NEW[1]{\marginpar{\mbox{}\hfill\fbox{New: #1}}}
% \providecommand\class[1]{\texttt{#1.cls}}
% \providecommand\pkg[1]{\texttt{#1}}
% \providecommand\hook[1]{\texttt{#1}}
%
% \begin{abstract}
% \emph{to be written}
% \end{abstract}
%
% \tableofcontents
%
%
% \section{Introduction}
%
% This code reimplements the footnote interfaces for \LaTeX{}
% offering configurable methods for layout and functionality
% adjustments that avoid overwriting each other when used in
% classes as well as in packages (as far as possible --- obviously
% some adjustments are mutually exclusive). This is achieved by
% providing a larger number of hooks (for areas where different
% packages/classes can easily coexist with their adjustments) and a
% number of configuration points to which only one class or package
% can write to successfully (in case of multiple changes the
% last one wins). The latter are for special functionality, e.g.,
% if footnote text is typeset as a single paragraph, it can't be configured
% the same time to be typeset vertically with one footnote below
% each other.
%
% The interfaces are set up to support tagged PDF, but in order
% for this to work, all packages altering the footnote setup should
% use the interfaces provided here and not do it through the
% legacy methods (though there is some support for the latter as
% well, but if will not work in a cases).
%
% \subsection{Configuration methods}
%
% Historically, the footnote setup in \LaTeX{} was done by
% providing definitions for \cs{@makefnmark} (format the footnote
% mark in running text and in front of the footnote text) and
% \cs{@makefntext} (formatting the footnote text and placing a mark
% in front of it).
%
% There was a default definition for \cs{@makefnmark} in the format
% that was used by most document classes,
% but \cs{@makefntext} had to be defined in the class itself because
% the format didn't provide a default. As a result you will find
% definitions for the latter in all document classes and definitions
% for \cs{@makefnmark} only in very few.
%
% Furthermore, to enable special footnote layouts or provide
% additional functionality a few packages (and a few classes)
% overwrote other internal commands of \LaTeX's footnote
% mechanism. The commands affected in this way are mainly
% \cs{@footnotemark} and \cs{@footnotetext}. These overwrites could
% not be used in combination, so either the packages/classes had to
% be aware of being loaded together (which they sometimes did or
% tried to) or they would fail by overwriting each other
% unconditionally.
%
% The present rewrite is an attempt to improve this situation, but
% of course, it will only work if all packages/classes make use of
% the new interfaces. Fortunately, the number of problematical
% packages altering these internal commands are fairly small so
% arranging for updates is a realistic goal --- to achieve properly
% tagged PDF it is a requirement.
%
%
%
% \section{Hooks and configuration points}
%
% Note: the configuration points do not have an interface mechanism
% yet and all their names are temporary right now.
% Also note that configuration points are of interest only to very
% few specialized packages, mainly \pkg{footmisc}, and packages
% providing similar functionality---the current documentation is
% therefore fairly sketchy.
%
% In contrast the hooks are of interest to many classes to provide
% their layout alterations in a way that it works smoothly with
% other packages handling aspects of footnote formatting.
%
%
% \subsection{Formatting the mark in the main text}
%
% This implements formatting the mark\footnote{Like this one.} and
% its relation to surrounding text, e.g., if several marks appear
% in the same place, etc.
%
%
% \subsubsection{Configuration points}
%
% None: everything is implemented through a single definition for
% \cs{@footnotemark} that offers a number of hooks that can be used
% by packages to implement handling of multiple marks and the
% formatting of marks.
%
%
% \subsubsection{Hooks}
%
% The hooks to customize the marks in the text are the following:
% \begin{description}
% \item[\hook{fnmark/before}]
%
% Executed at the very beginning of \cs{footnotemark}. Currently
% there are two packages (\pkg{bibarts} and \pkg{chextras}) that
% prepend material at this point (not necessarily correctly, e.g.,
% they do not all check that they are in horizontal mode).
%
% This hook is paired with hook \hook{fnmark/after}.
%
% \item[\hook{fnmark}]
%
% Executed in horizontal mode and after the current space factor
% has been saved away for reuse. This is where currently code for multiple
% marks does its preparation (as done by \pkg{footmisc} and
% others).
%
% The hook is only executed in hmode, i.e., not if the mark is
% generated in math --- maybe that means the multiple handling
% should happen later?
%
% After the hook \cs{nobreak} is executed, so any
% ``material'' added in the hook is tied to the following mark
% unless it contains its own permissible penalty.
%
% \item[\hook{fnmark/begin}]
%
% This hook is executed directly in front of the typeset mark.
% This is the place where \pkg{hyperref} would have added
% part of its code, i.e., after the \cs{nobreak} mentioned above.
% With the integration of hyperlinks in the tagging code
% this hook may not be necessary at all.
%
% \item[\hook{fnmark/end}]
%
% This hook is executed directly after the typeset mark. It is
% used by \pkg{memhfixc}, \pkg{scrlttr2}, and
% \pkg{footmisc}. Used, for example, to implement support for
% multiple marks in succession.
%
% It is \emph{not} a reversed hook.
%
%
% \item[\hook{fnmark/after}]
%
% This hook is executed at the very end of the \cs{footnotemark} command.
%
% It is a reversed hook to pair with \hook{fnmark/before}
% \end{description}
%
%
%
%
% \subsubsection{Additional configuration possibilities}
%
% The actual formatting is done through \cs{@makefnmark} --- no
% special customization support for now.
%
%
%
% \subsection{Formatting the footnote text}
%
% This implements the formatting of the footnote text the way it
% appears at the bottom of the page (default case), or possibly
% elsewhere, e.g. in the margin.
%
% \subsubsection{Configuration points}
%
% To cater for different layout configurations there are four
% configuration points which can be set only by one package or
% class, if two packages/classes set them they are mutually
% incompatible.
% These are:
% \begin{description}
% \item[\cs{@footnotetext@cfgpoint} (1 argument)]
%
% This receives all material that is to be processed (or stored)
% including color protection code and what have you. The default
% definition is to run \cs{insert}\cs{footins}.
%
% \item[\cs{@footnotetext@cfgpointii} (1 argument)]
%
% The default definition runs \cs{@makefntext} which contains
% various hooks for customization. For most scenarios this is
% sufficient. However, when running all footnotes as a single
% paragraph at the bottom, then each footnote needs to be
% prepared prior to storing in the insert and this configuration
% point allows running extra code to do that.
%
% \item[\cs{@footnotetext@cfgpointiii} (no argument)]
%
% By default this configuration point adds a strut to the
% footnote material so that consecutive footnotes are properly
% spaced vertically. In some use cases this is not appropriate
% (e.g., when running all footnotes as a single paragraph) and so
% this configuration point can cancel the action or do something
% else instead.
%
% The configuration point is executed near the start of the
% argument for the configuration point
% \cs{@footnotetext@cfgpointii}.
%
% \item[\cs{@footnotetext@cfgpointiv} (no argument)]
%
% This configuration point is executed at the very end of the
% argument passed to \cs{@footnotetext@cfgpointii}.
% By default it adds a final strut as long as we are still in
% horizontal mode (i.e., processing the footnote text paragraph.
% When running several footnotes in one paragraph some additional
% material (some horizontal glue) needs adding at this point.
%
% \end{description}
% The configuration point \cs{@footnotetext@cfgpointii} runs
% \cs{@makefntext} and this command contains two further
% configuration points (and a few hooks):
% \begin{description}
% \item[\cs{@makefntext@cfgpoint} (1 argument)]
%
% This configuration point receives the material to typeset the
% footnote mark. By default, all it does is running \cs{indent}
% to get a paragraph indentation (if one is set up---in most
% layouts it is 0~points) and then typesets the mark, but in
% some designs it executes more elaborate code.
%
% If tagging is produced this configuration point is also
% responsible for surrounding the mark with the appropriate tags
% marking the mark as an Lbl. It does this using the command
% \cs{tag@FENoteLbl}.
%
% \item[\cs{@makefntext@cfgpointii} (1 argument)]
%
% This configuration point manages the formatting of the footnote
% text once the mark has been typeset.
%
% If tagging is produced this configuration point is also
% responsible for surrounding the mark with the appropriate tags
% marking the mark as an MC of type FENote. It does this using
% the command \cs{tag@FENotetext}.
%
% \end{description}
%
%
% The above configuration points are sufficient to implement all
% commonly used footnote layouts assuming L-R typesetting. For R-L
% typesetting they or may or may not need some extension (though
% that is not clear right now).
%
%
%
% \subsubsection{Hooks}
%
% \begin{description}
% \item[\hook{fntext/before}]
%
% Executed at the very beginning of \cs{footnotetext}. Currently
% there is on package (\pkg{linguex}) that
% prepends material at this point.
%
% This hook is paired with hook \hook{fnmark/after}.
%
% \item[\hook{fntext}]
%
% Executed at the beginning of the material passed to the first
% configuration point. Typically used to set any baseline
% stretch for the footnote text, e.g., by \pkg{setspace},
% \pkg{footmisc}, \class{uathesis} and others. Could be done in a
% later hook but is a bit more efficient here.
%
% After the hook has run, the font is established, i.e., it can't
% be used to set a different font size.
%
% \item[\hook{fntext/para}]
%
% After the font is set default paragraph parameters are set up
% including \cs{interlinepenalty}, \cs{hsize}, \cs{parindent} and
% a number of others, as some of them depend on the font
% size. Then the \hook{fntext/para} is run. If one wants to
% change the font size, it is probably necessary to reset these
% other parameters too, e.g., \cs{parindent}, which can be done
% here.
%
% The configuration point \cs{@footnotetext@cfgpointii} normally
% runs the command \cs{@makefntext} or some code that eventually
% runs this command, and this then produces the footnote mark (in
% front of the footnote text) and the formatted footnote text. In
% front of both the mark and the footnote text some classes have
% placed paragraph parameter adjustments in their redefinition of
% \cs{@makefntext}. However, there is no need to place it there
% it could equally well go into the \hook{fntext/para} hook. We
% therefore do not provide another hook at this point.
%
% \item[\hook{fntext/begin} \& \hook{fntext/end}]
%
% The footnote text itself is surrounded by the hooks
% \hook{fntext/begin} and \hook{fntext/end}. The two hooks are
% not paired as they are typically used independently.
%
% \item[\hook{fntext/after}]
%
% At the very end of \cs{footnotetext} we execute the hook
% \hook{fntext/after} which is a reversed hook paired with
% \hook{fntext/before}. Some packages, e.g., \pkg{linguex}, have
% code in that position.
%
% \end{description}
%
%
%
%
% \subsubsection{Additional configuration possibilities}
%
% The formatting of the footnote mark in front of the footnote
% text is influenced by the setting of the dimen parameter
% \cs{footnotemargin}. By default its value is 1.8em in the current
% text font (or \texttt{-}\cs{maxdimen} when the para option is
% chosen). The following rules apply:
% \begin{itemize}
% \item
%
% If it has the value \texttt{-}\cs{maxdimen} then the mark is
% generated by \cs{@makefnmark}.
%
% \item
%
% Otherwise, if the value is
% negative then the mark is placed into an \cs{llap} left aligned
% in a box of size \texttt{-}\cs{footnotemargin}.
%
% \item
%
% If the value is zero an \cs{llap} is used without an inner box.
%
% \item
%
% If the value is greater zero (but less than \cs{maxdimen}) the
% mark is placed right aligned into a box of size
% \cs{footnotemargin}.
%
% \item
%
% The value \cs{maxdimen} is used as a marker to indicate that
% no value was given and that the default should be used,
% i.e. 1.8em or \texttt{-}\cs{maxdimen} depending on the chosen
% option.
% \end{itemize}
%
%
% \section{Tagging and hyperlinking support}
%
% Footnotes consist of a \emph{footnotemark} (short: mark) that is typically placed in the text
% as a superscript number like this\footnotemark[1], and a \emph{footnotetext}
% (short: note) that is placed at the bottom of the page.
% The \emph{footnotetext} normally repeats at the begin the mark as a visual clue.
%
% Tagging (and hyperlinking) has to connect the mark with the note.
% For the tagging code, we assume that every mark has exactly one associated note,
% and that every note is associated to at least one mark
% and can have more associated marks.
%
% The mark doesn't need to be visible, e.g. the typesetted
% mark\textsuperscript{1--3} denotes three marks, where the second is invisible.
% Tagging should produce here probably three \texttt{Lbl} structures
% (one without content), and an artifact for the range marker.
% If such a range is used, links can only point to the notes 1 and 3 and
% one has to suppress the linking for the second mark.
% This means that links and tagging are also related
% to the actual formatting of the footnote mark.
% In the following this problem is mostly ignored for now, but
% should not be forgotten and handled later.
%
% \subsection{Technical details for the tagging}
%
% The \emph{footnotemark} should create a \texttt{/Lbl} structure\footnote{to make it easier
% to identify the role we use \texttt{/footnotemark} which we rolemap to \texttt{/Lbl}} that should contain a \texttt{/Ref} entry pointing
% to the structure of the \emph{footnotetext}.
%
% The \emph{footnotetext} should create a \texttt{/FENote}\footnote{We tag it as \texttt{/footnote} and role map it.}
% structure with a \texttt{/Ref}
% entry pointing to the structures of \emph{all} marks related to the note.
% The mark at the begin of the
% note is in a \texttt{/Lbl}\footnote{We tag it as \texttt{/footnotelabel}.}
% structure but has to fulfil no special requirements.
%
% Structure objects and the underlying properties used by the tagging
% code are initialized when the structure is opened. This means that one can not
% directly add data to a future structure
% but as structure objects are written at the end of the document it is
% possible to update \texttt{/Ref} entries in an end document hook.
%
%
% So tagging has to solve two problems:
% \begin{itemize}
% \item the mark and the footnote text must be surrounded by the correct structure
% and marked content commands. This is not trivial
% as there are various layouts (bottom, marginpar, minipage) and the tagging
% from the automatic paratagging must be taken into account if one want to avoid
% faulty nesting.
%
% \item It must detect which marks are related to which notes
% so that it can setup the \texttt{/Ref} cross-references.
% \end{itemize}
%
%
% \subsection{Requirements for links}
%
% Links should go from the mark to the note. Sometimes it has been requested
% that links go back too, but as there
% can be more than one mark connected to a note it is not clear how to decide to which mark it should go.
% Using the keys from the PDF viewer to go back is normally better.
%
% Links are closely related to the references stored in the \texttt{/Ref}
% entry of a mark and so are handled in the code together with them.
% But there are subtle technical differences to take care of
% as links and destinations are whatsits and so must be created at the correct time.
%
% It should be possible to suppress the links both globally and locally.\footnote{
% Currently hyperref only offers the option to suppress the
% footnote links globally
% with the option \texttt{hyperfootnotes=false}. To suppress them locally
% only the \texttt{NoHyper} environment is provided.}
%
%
% \subsection{The algorithmus to connect marks and notes}
%
%
% The connection is made by comparing the value of \cs{@thefnmark}.
%
% The standard mark commands (\cs{footnotemark} and \cs{footnote})
% store the current value of \cs{@thefnmark}
% with their own structure number as a key in a property.
%
% A following \cs{footnotetext} compares its own \cs{@thefnmark} with the values in
% the prop. If there is a match it stores the structure numbers and removes the entries
% from the properties (so in a normal document the property will never contain more than
% a few entries).
%
% This works well as long as the \cs{footnotemark} commands are issued before the \cs{footnotetext} and
% as long as nothing unusual is done to \cs{@thefnmark}.
% It also works if a document uses more than one footnote series as long as they have distinct numbering
% systems, but in case a distinction is needed it is possible to define
% a new data structure and to switch locally to use this
% container. The following three commands are used for this.
%
% The default property uses the name \texttt{default}
%
% \begin{function}{\fnote_new:nn}
% \begin{syntax}
% \cs{fnote_new:nn}\Arg{name}\Arg{key/value option}
% \end{syntax}
%
% This commands set up the needed data structure. Currently this only
% consists of a property which is used to store and manage the mark values.
% There are no options yet.
% \end{function}
%
% \begin{function}{\fnote_mark_gput:nn,\fnote_mark_gput:no,\fnote_mark_gput:oo}
% \begin{syntax}
% \cs{fnote_mark_gput:nn}\Arg{mark}\Arg{footnote type name}
% \end{syntax}
% This command stores the current structure number as key and the \meta{mark} as
% value in the property associated with the \meta{footnote type name}
% \end{function}
%
% \begin{function}{\fnote_mark_gpop:nnN}
% \begin{syntax}
% \cs{fnote_mark_gpop:nnN}\Arg{mark}\Arg{footnote type name}\meta{sequence}
% \end{syntax}
% This command stores the keys/structure numbers whose value are \meta{mark} in the
% property associated with \meta{footnote type name} in the \meta{sequence}
% and then remove them from the property. The content of the sequence can then be
% used to create link targets and references.
% \end{function}
%
%
% \subsubsection{\cs{footref}}
%
% \cs{footref} use internally the same command to set the mark as \cs{footnotemark}, it only
% defines \cs{@thefnmark} differently. This \cs{@thefnmark} is not suitable for the method described
% above, as it contains a reference command it can't be used to match a note, also \cs{footref} can
% be used after the note has already been set. \cs{footref} disables therefore the automatic detection.
%
% Instead the \cs{label} command is (currently with the help of a hook from the \texttt{nameref} package)
% extended in the \cs{footnotetext} command to also store the structure number and \cs{footref} retrieves this
% number to setup the reference and the link.
%
% The structure related to the \cs{footref} is added to the end of the \texttt{/Ref} array of the note and so the
% \texttt{/Ref} array doesn't necessarly reflect the order of the marks in the document. It would probably
% be possible to change this, but it is not clear if it actually matters and so it worth the additional coding
% and processing.
%
% \subsubsection{\cs{footnotemark} after \cs{footnotetext}}
%
% The automatic detection doesn't work if a \cs{footnotemark} is issued after
% the \cs{footnotetext} it refers to. There will be no error, but neither the link nor
% the \texttt{/Ref} will connect both.
%
% The simple way to handle this is to use a label and \cs{footref}:
%
% \begin{verbatim}
% \footnotetext{\label{fn:a}text} ... \footref{fn:a}
% \end{verbatim}
%
% An alternative would be to extend the syntax of \cs{footnotemark} and
% \cs{footnotetext} to allow to add a label which can then be used.
% For example
%
% \begin{verbatim}
% \footnotetext[label=fn:a]{text} ... \footnotemark[label=fn:a]
% \end{verbatim}
%
% As both have already an optional argument, that requires the optional argument extension.
%
%
% \subsection{Links}
%
% The structure numbers detected for the \texttt{/Ref} are also used for links:
% even if tagging is not activated the tagging commands are defined through
% the \pkg{tagpdf-base} package
% and the structure commands increase the structure counter and this info can be used.
%
% A \cs{footnotetext} creates a bunch of destinations (in most cases this sums up to
% two destinations): one for every structure number in the \texttt{/Ref} (used as target
% by the mark commands) and one for the structure number of the footnotetest itself
% (used as target by \cs{footref}s commands).
%
% \subsection{Implementation details}
%
% \subsection{Handling the mark}
%
% The mark in the text is handled by redefining the kernel configuration point
% \cs{@kernel@process@makefnmark} to \cs{tag@FEMark}.
% It takes one argument, \cs{@makefnmark}, the command which formats the
% mark, and surrounds it by link and tagging commands.
% At the point where \cs{@kernel@process@makefnmark} is issued \cs{@thefnmark} has already been
% defined and can be used to setup the reference detections.
%
%
% \subsection{Handling the footnotetext}
%
% The main part is done by redefining \cs{@kernel@process@footnotetext}. This configuration point takes two arguments, \cs{@footnotetext@cfgpoint} (by default \verb+\insert\footins+) and as second argument lots of code related to typesetting the notemark and the footnote text with the actual content of the footnote text somewhere in the middle.
%
% The redefinition of \cs{@kernel@process@footnotetext} surrounds the content with the structure command
% and tries to detect to which mark the note is related.
%
% The actual typesetting of the note text is done
% by \cs{@makefntext}/\cs{fnote_makefntext:n}. In the new implementation this contains two configuration
% points, \cs{@makefntext@cfgpoint} and \cs{@makefntext@cfgpointii}. These are redefined to add the tagging commands around note mark and note text.
%
% \subsection{Footnotes in minipages}
%
% In minipages the \cs{footnote} command uses a special marker
% (small italic letters by default) and puts the
% footnote text at the bottom of the box. The \cs{footnotemark}
% command uses the standard footnote counter and marker (and so typically
% creates a superscript number).
% It is meant to be used with a \cs{footnotetext} \emph{outside}
% the minipage to create a footnote mark which refers to a footnote text
% at the bottom of the page.
% This means to repeat a footnote marker in a minipage you should use the \cs{footref} command.
%
% Tagging works quite similar to normal footnotes if the new definition is used
% and if the minipage code is changed to use the new configuration point.
% The main problem here is currently the tagging of the minipage itself.
%
% \section{TODOs}
%
% \begin{itemize}
%
% \item tagging destroys footnotes directly following the text with pdflatex.
%
% \item there is a dependency on nameref as it provides the hook in \cs{label}
% used by the \cs{footref} code.
%
% \item there is a dependency to etoolbox as we patch \cs{\@iiiminipage}
%
% \item Special formatting of footnote marks in the text, e.g. if ranges or commas are
% used require special care as they should normally mark up such text as artifacts and
% perhaps have to insert empty structures to represent an invisible mark. This must be coordinated
% with the relevant packages and classes.
%
% \item manyfoot doesn't work correctly and must be analyzed.
%
% \item Check if additional kernel configuration points are needed/possible
% to avoid the redefinitions of \cs{@makefntext@cfgpoint} and \cs{@makefntext@cfgpointii}.
%
% \item \pkg{memoir} is not supported at all and errors when the code tries to patch
% \cs{@makefntext}.
% \end{itemize}
%
% \emph{To be documented}
%
%
%
%
% \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
%
%
% \section{The Implementation}
%
% All this is very rough and misses a lot of documentation.
%
% \begin{macrocode}
%<*kernel>
%<@@=fnote>
% \end{macrocode}
%
% \subsection{File declaration}
% \begin{macrocode}
\ProvidesFile{latex-lab-footnotes.ltx}
[2022-03-10 v0.6a changes to the footnote interfaces]
% \end{macrocode}
%
% \subsection{code not fully handled yet}
% \begin{macrocode}
%
% latex.ltx
% not looked at yet
% \@mpfootnotetext is probably no longer needed, or only to support other
% classes and package. See below about the minipage code.
%
% \long\def\@mpfootnotetext#1{%
% \global\setbox\@mpfootins\vbox{%
% \unvbox\@mpfootins
% \reset@font\footnotesize
% \hsize\columnwidth
% \@parboxrestore
% \def\@currentcounter{mpfootnote}%
% \protected@edef\@currentlabel
% {\csname p@mpfootnote\endcsname\@thefnmark}%
% \color@begingroup
% \@makefntext{%
% \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
% \par
% \color@endgroup}}
% ========
% used by the minipage footnote code.
%
% \def\@mpfn{footnote}
% \def\thempfn{\thefootnote}
% =========
% this perhaps need some configuration options.
%
%\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\@thefnmark}}}
%
% =========
%% alterations not covered:
%
% ./arabtex/afoot.sty --- too different (and probably too old)
%
% =====
% alterations of footnotetext not covered:
%
% ./revtex4-1/revtex4-1.cls ./revtex/ltxutil.sty ./revtex/revtex4-2.cls ... (need analysis)
% ./bigfoot/bigfoot.sty
%
% memoir needs checking too
%
% =====
%
% use of kerns to mark h-mode positions (unit sp)
%
% 1 = CJK
% 2 = CJK
% 3 = multiple footnotes (footmisc, koma, eledmac, tufte, memoir,
% parnotes, sidenotes)
% 3 = outer kern in letter spacing (letterspace)
% 3 = beginning of list (examdesign.cls)
% 4 = CJK pigin
% 5 = CJK ruby
% 1-4 = polyglossia for korean
%
% \end{macrocode}
%-------------------------------------
% \begin{macrocode}
\ExplSyntaxOn
% \end{macrocode}
% \subsection{Temporary variables}
% \begin{macrocode}
\prop_new:N \l_@@_tmpa_prop
\tl_new:N \l_@@_tmpa_tl
% \end{macrocode}
% \subsection{Public variables}
%
% A footnote mark will store its structure number (key) and the
% expanded \cs{@thefnmark} in this prop so
% that a following note can retrieve this info
% if needed. It is possible to use more than one footnote series (type)
% if needed (if different footnotes/note use the same
% numbering system).
% If this command is changed an accompanying property must be created
% \begin{NOTE}{UF}
% TODO: interface to create the property.\\
% TODO: check and decide about the name of the tl
% \end{NOTE}
% \begin{macro}{\l_fnote_type_tl}
% \begin{macrocode}
\tl_new:N \l_fnote_type_tl
\tl_set:Nn \l_fnote_type_tl {default}
% \end{macrocode}
% \end{macro}
% It must be possible to suppress the hyperlinking, both locally
% and globally. hyperref's hyperfootnotes option should set the boolean.
% \begin{macro}{\l_fnote_link_bool}
% \begin{macrocode}
\bool_new:N \l_fnote_link_bool
\bool_set_true:N \l_fnote_link_bool
% \end{macrocode}
% \end{macro}
% A hyperlink should have an changeable link type. This can
% be e.g. used to change the color or the border.
% \begin{macro}{\l_fnote_link_type_tl}
% \begin{macrocode}
\tl_new:N \l_fnote_link_type_tl
\tl_set:Nn \l_fnote_link_type_tl {link}
% \end{macrocode}
% \end{macro}
%
% \subsection{Internal variables}
%
% \begin{macro}{\l_@@_linktarget_tl}
% This command stores the name of a linktarget/destination
% when needed
% \begin{macrocode}
\tl_new:N \l_@@_linktarget_tl
% \end{macrocode}
% \end{macro}
% \begin{macro}{\l_@@_currentlabel_tl}
% This command is used to pass a label name around.
% \begin{macrocode}
\tl_new:N \l_@@_currentlabel_tl
% \end{macrocode}
% \end{macro}
% \begin{macro}{\l_@@_currentrefs_seq}
% This sequence stores the list of reference of a note
% \begin{macrocode}
\seq_new:N \l_@@_currentrefs_seq
% \end{macrocode}
% \end{macro}
%
% The connection between the mark(s) in the text and the note
% is either deduced automatically or done through an label.
% The default is automatic, but we must be able to suppress it. For this we use a boolean.
% \begin{macro}{\l_@@_autodetect_bool}
% \begin{macrocode}
\bool_new:N \l_@@_autodetect_bool
\bool_set_true:N \l_@@_autodetect_bool
% \end{macrocode}
% \end{macro}
% This is used to pass the structure number of the note around, e.g.
% to a label inside the note.
% \begin{macrocode}
\tl_new:N \l_@@_currentstruct_tl
\tl_set:Nn \l_@@_currentstruct_tl {1}
% \end{macrocode}
%
%
% \subsection{Variants}
%
% \begin{macrocode}
\cs_generate_variant:Nn \ref_label:nn { Vn }
\cs_generate_variant:Nn \ref_value:nn { Vn }
\cs_generate_variant:Nn \prop_gput:Nnn {cxn}
\cs_generate_variant:Nn \hook_gput_code:nnn{nne}
\cs_generate_variant:Nn \tag_struct_use:n {e}
% \end{macrocode}
%
% \subsection{Updating \cs{@thefnmark}}
% \begin{macro}{\fnote_step_fnmark:nn}
% This command updates \cs{@thefnmark}. The first argument
% is an optional integer expression, the second a counter name.
% If the optional argument is not given it steps the counter.
% \begin{macrocode}
\cs_new_protected:Npn \fnote_step_fnmark:nn #1#2 {
\tl_if_novalue:nTF {#1}
{
\stepcounter {#2}
\protected@xdef \@thefnmark { \use:c { the#2 } }
}
{
\group_begin:
% \end{macrocode}
% Note that this is a local assignment even though \LaTeX{}
% counters are normally globally changed. This is the way it was in
% 2e and so far we haven't changed it. The alternative would be to
% store the current value and restore it after \cs{@thefnmark} is
% altered.
% \begin{macrocode}
\int_set:cn { c@#2 }{ #1 }
\unrestored@protected@xdef \@thefnmark { \use:c { the#2 } }
\group_end:
}
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\fnote_set_fnmark:nn}
% This is similar to the previous command, but it doesn't step the
% counter but use the current value.
% \begin{macrocode}
\cs_new_protected:Npn \fnote_set_fnmark:nn #1#2 {
\tl_if_novalue:nTF {#1}
{
\protected@xdef \@thefnmark { \use:c { the#2 } }
}
{
\group_begin:
\int_set:cn { c@#2 }{ #1 }
\unrestored@protected@xdef \@thefnmark { \use:c { the#2 } }
\group_end:
}
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Hooks}
%
% Hooks in the footnotemark command.
% \begin{macrocode}
\NewMirroredHookPair{fnmark/before}{fnmark/after}
\NewHook{fnmark}
\NewHook{fnmark/begin}
\NewHook{fnmark/end}
% \end{macrocode}
% Hooks in the footnotetext command
% \begin{macrocode}
\NewMirroredHookPair{fntext/before}{fntext/after}
\NewHook{fntext}
\NewHook{fntext/para}
\NewHook{fntext/begin}
\NewHook{fntext/end}
% \end{macrocode}
%
% \subsection{Debugging code}
% the debugging code is just temporary
%
% For now we have debugging turned on by default
% \begin{macrocode}
\bool_new:N \g_fnote_debug_bool
\bool_gset_true:N \g_fnote_debug_bool
% \end{macrocode}
% We log the hooks in the footnote mark command, but only once
% \begin{macrocode}
\cs_new_protected:Npn \@@_debug_footnotemark:
{
\bool_if:NT \g_fnote_debug_bool
{
\LogHook{fnmark/before}
\LogHook{fnmark}
\LogHook{fnmark/begin}
\LogHook{fnmark/end}
\LogHook{fnmark/after}
\cs_gset_eq:NN \@@_debug_footnotemark: \prg_do_nothing:
}
}
% \end{macrocode}
% Similar for the footnotetext
% \begin{macrocode}
\cs_new_protected:Npn \@@_debug_footnotetext:
{
\bool_if:NT \g_fnote_debug_bool
{
\cs_log:N\@footnotetext@cfgpoint
\cs_log:N\@footnotetext@cfgpointii
\cs_log:N\@footnotetext@cfgpointiii
\cs_log:N\@footnotetext@cfgpointiv
\cs_log:N\@makefntext@cfgpoint
\cs_log:N\@makefntext@cfgpointii
\LogHook{fntext/before}
\LogHook{fntext}
\LogHook{fntext/para}
\LogHook{fntext/begin}
\LogHook{fntext/end}
\LogHook{fntext/after}
% \end{macrocode}
% Show the info only once (if at all).
% \begin{macrocode}
\cs_gset_eq:NN \@@_debug_footnotetext: \prg_do_nothing:
}
}
% \end{macrocode}
%
% \subsection{The new \cs{@footnotemark} command}
% \begin{macro}{\fnote_footnotemark:}
% This is the main command which will replace \cs{@footnotemark}.
% \begin{macrocode}
\cs_new_protected:Npn \fnote_footnotemark: {
\@@_debug_footnotemark:
%-------
% bibarts
% chextras --- actually in the wrong place does an \unskip
\UseHook{fnmark/before}
%-------
\leavevmode
\ifhmode
\edef\@x@sf{\the\spacefactor}
%-------
% bxjsja-minimal.def --- what they do could be done at ``bibarts''
% (a bit less efficient)
% memhfixc.sty
% footmisc.sty
\UseHook{fnmark}
%-------
\nobreak
\fi
%-------
% hyperref.sty
\UseHook{fnmark/begin}
%-------
\@kernel@process@makefnmark
\@makefnmark
%-------
% \end{macrocode}
% If a footnote mark is placed by its own then it should finish by
% executing \hook{fnmark/end}, resetting the space factor, and
% finishing with \hook{fnmark/after}. However, in a complete
% footnote these actions have to happen only after we have handled
% the footnote text (e.g., by placing it into an \cs{insert}). In
% such a situation \cs{_@@_footmark_finish:} below does nothing
% and the action is carried out later.
% \begin{macrocode}
\@@_footnotemark_finish:
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_finish:,\@@_footnotemark_finish:}
% \begin{macrocode}
\cs_new_protected:Npn \@@_finish: {
% hyperref.sty
% memhfixc.sty --- could move fnmark/after
% scrlttr2.cls --- could vanish if footmisc uses a hook
% footmisc.sty
\UseHook{fnmark/end}
%-------
\ifhmode
\spacefactor \@x@sf \relax
\fi
%
%-------
\UseHook{fnmark/after}
%-------
}
\cs_new_eq:NN \@@_footnotemark_finish: \@@_finish:
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@kernel@process@makefnmark}
% Not a public config point but the kernel hook to add tagging
% \begin{macrocode}
\def \@kernel@process@makefnmark { }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@footnotemark}
% At last provide the name \LaTeXe{} is used to.
% \begin{macrocode}
\cs_set_eq:NN \@footnotemark \fnote_footnotemark:
% \end{macrocode}
% \end{macro}
%
%