Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-footnotes.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-footnotes.dtx
4 % Copyright (C) 2022-2026 The LaTeX Project
5 %
6 % It may be distributed and/or modified under the conditions of the
7 % LaTeX Project Public License (LPPL), either version 1.3c of this
8 % license or (at your option) any later version. The latest version
9 % of this license is in the file
10 %
11 % https://www.latex-project.org/lppl.txt
12 %
13 %
14 % The latex-lab bundle is developed in the LaTeX2e GitHub.
15 % Issues may be reported at
16 %
17 % https://github.com/latex3/latex2e/issues
18 %
19 \def\ltlabfootnotedate{2026-04-28}
20 \def\ltlabfootnoteversion{0.8p}
21
22 %<*driver>
23 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
24 \documentclass{l3in2edoc}
25
26 \EnableCrossrefs
27 \CodelineIndex
28 \begin{document}
29 \DocInput{latex-lab-footnotes.dtx}
30 \end{document}
31 %</driver>
32 %
33 % \fi
34 %
35 %
36 % \title{The \texttt{latex-lab-footnotes} code\thanks{}}
37 % \author{Frank Mittelbach, \LaTeX{} Project}
38 % \date{v\ltlabfootnoteversion\ \ltlabfootnotedate}
39 %
40 % \maketitle
41 %
42 % \newcommand\fmi[1]{\begin{quote} TODO: \itshape #1\end{quote}}
43 % \newcommand\NEW[1]{\marginpar{\mbox{}\hfill\fbox{New: #1}}}
44 % \providecommand\class[1]{\texttt{#1.cls}}
45 % \providecommand\pkg[1]{\texttt{#1}}
46 %
47 %
48 % \begin{abstract}
49 % \emph{to be written}
50 % \end{abstract}
51 %
52 % \tableofcontents
53 %
54 %
55 % \section{Introduction}
56 %
57 % This code reimplements the footnote interfaces for \LaTeX{}
58 % offering configurable methods for layout and functionality
59 % adjustments that avoid overwriting each other when used in
60 % classes as well as in packages (as far as possible --- obviously
61 % some adjustments are mutually exclusive). This is achieved by
62 % providing a larger number of hooks (for areas where different
63 % packages/classes can easily coexist with their adjustments) and a
64 % number of sockets to which only one class or package
65 % can write to successfully (in case of multiple changes the
66 % last one wins). The latter are for special functionality, e.g.,
67 % if footnote text is typeset as a single paragraph, it can't be configured
68 % the same time to be typeset vertically with one footnote below
69 % each other.
70 %
71 % The interfaces are set up to support tagged PDF, but in order
72 % for this to work, all packages altering the footnote setup should
73 % use the interfaces provided here and not do it through the
74 % legacy methods (though there is some support for the latter as
75 % well, but it will not work in all cases).
76 %
77 % \subsection{Configuration methods}
78 %
79 % Historically, the footnote setup in \LaTeX{} was done by
80 % providing definitions for \cs{@makefnmark} (format the footnote
81 % mark in running text and in front of the footnote text) and
82 % \cs{@makefntext} (formatting the footnote text and placing a mark
83 % in front of it).
84 %
85 % There was a default definition for \cs{@makefnmark} in the format
86 % that was used by most document classes,
87 % but \cs{@makefntext} had to be defined in the class itself because
88 % the format didn't provide a default. As a result you will find
89 % definitions for the latter in all document classes and definitions
90 % for \cs{@makefnmark} only in very few.
91 %
92 % Furthermore, to enable special footnote layouts or provide
93 % additional functionality a few packages (and a few classes)
94 % overwrote other internal commands of \LaTeX's footnote
95 % mechanism. The commands affected in this way are mainly
96 % \cs{@footnotemark} and \cs{@footnotetext}. These overwrites could
97 % not be used in combination, so either the packages/classes had to
98 % be aware of being loaded together (which they sometimes did or
99 % tried to) or they would fail by overwriting each other
100 % unconditionally.
101 %
102 % The present rewrite is an attempt to improve this situation, but
103 % of course, it will only work if all packages/classes make use of
104 % the new interfaces. Fortunately, the number of problematical
105 % packages altering these internal commands are fairly small so
106 % arranging for updates is a realistic goal --- to achieve properly
107 % tagged PDF it is a requirement.
108 %
109 %
110 %
111 % \section{Sockets and hooks}
112 %
113 % We use sockets for those parts that can be controlled only by one
114 % package or by the kernel and hooks for places where it may be
115 % possible that several packages or the document class adds code
116 % (typically declarations such as font changes, etc.).
117 %
118 % Note that sockets are of interest only to very
119 % few specialized packages, mainly \pkg{footmisc}, and packages
120 % providing similar functionality---the current documentation is
121 % therefore fairly sketchy.
122 %
123 % In contrast the hooks are of interest to many classes to provide
124 % their layout alterations in a way that it works smoothly with
125 % other packages handling aspects of footnote formatting.
126 %
127 %
128 % \subsection{Formatting the mark in the main text}
129 %
130 % This implements formatting the mark\footnote{Like this one.} and
131 % its relation to surrounding text, e.g., if several marks appear
132 % in the same place, etc.
133 %
134 %
135 % \subsubsection{Sockets}
136 %
137 % None: everything is implemented through a single definition for
138 % \cs{@footnotemark} that offers a number of hooks that can be used
139 % by packages to implement handling of multiple marks and the
140 % formatting of marks.
141 %
142 %
143 % \subsubsection{Hooks for formatting the footnote mark in text}
144 %
145 % The hooks to customize the marks in the text are the following:
146 % \begin{description}
147 % \item[\hook{fnmark/before}]
148 %
149 % \DescribeHook[noprint]{fnmark/before}
150 %
151 % Executed at the very beginning of \cs{footnotemark}. Currently
152 % there are two packages (\pkg{bibarts} and \pkg{chextras}) that
153 % prepend material at this point (not necessarily correctly, e.g.,
154 % they do not all check that they are in horizontal mode).
155 %
156 % This hook is paired with hook \hook{fnmark/after}.
157 %
158 % \item[\hook{fnmark}]
159 %
160 % \DescribeHook[noprint]{fnmark}
161 %
162 % Executed in horizontal mode and after the current space factor
163 % has been saved away for reuse. This is where currently code for multiple
164 % marks does its preparation (as done by \pkg{footmisc} and
165 % others).
166 %
167 % The hook is only executed in hmode, i.e., not if the mark is
168 % generated in math --- maybe that means the multiple handling
169 % should happen later?
170 %
171 % After the hook a \cs{nobreak} is executed, so any
172 % ``material'' added in the hook is tied to the following mark
173 % unless it contains its own permissible penalty.
174 %
175 % \item[\hook{fnmark/begin}]
176 %
177 % \DescribeHook[noprint]{fnmark/begin}
178 %
179 % This hook is executed directly in front of the typeset mark.
180 % This is the place where \pkg{hyperref} would have added
181 % part of its code, i.e., after the \cs{nobreak} mentioned above.
182 % With the integration of hyperlinks in the tagging code
183 % this hook may not be necessary at all.
184 %
185 % \item[\hook{fnmark/end}]
186 %
187 % \DescribeHook[noprint]{fnmark/end}
188 %
189 % This hook is executed directly after the typeset mark. It is
190 % used by \pkg{memhfixc}, \pkg{scrlttr2}, and
191 % \pkg{footmisc}. Used, for example, to implement support for
192 % multiple marks in succession.
193 %
194 % It is \emph{not} a reversed hook.
195 %
196 %
197 % \item[\hook{fnmark/after}]
198 %
199 % \DescribeHook[noprint]{fnmark/after}
200 %
201 % This hook is executed at the very end of the \cs{footnotemark} command.
202 %
203 % It is a reversed hook to pair with \hook{fnmark/before}
204 % \end{description}
205 %
206 %
207 %
208 %
209 % \subsubsection{Additional configuration possibilities}
210 %
211 % The actual formatting is done through \cs{@makefnmark} --- no
212 % special customization support for now.
213 %
214 %
215 %
216 % \subsection{Formatting the footnote text}
217 %
218 % This implements the formatting of the footnote text the way it
219 % appears at the bottom of the page (default case), or possibly
220 % elsewhere, e.g. in the margin.
221 %
222 % \subsubsection{Sockets}
223 %
224 % To cater for different layout configurations there are four
225 % sockets that can be set by a package or
226 % class but there should be only one per document setting them,
227 % i.e., if two packages/classes set them they are mutually
228 % incompatible (or rather the last one wins most likely).
229 % These are:
230 % \begin{description}
231 % \item[\socket{fntext/process} (1 argument)]
232 %
233 % \DescribeSocket[noprint]{fntext/process}
234 %
235 % This socket receives all material that is to be processed (or
236 % stored) including color protection code and what have you.
237 % The \plug{default} executes \cs{insert}\cs{footins}.
238 %
239 % Available plugs are \plug{default}, \plug{side} (side notes), and \plug{mp} (minipage).
240 %
241 %
242 % \item[\socket{fntext/make} (1 argument)]
243 %
244 % \DescribeSocket[noprint]{fntext/make}
245 %
246 % This socket receives the \meta{text} as given in \cs{footnote}
247 % or \cs{footnotetext} in the document and adds formatting
248 % instructions to it.
249 %
250 % The \plug{default} plug runs \cs{@makefntext} which contains
251 % various hooks for customization. For most scenarios this is
252 % sufficient. However, when running all footnotes as a single
253 % paragraph at the bottom, then each footnote needs to be
254 % prepared prior to storing it with \cs{insert} and this socket
255 % allows running extra code to do that.
256 %
257 % Available plugs are \plug{default} and \plug{para}.
258 %
259 % \item[\socket{fntext/begin} (no argument)]
260 %
261 % \DescribeSocket[noprint]{fntext/begin}
262 %
263 % The socket is executed near the start of the
264 % argument for the \socket{fntext/make} socket.
265 % By \plug{default} it adds a strut to the footnote
266 % material so that consecutive footnotes are properly spaced
267 % vertically. In some use cases this is not appropriate (e.g.,
268 % when running all footnotes as a single paragraph) and so with
269 % this socket one can cancel the action or do something else
270 % instead.
271 %
272 % Available plugs are \plug{default} and \plug{noop}.
273 %
274 %
275 % \item[\socket{fntext/end} (no argument)]
276 %
277 % \DescribeSocket[noprint]{fntext/end}
278 %
279 % This socket is executed at the very end of the argument passed
280 % to socket \socket{fntext/make}. By \plug{default} it
281 % adds a final strut as long as we are still in horizontal mode
282 % (i.e., processing the footnote text paragraph). When running
283 % several footnotes in one paragraph some additional material
284 % (some horizontal glue) needs adding at this point which is done
285 % with the plug \plug{para}.
286 %
287 % Available plugs are \plug{default}, \plug{para}, and
288 % \plug{noop}.
289 % \end{description}
290 %
291 %
292 % All standard plugs for the socket \socket{fntext/make} run
293 % \cs{@makefntext} and this command contains two further
294 % sockets (unless it is overwritten by a legacy class):
295 % \begin{description}
296 % \item[\socket{fntext/mark} (0 arguments)]
297 %
298 % \DescribeSocket[noprint]{fntext/mark}
299 %
300 % This socket has no input arguments but uses \cs{@makefnmark} to
301 % typeset the mark in front of the footnote text. Its
302 % \plug{default} uses code that examines the value of
303 % \cs{footnotemargin} and based on its setting typeset the mark
304 % in different ways:
305 % \begin{itemize}
306 % \item positive: typeset the mark in a box of that size
307 % \item zero: use \cs{llap} around the mark
308 % \item negative: use \cs{llap} but with a box of the given size
309 % negated inside
310 % \item \texttt{-}\cs{maxdimen}: just use \cs{@makefnmark}
311 % \end{itemize}
312 % For most cases this would be flexible enough, but if not then a
313 % class can define its own plug to specify the placement of the mark.
314 %
315 % Available plugs are \plug{default} and \plug{noop} (no mark is produced).
316 %
317 %
318 % \item[\socket{fntext/text} (1 argument)]
319 %
320 % \DescribeSocket[noprint]{fntext/text}
321 %
322 % This socket manages the formatting of the footnote text
323 % (presented as an argument) once the mark has been typeset. In
324 % all cases we can think of this formatting is better configured
325 % via the available hooks described below, so the \plug{default}
326 % just grabs the argument and processes it without any other
327 % action. It is really only there to allow for some fancy stuff
328 % that some design comes up with.
329 %
330 % Available plugs are \plug{identity} (default) and \plug{noop}.
331 %
332 % \end{description}
333 %
334 %
335 % The above configuration points are sufficient to implement all
336 % commonly used footnote layouts assuming L-R typesetting. For R-L
337 % typesetting they or may or may not need some extension (though
338 % that is not clear right now).
339 %
340 %
341 %
342 % \subsubsection{Hooks for formatting the footnote text}
343 %
344 % \begin{description}
345 % \item[\hook{fntext/before}]
346 %
347 % \DescribeHook[noprint]{fntext/before}
348 %
349 % Executed at the very beginning of \cs{footnotetext}. Currently
350 % there is one package (\pkg{linguex}) that
351 % prepends material at this point.
352 %
353 % This hook is paired with hook \hook{fnmark/after}.
354 %
355 % \item[\hook{fntext}]
356 %
357 % \DescribeHook[noprint]{fntext}
358 %
359 % Executed at the beginning of the material passed to the first
360 % configuration point. Typically used to set any baseline
361 % stretch for the footnote text, e.g., by \pkg{setspace},
362 % \pkg{footmisc}, \class{uathesis} and others. Could be done in a
363 % later hook but is a bit more efficient here.
364 %
365 % After the hook has run, the font is established, i.e., it can't
366 % be used to set a different font size.
367 %
368 % \item[\hook{fntext/para}]
369 %
370 % \DescribeHook[noprint]{fntext/para}
371 %
372 % After the font is set (after the previous hook), some default
373 % paragraph parameters
374 % are set up
375 % including \cs{interlinepenalty}, \cs{hsize}, \cs{parindent} and
376 % a number of others, as some of them depend on the font
377 % size. Then the \hook{fntext/para} is run which can overwrite
378 % the default. If one wants to
379 % change the font size, it is probably necessary to reset these
380 % other parameters too, e.g., \cs{parindent}, which can be done
381 % here.
382 %
383 % Note: the socket \socket{fntext/make} normally
384 % runs the command \cs{@makefntext} or some code that eventually
385 % runs this command, and this then produces the footnote mark in
386 % front of the formatted footnote text. In
387 % front of both the mark and the footnote text some classes have
388 % placed paragraph parameter adjustments in their redefinition of
389 % \cs{@makefntext}. However, there is no need to place it there
390 % it could equally well go into the \hook{fntext/para} hook. We
391 % therefore do not provide another hook at this other point.
392 %
393 % \item[\hook{fntext/begin} \& \hook{fntext/end}]
394 %
395 % \DescribeHook[noprint]{fntext/begin}
396 % \DescribeHook[noprint]{fntext/end}
397 %
398 % The footnote text itself is surrounded by the hooks
399 % \hook{fntext/begin} and \hook{fntext/end}. The two hooks are
400 % not paired as they are typically used independently.
401 %
402 % \item[\hook{fntext/after}]
403 %
404 % \DescribeHook[noprint]{fntext/after}
405 %
406 % At the very end of \cs{footnotetext} we execute the hook
407 % \hook{fntext/after} which is a reversed hook paired with
408 % \hook{fntext/before}. Some packages, e.g., \pkg{linguex}, have
409 % code in that position.
410 %
411 % \end{description}
412 %
413 %
414 %
415 %
416 % \subsubsection{Additional configuration possibilities}
417 %
418 % The formatting of the footnote mark in front of the footnote
419 % text is influenced by the setting of the dimen parameter
420 % \cs{footnotemargin}. By default its value is 1.8em in the current
421 % text font (or \texttt{-}\cs{maxdimen} when the para option is
422 % chosen). The following rules apply:
423 % \begin{itemize}
424 % \item
425 %
426 % If it has the value \texttt{-}\cs{maxdimen} then the mark is
427 % generated by \cs{@makefnmark}.
428 %
429 % \item
430 %
431 % Otherwise, if the value is
432 % negative then the mark is placed into an \cs{llap} left aligned
433 % in a box of size \texttt{-}\cs{footnotemargin}.
434 %
435 % \item
436 %
437 % If the value is zero an \cs{llap} is used without an inner box.
438 %
439 % \item
440 %
441 % If the value is greater zero (but less than \cs{maxdimen}) the
442 % mark is placed right aligned into a box of size
443 % \cs{footnotemargin}.
444 %
445 % \item
446 %
447 % The value \cs{maxdimen} is used as a marker to indicate that
448 % no value was given and that the default should be used,
449 % i.e. 1.8em or \texttt{-}\cs{maxdimen} depending on the chosen
450 % option.
451 % \end{itemize}
452 %
453 % \subsection{Debugging sockets and hooks}
454 %
455 % For some rudimentary debugging we currently have \cs{DebugFNotesOn}
456 % (and \cs{DebugFNotesOff}). At the moment \cs{DebugFNotesOn} only
457 % shows the current settings for hooks and sockets related to the
458 % footnote code and then
459 % automatically turns itself off again.
460 %
461 %
462 % \section{Tagging and hyperlinking support}
463 %
464 % \fmi{this section needs work (and probably csname changes)}
465 %
466 % Footnotes consist of a \emph{footnotemark} (short: mark) that is typically placed in the text
467 % as a superscript number like this\footnotemark[1], and a \emph{footnotetext}
468 % (short: note) that is placed at the bottom of the page.
469 % The \emph{footnotetext} normally repeats at the begin the mark as a visual clue.
470 %
471 % Tagging (and hyperlinking) has to connect the mark with the note.
472 % For the tagging code, we assume that every mark has exactly one associated note,
473 % and that every note is associated to at least one mark
474 % and can have more associated marks.
475 %
476 % The mark doesn't need to be visible, e.g. the typesetted
477 % mark\textsuperscript{1--3} denotes three marks, where the second is invisible.
478 % Tagging should produce here probably three \texttt{Lbl} structures
479 % (one without content), and an artifact for the range marker.
480 % If such a range is used, links can only point to the notes 1 and 3 and
481 % one has to suppress the linking for the second mark.
482 % This means that links and tagging are also related
483 % to the actual formatting of the footnote mark.
484 % In the following this problem is mostly ignored for now, but
485 % should not be forgotten and handled later.
486 %
487 % \subsection{Technical details for the tagging}
488 %
489 % The following sockets are set up for kernel use, when doing tagging:
490 % There name and/or function will probably change as they currently
491 % mix tagging with the link support.
492 %
493 %
494 % TODO: review this sockets
495 % \begin{description}
496 % \item[\socket{tagsupport/fnmark} (2 argument)]
497 %
498 % \DescribeSocket[noprint]{tagsupport/fnmark}
499 %
500 % The socket is used in \cs{@footnotemark}/\cs{fnote_footnotemark:}
501 % and takes \cs{@makefnmark} or --- if link support is wanted ---
502 % \verb+\socket_use:n{fnmark/link}{\@makefnmark}+ as second argument.
503 % It prints the mark in the text
504 % and surrounds it with a tagging structure.
505 %
506 % \fmi{describe and decide on names}
507 %
508 %
509 % \item[\socket{tagsupport/fntext/begin} (no argument)]
510 %
511 % \DescribeSocket[noprint]{tagsupport/fntext/begin}
512 %
513 % This socket is used before the main processing socket
514 % (so before the \cs{insert} command). It opens the FEnote structure.
515 %
516 %
517 % \item[\socket{tagsupport/fntext/end} (no argument)]
518 %
519 % \DescribeSocket[noprint]{tagsupport/fntext/end}
520 %
521 % This socket is used after the main processing socket
522 % (so after the \cs{insert} command). It closes the FEnote structure.
523 %
524 %
525 % \item[\socket{tagsupport/fntext/mark} (2 argument)]
526 %
527 % \DescribeSocket[noprint]{tagsupport/fntext/mark}
528 %
529 % This socket is used around the mark in the footnote text.
530 % It adds tagging support.
531 %
532 % \item[\socket{tagsupport/fntext/text} (2 argument)]
533 %
534 % \DescribeSocket[noprint]{tagsupport/fntext/text}
535 %
536 % This socket handles mc-chunks around the text of the footnote. It takes as second
537 % argument the text.
538 %
539 % \end{description}
540 %
541 %
542 % The \emph{footnotemark} should create a \texttt{/Lbl} structure\footnote{to make it easier
543 % to identify the role we use \texttt{/footnotemark} which we rolemap to \texttt{/Lbl}}
544 % that should contain a \texttt{/Ref} entry pointing
545 % to the structure of the \emph{footnotetext}.
546 %
547 % The \emph{footnotetext} should create a \texttt{/FENote}%
548 % \footnote{We tag it as \texttt{/footnote} and role map it.}
549 % structure with a \texttt{/Ref}
550 % entry pointing to the structures of \emph{all} marks related to the note.
551 % The mark at the begin of the
552 % note is in a \texttt{/Lbl}\footnote{We tag it as \texttt{/footnotelabel}.}
553 % structure but has to fulfil no special requirements.
554 %
555 % Structure objects and the underlying properties used by the tagging
556 % code are initialized when the structure is opened. This means that one can not
557 % directly add data to a future structure
558 % but as structure objects are written at the end of the document it is
559 % possible to update \texttt{/Ref} entries in an end document hook.
560 %
561 %
562 % So tagging has to solve two problems:
563 % \begin{itemize}
564 % \item the mark and the footnote text must be surrounded by the correct structure
565 % and marked content commands. This is not trivial
566 % as there are various layouts (bottom, marginpar, minipage) and the tagging
567 % from the automatic paratagging must be taken into account if one want to avoid
568 % faulty nesting.
569 %
570 % \item It must detect which marks are related to which notes
571 % so that it can setup the \texttt{/Ref} cross-references.
572 % \end{itemize}
573 %
574 %
575 % \subsection{Requirements for links}
576 %
577 % Links should go from the mark to the note. Sometimes it has been requested
578 % that links go back too, but as there
579 % can be more than one mark connected to a note it is not clear how to decide to which mark it should go.
580 % Using the keys from the PDF viewer to go back is normally better.
581 %
582 % Links are closely related to the references stored in the \texttt{/Ref}
583 % entry of a mark and so are handled in the code together with them.
584 % But there are subtle technical differences to take care of
585 % as links and destinations are whatsits and so must be created at the correct time.
586 %
587 % It should be possible to suppress the links both globally and locally.\footnote{
588 % Currently hyperref only offers the option to suppress the
589 % footnote links globally
590 % with the option \texttt{hyperfootnotes=false}. To suppress them locally
591 % only the \texttt{NoHyper} environment is provided.}
592 %
593 % Footnote links should work also if tagging is disabled, either locally (e.g. in an artifact)
594 % or if tagging is deactivated globally. They should therefore use their own system
595 % to store the relations between mark and note, even if this duplicates some code.
596 %
597 % \subsection{The algorithmus to connect marks and notes}
598 %
599 %
600 % The connection is made by comparing the value of \cs{@thefnmark}.
601 %
602 % The standard mark commands (\cs{footnotemark} and \cs{footnote})
603 % store the current value of \cs{@thefnmark}
604 % with a combination of their own structure number (for the tagging) and a unique id (for the link)
605 % as a key in a property.
606 %
607 % A following \cs{footnotetext} compares its own \cs{@thefnmark} with the values in
608 % the prop. If there is one or more match it stores the keys and removes the entries
609 % from the property (so in a normal document the property will never contain more than
610 % a few entries).
611 %
612 % This works well as long as the \cs{footnotemark} commands are issued before the \cs{footnotetext} and
613 % as long as nothing unusual is done to \cs{@thefnmark}.
614 % It also works if a document uses more than one footnote series as long as they have distinct numbering
615 % systems, but in case a distinction is needed it is possible to define
616 % a new class with its own data structure and to switch locally to use this
617 % class. The following three commands are used for this.
618 %
619 % The default class uses the name \texttt{default}
620 %
621 % \begin{variable}{\g_fnote_id_int}
622 % This integer is used as unique identifier to store data for a footnote.
623 % It should be increase when a footnote mark or a footnote text is created.
624 % \end{variable}
625 %
626 % \begin{function}{\fnote_class_new:nn}
627 % \begin{syntax}
628 % \cs{fnote_class_new:nn}\Arg{name}\Arg{key/value option}
629 % \end{syntax}
630 % This declaration sets up the needed data structure. Currently this only
631 % consists of a property list which is used to store and manage the mark values.
632 % There are no options yet.
633 % \end{function}
634 %
635 % \begin{function}{\fnote_mark_struct_gput:nnn,\fnote_mark_id_gput:nnn}
636 % \begin{syntax}
637 % \cs{fnote_mark_struct_gput:nnn}\Arg{mark}\Arg{class name}
638 % \cs{fnote_mark_id_gput:nnn}\Arg{mark}\Arg{class name}
639 % \end{syntax}
640 % These commands store either the current structure number or the current id
641 % as key and the \meta{mark} as value in the property list
642 % associated with the \meta{class name}.
643 % \end{function}
644 %
645 % \begin{function}{\fnote_mark_gpop_all:nnnN}
646 % \begin{syntax}
647 % \cs{fnote_mark_gpop_all:nnN}\Arg{id or struct}\Arg{mark}\Arg{class name}\meta{sequence}
648 % \end{syntax}
649 % This command stores all the keys/structure numbers whose value in the
650 % property list for \meta{class name} are equal to \meta{mark}
651 % into the sequence \meta{sequence} and then removes them from the property list.
652 % The content of the sequence can then be
653 % used to create link targets and references.
654 % \end{function}
655 %
656 %
657 % \subsubsection{\cs{footref}}
658 %
659 % \cs{footref} uses internally the same command to set the mark as \cs{footnotemark}, it only
660 % defines \cs{@thefnmark} differently. This \cs{@thefnmark} is not suitable for the method described
661 % above: as it contains a reference command it can't be used to match a note, also \cs{footref} can
662 % be used after the note has already been set. \cs{footref} disables therefore the automatic detection.
663 %
664 % Instead the \cs{label} command is
665 % extended in the \cs{footnotetext} command to also store the structure number and \cs{footref} retrieves this
666 % number to setup the reference and the link.
667 %
668 % The structure related to the \cs{footref} is added to the end of the \texttt{/Ref} array of the note and so the
669 % \texttt{/Ref} array doesn't necessarily reflect the order of the marks in the document. It would probably
670 % be possible to change this, but it is not clear if it actually matters and so it worth the additional coding
671 % and processing.
672 %
673 % \subsubsection{\cs{footnotemark} after \cs{footnotetext}}
674 %
675 % The automatic detection doesn't work if a \cs{footnotemark} is issued after
676 % the \cs{footnotetext} it refers to. There will be no error, but neither the link nor
677 % the \texttt{/Ref} will connect both.
678 %
679 % The simple way to handle this is to use a label and \cs{footref}:
680 %
681 % \begin{verbatim}
682 % \footnotetext{\label{fn:a}text} ... \footref{fn:a}
683 % \end{verbatim}
684 %
685 % An alternative would be to extend the syntax of \cs{footnotemark} and
686 % \cs{footnotetext} to allow to add a label which can then be used.
687 % For example
688 %
689 % \begin{verbatim}
690 % \footnotetext[label=fn:a]{text} ... \footnotemark[label=fn:a]
691 % \end{verbatim}
692 %
693 % As both have already an optional argument, that requires the optional argument extension.
694 %
695 %
696 % \subsection{Links}
697 %
698 % The keys containing the structure number/id combination
699 % detected for the \texttt{/Ref} are also used for links. For links the second
700 % part is used as this id is increased also if tagging is deactivated.
701 %
702 % A \cs{footnotetext} creates a bunch of destinations (in most cases this sums up to
703 % two destinations): one for every structure number in the \texttt{/Ref} (used as target
704 % by the mark commands) and one for the structure number of the footnotetext itself
705 % (used as target by \cs{footref}s commands).
706 %
707 % \subsection{Implementation details regarding tagging}
708 %
709 % \subsection{Handling the mark}
710 %
711 % The mark in the text is handled by assigning an appropriate
712 % plug to the socket \socket{tagsupport/fnmark}.
713 % It takes one argument, \cs{@makefnmark}, the
714 % command which formats the mark, and surrounds it by link and tagging
715 % commands. At the point where the socket is
716 % executed, \cs{@thefnmark} has already been defined and can be used to
717 % setup the reference detections.
718 %
719 %
720 % \subsection{Handling the footnotetext}
721 %
722 % The main part is done by assigning a different plug to socket \socket{tagsupport/fntext/begin}
723 % and \socket{tagsupport/fntext/end}
724 % surrounding the footnote text.
725 % These sockets are used to start and end the structure and
726 % attempt to detect to which mark the note is related.
727 %
728 % The actual typesetting of the note text is done by
729 % \cs{fnote_makefntext:n} (or its \LaTeXe{} name \cs{@makefntext}). In
730 % the new implementation this contains two further kernel sockets for tagging:
731 % \socket{tagsupport/fntext/mark} and
732 % \socket{tagsupport/fntext/text}. They get plugs assigned that add the
733 % tagging commands around note mark and note text.
734 %
735 % \subsection{Footnotes in minipages}
736 %
737 % In minipages the \cs{footnote} command uses a special marker
738 % (small italic letters by default) and puts the
739 % footnote text at the bottom of the box. The \cs{footnotemark}
740 % command uses the standard footnote counter and marker (and so typically
741 % creates a superscript number).
742 % It is meant to be used with a \cs{footnotetext} \emph{outside}
743 % the minipage to create a footnote mark which refers to a footnote text
744 % at the bottom of the page.
745 % This means to repeat a footnote marker in a minipage you should use the \cs{footref} command.
746 %
747 % Tagging works quite similar to normal footnotes if the new definition is used
748 % and if the minipage code is changed to use the new configuration point.
749 % The main problem here is currently the tagging of the minipage itself.
750 %
751 % \section{TODOs}
752 %
753 % \begin{itemize}
754 %
755 % \item Special formatting of footnote marks in the text, e.g. if ranges or commas are
756 % used require special care as they should normally mark up such text as artifacts and
757 % perhaps have to insert empty structures to represent an invisible mark. This must be coordinated
758 % with the relevant packages and classes.
759 %
760 % \item manyfoot doesn't work correctly and must be analyzed.
761 %
762 % \item \pkg{memoir} is not supported at all and errors when the code tries to patch
763 % \cs{@makefntext}.
764 % \end{itemize}
765 %
766 % \emph{To be documented}
767 %
768 %
769 %
770 %
771 % \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
772 %
773 %
774 % \section{The Implementation}
775 %
776 % All this is very rough and misses a lot of documentation.
777 %
778 % \begin{macrocode}
779 %<*kernel>
780 %<@@=fnote>
781 % \end{macrocode}
782 %
783 % \subsection{File declaration}
784 % \begin{macrocode}
785 \ProvidesFile{latex-lab-footnotes.ltx}
786 [\ltlabfootnotedate\space v\ltlabfootnoteversion\space
787 changes to the footnote interfaces]
788 % \end{macrocode}
789 %
790 % \subsection{code not fully handled yet}
791 % \begin{macrocode}
792 %
793 % latex.ltx
794 % not looked at yet
795 % \@mpfootnotetext is probably no longer needed, or only to support other
796 % classes and package. See below about the minipage code.
797 %
798 % \long\def\@mpfootnotetext#1{%
799 % \global\setbox\@mpfootins\vbox{%
800 % \unvbox\@mpfootins
801 % \reset@font\footnotesize
802 % \hsize\columnwidth
803 % \@parboxrestore
804 % \def\@currentcounter{mpfootnote}%
805 % \protected@edef\@currentlabel
806 % {\csname p@mpfootnote\endcsname\@thefnmark}%
807 % \color@begingroup
808 % \@makefntext{%
809 % \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
810 % \par
811 % \color@endgroup}}
812 % ========
813 % used by the minipage footnote code.
814 %
815 % \def\@mpfn{footnote}
816 % \def\thempfn{\thefootnote}
817 % =========
818 % this perhaps need some configuration options.
819 %
820 %\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\@thefnmark}}}
821 %
822 % =========
823 %% alterations not covered:
824 %
825 % ./arabtex/afoot.sty --- too different (and probably too old)
826 %
827 % =====
828 % alterations of footnotetext not covered:
829 %
830 % ./revtex4-1/revtex4-1.cls ./revtex/ltxutil.sty ./revtex/revtex4-2.cls ... (need analysis)
831 % ./bigfoot/bigfoot.sty
832 %
833 % memoir needs checking too
834 %
835 % =====
836 %
837 % use of kerns to mark h-mode positions (unit sp)
838 %
839 % 1 = CJK
840 % 2 = CJK
841 % 3 = multiple footnotes (footmisc, koma, eledmac, tufte, memoir,
842 % parnotes, sidenotes)
843 % 3 = outer kern in letter spacing (letterspace)
844 % 3 = beginning of list (examdesign.cls)
845 % 4 = CJK pigin
846 % 5 = CJK ruby
847
848 % 1-4 = polyglossia for korean
849 %
850 % \end{macrocode}
851 %-------------------------------------
852 % \begin{macrocode}
853 \ExplSyntaxOn
854 % \end{macrocode}
855 % \subsection{Temporary variables}
856 % \begin{macrocode}
857 \prop_new:N \l_@@_tmpa_prop
858 \tl_new:N \l_@@_tmpa_tl
859 % \end{macrocode}
860 % \subsection{Public variables}
861 %
862 % A footnote mark will store its structure number (key) and the
863 % expanded \cs{@thefnmark} in this prop so
864 % that a following note can retrieve this info
865 % if needed. It is possible to use more than one footnote series (type)
866 % if needed (if different footnotes/note use the same
867 % numbering system).
868 % If this command is changed an accompanying property must be created
869 % \begin{NOTE}{UF}
870 % TODO: interface to create the property.\\
871 % TODO: check and decide about the name of the tl
872 % \end{NOTE}
873 % \begin{macro}[no-user-doc]{\l_fnote_type_tl}
874 % \begin{macrocode}
875 \tl_new:N \l_fnote_type_tl
876 \tl_set:Nn \l_fnote_type_tl {default}
877 % \end{macrocode}
878 % \end{macro}
879 % It must be possible to suppress the hyperlinking, both locally
880 % and globally. hyperref's hyperfootnotes option should set the boolean.
881 % \begin{macro}[no-user-doc]{\l_fnote_link_bool}
882 % \begin{macrocode}
883 \bool_new:N \l_fnote_link_bool
884 \bool_set_true:N \l_fnote_link_bool
885 % \end{macrocode}
886 % \end{macro}
887 % A hyperlink should have an changeable link type. This can
888 % be e.g. used to change the color or the border.
889 % \begin{macro}[no-user-doc]{\l_fnote_link_type_tl}
890 % \begin{macrocode}
891 \tl_new:N \l_fnote_link_type_tl
892 \tl_set:Nn \l_fnote_link_type_tl {link}
893 % \end{macrocode}
894 % \end{macro}
895 %
896 % \subsection{Internal variables}
897 %
898 % \begin{macro}{\l_@@_linktarget_tl}
899 % This command stores the name of a linktarget/destination
900 % when needed
901 % \begin{macrocode}
902 \tl_new:N \l_@@_linktarget_tl
903 % \end{macrocode}
904 % \end{macro}
905 % \begin{macro}{\l_@@_currentlabel_tl}
906 % This command is used to pass a label name around.
907 % \begin{macrocode}
908 \tl_new:N \l_@@_currentlabel_tl
909 % \end{macrocode}
910 % \end{macro}
911
912 % \begin{macro}{\l_@@_currentrefs_seq}
913 % This sequence stores the list of reference of a note
914 % \begin{macrocode}
915 \seq_new:N \l_@@_currentrefs_seq
916 % \end{macrocode}
917 % \end{macro}
918 %
919 % The connection between the mark(s) in the text and the note
920 % is either deduced automatically or done through an label.
921 % The default is automatic, but we must be able to suppress it. For this we use a boolean.
922 % \begin{macro}{\l_@@_autodetect_bool}
923 % \begin{macrocode}
924 \bool_new:N \l_@@_autodetect_bool
925 \bool_set_true:N \l_@@_autodetect_bool
926 % \end{macrocode}
927 % \end{macro}
928 % This is used to pass the structure number of the note around, e.g.
929 % to a label inside the note.
930 % \begin{macrocode}
931 \tl_new:N \l_@@_currentstruct_tl
932 \tl_set:Nn \l_@@_currentstruct_tl {2}
933 % \end{macrocode}
934 %
935 %
936 % \subsection{Variants}
937 %
938 % \begin{macrocode}
939 \cs_generate_variant:Nn \hook_gput_code:nnn{nne}
940 \cs_generate_variant:Nn \tag_struct_use:n {e}
941 % \end{macrocode}
942 %
943 % \subsection{Updating \cs{@thefnmark}}
944 % \begin{macro}[no-user-doc]{\fnote_step_fnmark:nn}
945 % This command updates \cs{@thefnmark}. The first argument
946 % is an optional integer expression, the second a counter name.
947 % If the optional argument is not given it steps the counter.
948 % \begin{macrocode}
949 \cs_new_protected:Npn \fnote_step_fnmark:nn #1#2 {
950 \tl_if_novalue:nTF {#1}
951 {
952 \stepcounter {#2}
953 \protected@xdef \@thefnmark { \use:c { the#2 } }
954 }
955 {
956 \group_begin:
957 % \end{macrocode}
958 % Note that this is a local assignment even though \LaTeX{}
959 % counters are normally globally changed. This is the way it was in
960 % 2e and so far we haven't changed it. The alternative would be to
961 % store the current value and restore it after \cs{@thefnmark} is
962 % altered.
963 % \begin{macrocode}
964 \int_set:cn { c@#2 }{ #1 }
965 \unrestored@protected@xdef \@thefnmark { \use:c { the#2 } }
966 \group_end:
967 }
968 }
969 % \end{macrocode}
970 % \end{macro}
971 % \begin{macro}[no-user-doc]{\fnote_set_fnmark:nn}
972 % This is similar to the previous command, but it doesn't step the
973 % counter but use the current value.
974 % \begin{macrocode}
975 \cs_new_protected:Npn \fnote_set_fnmark:nn #1#2 {
976 \tl_if_novalue:nTF {#1}
977 {
978 \protected@xdef \@thefnmark { \use:c { the#2 } }
979 }
980 {
981 \group_begin:
982 \int_set:cn { c@#2 }{ #1 }
983 \unrestored@protected@xdef \@thefnmark { \use:c { the#2 } }
984 \group_end:
985 }
986 }
987 % \end{macrocode}
988 % \end{macro}
989 %
990 % \subsection{Hooks}
991 %
992 % \begin{hookdecl}{fnmark/before,fnmark/after,
993 % fnmark,
994 % fnmark/begin,fnmark/end}
995 % Hooks in the footnotemark command.
996 % \begin{macrocode}
997 \NewMirroredHookPair{fnmark/before}{fnmark/after}
998 \NewHook{fnmark}
999 \NewHook{fnmark/begin}
1000 \NewHook{fnmark/end}
1001 % \end{macrocode}
1002 % \end{hookdecl}
1003 %
1004 % \begin{hookdecl}{fntext/before,fntext/after,
1005 % fntext,
1006 % fntext/begin,fntext/end,fntext/para}
1007 % Hooks in the footnotetext command:
1008 % \begin{macrocode}
1009 \NewMirroredHookPair{fntext/before}{fntext/after}
1010 \NewHook{fntext}
1011 \NewHook{fntext/para}
1012 \NewHook{fntext/begin}
1013 \NewHook{fntext/end}
1014 % \end{macrocode}
1015 % \end{hookdecl}
1016 %
1017 % \subsection{Debugging code}
1018 % The debugging code is just temporary
1019 %
1020 % \begin{macrocode}
1021 \bool_new:N \g_fnote_debug_bool
1022 % \end{macrocode}
1023
1024 % \begin{macro}[no-user-doc]{\DebugFNotesOn,\DebugFNotesOff}
1025 %
1026 % \begin{macrocode}
1027 \cs_new_protected:Npn \DebugFNotesOn { \bool_gset_true:N \g_fnote_debug_bool }
1028 \cs_new_protected:Npn \DebugFNotesOff { \bool_gset_false:N \g_fnote_debug_bool }
1029 % \end{macrocode}
1030 % \end{macro}
1031 %
1032 %
1033 %
1034 % We log the hooks in the footnote mark command, but only once
1035 % \begin{macrocode}
1036 \cs_new_protected:Npn \@@_debug_footnotemark:
1037 {
1038 \bool_if:NT \g_fnote_debug_bool
1039 {
1040 \hook_log:n {fnmark/before}
1041 \hook_log:n {fnmark}
1042 \hook_log:n {fnmark/begin}
1043 \hook_log:n {fnmark/end}
1044 \hook_log:n {fnmark/after}
1045 \cs_gset_eq:NN \@@_debug_footnotemark: \prg_do_nothing:
1046 }
1047 }
1048 % \end{macrocode}
1049 % Similar for the footnotetext
1050 % \begin{macrocode}
1051 \cs_new_protected:Npn \@@_debug_footnotetext:
1052 {
1053 \bool_if:NT \g_fnote_debug_bool
1054 {
1055 \socket_log:n {fntext/process}
1056 \socket_log:n {fntext/make}
1057 \socket_log:n {fntext/begin}
1058 \socket_log:n {fntext/end}
1059 % \end{macrocode}
1060 %
1061 % \begin{macrocode}
1062 \socket_log:n {fntext/mark}
1063 \socket_log:n {fntext/text}
1064 % \end{macrocode}
1065 %
1066 % \begin{macrocode}
1067 \socket_log:n {tagsupport/fnmark}
1068 \socket_log:n {tagsupport/fntext/begin}
1069 \socket_log:n {tagsupport/fntext/end}
1070 \socket_log:n {tagsupport/fntext/mark}
1071 \socket_log:n {tagsupport/fntext/text}
1072 % \end{macrocode}
1073 %
1074 % \begin{macrocode}
1075 \hook_log:n {fntext/before}
1076 \hook_log:n {fntext}
1077 \hook_log:n {fntext/para}
1078 \hook_log:n {fntext/begin}
1079 \hook_log:n {fntext/end}
1080 \hook_log:n {fntext/after}
1081 % \end{macrocode}
1082 % Show the info only once (if at all).
1083 % \begin{macrocode}
1084 \cs_gset_eq:NN \@@_debug_footnotetext: \prg_do_nothing:
1085 }
1086 }
1087 % \end{macrocode}
1088 %
1089 % \subsection{The new \cs{@footnotemark} command}
1090 % \begin{macro}[no-user-doc]{\fnote_footnotemark:}
1091 % This is the main command which will replace \cs{@footnotemark}.
1092 % \begin{macrocode}
1093 \cs_new_protected:Npn \fnote_footnotemark: {
1094 \@@_debug_footnotemark:
1095 %-------
1096 % bibarts
1097 % chextras --- actually in the wrong place does an \unskip
1098 \hook_use:n {fnmark/before}
1099 %-------
1100 \leavevmode
1101 \ifhmode
1102 \edef\@x@sf{\the\spacefactor}
1103 %-------
1104 % bxjsja-minimal.def --- what they do could be done at ``bibarts''
1105 % (a bit less efficient)
1106 % memhfixc.sty
1107 % footmisc.sty
1108 \hook_use:n {fnmark}
1109 %-------
1110 \nobreak
1111 \fi
1112 %-------
1113 % hyperref.sty
1114 \hook_use:n {fnmark/begin}
1115 %-------
1116 % \end{macrocode}
1117 % The kernel socket for tagging. It picks up \cs{@makefnmark} as its
1118 % argument. For link support it should surround the argument with the
1119 % link socket.
1120 % \begin{macrocode}
1121 \tag_socket_use:nnn {fnmark}{}{ \socket_use:n{fnmark/link}{\@makefnmark} }
1122 %-------
1123 % \end{macrocode}
1124 % If a footnote mark is placed by its own then it should finish by
1125 % executing the hook \hook{fnmark/end}, resetting the space factor, and
1126 % finishing with the hook \hook{fnmark/after}. However, in a complete
1127 % footnote these actions have to happen only after we have handled
1128 % the footnote text (e.g., by placing it into an \cs{insert}). In
1129 % such a situation \cs{_@@_footmark_finish:} below does nothing
1130 % and the action is carried out later.
1131 % \begin{macrocode}
1132 \@@_footnotemark_finish:
1133 }
1134 % \end{macrocode}
1135 % \end{macro}
1136 %
1137 % \begin{macro}{\@@_footnotemark_default_finish:,\@@_footnotemark_finish:}
1138 % The default definition for \cs{@@_footnotemark_finish:} is called \cs{@@_footnotemark_default_finish:}
1139 % \begin{macrocode}
1140 \cs_new_protected:Npn \@@_footnotemark_default_finish: {
1141 % hyperref.sty
1142 % memhfixc.sty --- could move fnmark/after
1143 % scrlttr2.cls --- could vanish if footmisc uses a hook
1144 % footmisc.sty
1145 \UseHook{fnmark/end}
1146 %-------
1147 \ifhmode
1148 \spacefactor \@x@sf \relax
1149 \fi
1150 %
1151 %-------
1152 \UseHook{fnmark/after}
1153 %-------
1154 }
1155 % \end{macrocode}
1156 %
1157 % \begin{macrocode}
1158 \cs_new_eq:NN \@@_footnotemark_finish: \@@_footnotemark_default_finish:
1159 % \end{macrocode}
1160 % \end{macro}
1161 %
1162 % \begin{socketdecl}{tagsupport/fnmark}
1163 % Not a public socket but reserved for tagging. By
1164 % default (without tagging) it uses the transparent plug.
1165 % \begin{macrocode}
1166 \NewTaggingSocket{fnmark}{2}
1167 % \end{macrocode}
1168 % \end{socketdecl}
1169 %
1170 % \begin{macro}[no-user-doc]{\@footnotemark}
1171 % Here we provide the traditional \LaTeXe{} name in case it is directly used
1172 % in some legacy class.
1173 % \begin{macrocode}
1174 \cs_set_eq:NN \@footnotemark \fnote_footnotemark:
1175 % \end{macrocode}
1176 % \end{macro}
1177 %
1178 %
1179 % \subsection{The new \cs{@footnotetext} command}
1180 %
1181 %
1182 % \begin{macro}[no-user-doc]{\fnote_footnotetext:n}
1183 %
1184 % \begin{macrocode}
1185 \cs_new_protected:Npn \fnote_footnotetext:n #1 {
1186 \@@_debug_footnotetext:
1187 %-------
1188 % ./linguex/linguex.sty
1189 \hook_use:n {fntext/before}
1190 %-------
1191 % \end{macrocode}
1192 % Execute a kernel socket for tagging.
1193 % \begin{macrocode}
1194 \tag_socket_use:n {fntext/begin}
1195 % \end{macrocode}
1196 %
1197 % \begin{macrocode}
1198 \socket_use:nn {fntext/process}
1199 {
1200 %-------
1201 % resetting baselinestretch ... (could be done further down)
1202 % ./uafthesis/uafthesis.cls
1203 % ./setspace/setspace.sty
1204 % ./footmisc/footmisc.sty (normal)
1205 \hook_use:n {fntext}
1206 %-------
1207 \reset@font
1208 \footnotesize
1209 %-------
1210 % some classes use a different font size, e.g.,
1211 % ./nrc/nrc1.cls ./nrc/nrc2.cls
1212 % but those could be done in fntext/para instead
1213 %-------
1214 % \end{macrocode}
1215 % In case of sidenotes the next settings are pointless, but as they
1216 % do not hurt (except for the \cs{hsize} setting) and are needed
1217 % for all other cases we make them here and overwrite them for side notes
1218 % \begin{macrocode}
1219 \interlinepenalty\interfootnotelinepenalty
1220 \splittopskip\footnotesep
1221 \splitmaxdepth \dp\strutbox
1222 \floatingpenalty \@MM
1223 \hsize\columnwidth
1224 \@parboxrestore
1225 \UseTaggingSocket{para/restore}
1226 \parindent 1em % typical default used in \@makefntext moved up here
1227 \def\@currentcounter{footnote}
1228 \protected@edef \@currentlabel { \p@footnote \@thefnmark }
1229 %-------
1230 % for altering para parameters ...
1231 % code for resphilosophica came earlier but it could go here.
1232 % Has the advantage that one can also overwrite \cs{@currentcounter}
1233 % and \cs{@currentlabel} is that is necessary.
1234 %
1235 % ./resphilosophica/resphilosophica.cls
1236 \hook_use:n {fntext/para}
1237 %-------
1238 \color@begingroup
1239 %-------
1240 % fnpara wants to replace \@makefntext{...} and para and side
1241 % option of footmisc etc too ...
1242 % so we make this a socket, because only one action can be active:
1243 %-------
1244 \socket_use:nn {fntext/make}
1245 {
1246 %-------
1247 % ./resphilosophica/resphilosophica.cls
1248 %-------
1249 \socket_use:n {fntext/begin}%
1250 %-------
1251 % bibarts
1252 % fnbreak.sty
1253 \hook_use:n {fntext/begin}
1254 %-------
1255 \ignorespaces
1256 #1
1257 %-------
1258 % bibarts
1259 % fnbreak.sty
1260 \hook_use:n {fntext/end}
1261 %-------
1262 % \end{macrocode}
1263 % The socket code (by default adding a strut) has to come
1264 % \emph{after} everything added into the hook above.
1265 % \begin{macrocode}
1266 \socket_use:n {fntext/end}
1267 }
1268 \par
1269 \color@endgroup
1270 }
1271 %-------
1272 % \end{macrocode}
1273 % The corresponding kernel hook that ends the tagging structure if
1274 % tagging is active.
1275 % \begin{macrocode}
1276 \tag_socket_use:n{fntext/end}
1277 %-------
1278 % ./linguex/linguex.sty
1279 \hook_use:n {fntext/after}
1280 %-------
1281 }
1282 % \end{macrocode}
1283 % \end{macro}
1284 %
1285 % \begin{socketdecl}{fntext/process}
1286 %
1287 % \begin{macrocode}
1288 \NewSocket {fntext/process}{1}
1289 \NewSocketPlug{fntext/process}{default}{ \insert\footins {#1} }
1290 \NewSocketPlug{fntext/process}{side} { \marginpar {#1} }
1291 % \end{macrocode}
1292 %
1293 % \begin{macrocode}
1294 \AssignSocketPlug{fntext/process}{default}
1295 % \end{macrocode}
1296 % \end{socketdecl}
1297 %
1298 %
1299 %
1300 % \begin{socketdecl}{fntext/make}
1301 % This socket receives the \meta{text} from the \cs{footnote} or
1302 % \cs{footnotetext} and formats it.
1303 % \begin{macrocode}
1304 \NewSocket {fntext/make}{1}
1305 \NewSocketPlug{fntext/make}{default}{ \@makefntext {#1} }
1306 % \end{macrocode}
1307 % When running several footnotes together as a paragraph some
1308 % additional work is necessary to unbox the individual footnotes
1309 % recursively (see \TeX{}book algorithm in appendix~D).
1310 % \begin{macrocode}
1311 \NewSocketPlug{fntext/make}{para}
1312 {
1313 \setbox\FN@tempboxa\hbox{\@makefntext{#1}}%
1314 \dp\FN@tempboxa\z@
1315 \ht\FN@tempboxa
1316 \dimexpr\wd\FN@tempboxa *%
1317 \footnotebaselineskip /\columnwidth\relax
1318 \box\FN@tempboxa
1319 }
1320 % \end{macrocode}
1321 %
1322 % \begin{macrocode}
1323 \AssignSocketPlug{fntext/make}{default}
1324 % \end{macrocode}
1325 % \end{socketdecl}
1326 %
1327 % \begin{socketdecl}{fntext/begin}
1328 % By default adds a strut at the start of the footnote text.
1329 % \begin{macrocode}
1330 \NewSocket {fntext/begin}{0}
1331 \NewSocketPlug{fntext/begin}{default}{ \rule\z@\footnotesep }
1332 % \end{macrocode}
1333 %
1334 % \begin{macrocode}
1335 \AssignSocketPlug{fntext/begin}{default}
1336 % \end{macrocode}
1337 % \end{socketdecl}
1338 %
1339 % \begin{socketdecl}{fntext/end}
1340 % By default adds a strut at the end of the footnote text unless we
1341 % are no longer in hmode.
1342 % \begin{macrocode}
1343 \NewSocket {fntext/end}{0}
1344 \NewSocketPlug{fntext/end}{default}{ \@finalstrut\strutbox }
1345 % \end{macrocode}
1346 % When running several footnotes together as a paragraph some
1347 % additional glue has to be added between them.
1348 % \begin{macrocode}
1349 \NewSocketPlug{fntext/end}{para}
1350 {%
1351 \strut
1352 \penalty-10\relax
1353 \hskip\footglue
1354 }
1355 % \end{macrocode}
1356 %
1357 % \begin{macrocode}
1358 \AssignSocketPlug{fntext/end}{default}
1359 % \end{macrocode}
1360 % \end{socketdecl}
1361 %
1362 % \begin{socketdecl}{tagsupport/fntext/begin,tagsupport/fntext/end}
1363 % Kernel sockets for tagging.
1364 % \begin{macrocode}
1365 \NewTaggingSocket{fntext/begin}{0}
1366 \NewTaggingSocket{fntext/end}{0}
1367 % \end{macrocode}
1368 % \end{socketdecl}
1369 %
1370 % Provide the name \LaTeXe{} is used to and do this unconditionally
1371 % (no patching of class code if any). This means that if a class
1372 % provides it own definition that gets lost and if necessary needs to
1373 % be handled with firstaid (or updating of the class).
1374 % \begin{macrocode}
1375 \AddToHook{begindocument}
1376 {
1377 \cs_set_eq:NN \@footnotetext \fnote_footnotetext:n
1378 }
1379 % \end{macrocode}
1380 %
1381 %
1382 %
1383 %
1384 % \subsection{The new \cs{@makefntext} command}
1385 %
1386 % \cs{footnotemargin} is the logic implemented by footmisc. Perhaps we
1387 % don't want to do this like that in the kernel but for now I have
1388 % used this interface unchanged.
1389 % \begin{macrocode}
1390 \newdimen\footnotemargin
1391 \footnotemargin\maxdimen % no value given
1392
1393 \AtBeginDocument
1394 {
1395 \ifdim \footnotemargin=\maxdimen
1396 \setlength\footnotemargin{1.8em}
1397 \fi
1398 }
1399 % \end{macrocode}
1400 %
1401 %
1402 %
1403 %
1404 % \begin{macro}[no-user-doc]{\fnote_makefntext:n}
1405 % \begin{macrocode}
1406 \cs_new_protected:Npn \fnote_makefntext:n #1 {
1407 % \end{macrocode}
1408 % Some classes in their redefinition for \cs{@makefntext} have
1409 % placed some paragraph parameters at this point, but those can
1410 % equally well go into the hook \hook{fntext/para}. We therefore do
1411 % not provide a further hook at this point.
1412 % \begin{macrocode}
1413 \noindent
1414 % \end{macrocode}
1415 % after leaving the vmode we can set the link targets.
1416 % \begin{macrocode}
1417 \socket_use:n{fntext/mark/link}
1418 % \end{macrocode}
1419 %
1420 % \begin{macrocode}
1421 \tag_socket_use:nnn {fntext/mark} {} { \socket_use:n {fntext/mark} }
1422 \tag_socket_use:nnn {fntext/text} {} { \socket_use:nn {fntext/text}{#1} }
1423 }
1424 % \end{macrocode}
1425 % \end{macro}
1426 %
1427 % \begin{socketdecl}{fntext/mark}
1428 % A socket to typeset the mark at the start of a footnote.
1429 % \begin{macrocode}
1430 \NewSocket {fntext/mark}{0}
1431 % \end{macrocode}
1432 % The \plug{default} plug implements the logic introduced with the
1433 % \pkg{footmisc} package.
1434 % \begin{macrocode}
1435 \NewSocketPlug{fntext/mark}{default}{
1436 \ifdim\footnotemargin>\z@
1437 \hb@xt@ \footnotemargin{\hss\@makefnmark}
1438 \else
1439 \ifdim\footnotemargin=\z@
1440 \llap{\@makefnmark}
1441 \else
1442 \ifdim\footnotemargin=-\maxdimen
1443 \@makefnmark
1444 \else
1445 \llap{\hb@xt@ -\footnotemargin{\@makefnmark\hss}}
1446 \fi
1447 \fi
1448 \fi
1449 }
1450 % \end{macrocode}
1451 %
1452 % \begin{macrocode}
1453 \AssignSocketPlug{fntext/mark}{default}
1454 % \end{macrocode}
1455 % \end{socketdecl}
1456 %
1457 % \begin{socketdecl}{fntext/text}
1458 % By default this socket does nothing special and simply processes
1459 % its argument as provided.
1460 % \begin{macrocode}
1461 \NewSocket {fntext/text}{1}
1462 % \end{macrocode}
1463 % \end{socketdecl}
1464 %
1465 %
1466 %
1467 % \begin{socketdecl}{tagsupport/fntext/mark,tagsupport/fntext/text}
1468 % Not a public socket but reserved for tagging. By
1469 % default they contain the \plug{transparent} and are reassigned if tagging is active.
1470 % \begin{macrocode}
1471 \NewTaggingSocket{fntext/mark}{2}
1472 \NewTaggingSocket{fntext/text}{2}
1473 % \end{macrocode}
1474 % \end{socketdecl}
1475 %
1476 %
1477 %
1478 % \subsubsection{Making documents use the new \cs{@makefntext}}
1479 %
1480 % If the definition for \cs{@makefntext} is that of the standard
1481 % classes then replace it with \cs{fnote_makefntext:n}, otherwise
1482 % try to patch the definition used in the class.
1483 %
1484 % Here is the definition the way it is in
1485 % \texttt{classes.dtx}. Notice that (for saving space) there is no
1486 % space after \texttt{em} to terminate the assignment. We need to
1487 % mimic that, otherwise a test would return false even if the
1488 % definition has not been modified.
1489 %
1490 %
1491 % \begin{macro}[no-user-doc]{\old@std@class@makefntext}
1492 % \begin{macrocode}
1493 \newcommand\old@std@class@makefntext[1]{%
1494 \parindent 1em%
1495 \noindent
1496 \hb@[email protected]{\hss\@makefnmark}#1}
1497 % \end{macrocode}
1498 % \end{macro}
1499 %
1500 % Here is the messy code for patching. Note that this is only there
1501 % to help classes along that aren't updated yet so it does some
1502 % minimal patching to hopefully add kernel configuration hooks in the
1503 % right place while otherwise leaving the legacy code alone. An
1504 % updated class would not redefine \cs{@makefntext} but simply add
1505 % appropriate code to the provided hooks.
1506 %
1507 % What it does is roughly the
1508 % following: It looks for a definition of \cs{@makefntext} of the form
1509 %\begin{verbatim}
1510 % {AAA \hbox BBB { CCC } DDD #1 EEE }
1511 %\end{verbatim}
1512 % where ``BBB'' is something like \texttt{to 1em} or similar. It then
1513 % replaces that with
1514 %\begin{verbatim}
1515 % {AAA \UseTaggingSocket{fntext/mark}{}{\hbox BBB { CCC }} DDD
1516 % \UseTaggingSocket{fntext/text}{}{#1} EEE }
1517 %\end{verbatim}
1518 % The patching is not very careful, i.e., it assumes there is only
1519 % one \verb=#1= in the replacement text and that the first \cs{hbox} found
1520 % is the right one to patch. But that is enough to cater for all
1521 % definitions of \cs{@makefntext} out there in the TL distribution.
1522 %
1523 % If \cs{hbox} is not found it tries the same looking for
1524 % \cs{hb@xt@} which is what some classes use and if that is not
1525 % found either it assume that this is a version that uses
1526 % \cs{@makefnmark} without surrounding it in a box and if that
1527 % fails it gives up with an \cs{ERROR} (which needs to get a proper definition).
1528 % \begin{macrocode}
1529 \tl_new:N \l_@@_patch_tl
1530 \cs_new_eq:NN \@@_tmp:w \ERROR
1531
1532 \cs_new_protected:Npn \@@_patch:
1533 {
1534 \tl_set:No \l_@@_patch_tl { \@makefntext { \UseTaggingSocket{fntext/text}{}{##1} } }
1535 \tl_if_in:NnTF \l_@@_patch_tl { \hbox }
1536 { \cs_set_eq:NN \@@_tmp:w \@@_patch_hbox:w }
1537 {
1538 \tl_if_in:NnTF \l_@@_patch_tl { \hb@xt@ }
1539 { \cs_set_eq:NN \@@_tmp:w \@@_patch_hb@xt@:w }
1540 {
1541 % \end{macrocode}
1542 % Some styles/classes use \verb=\makebox[...][...]= instead of \cs{hb@xt@}
1543 % so try to patch those too.
1544 % \begin{macrocode}
1545 \tl_if_in:NnTF \l_@@_patch_tl { \makebox }
1546 { \cs_set_eq:NN \@@_tmp:w \@@_patch_makebox:w }
1547 {
1548 \tl_if_in:NnTF \l_@@_patch_tl { \@makefnmark }
1549 { \cs_set_eq:NN \@@_tmp:w \@@_patch_@makefnmark:w }
1550 { \ERROR
1551 \cs_set_eq:NN \@@_tmp:w \exp_stop_f: }
1552 }
1553 }
1554 }
1555 \tl_set:Nf \l_@@_patch_tl
1556 { \exp_after:wN \@@_tmp:w \l_@@_patch_tl }
1557 \cs_set:Npn \@@_tmp:w { \long \def \@makefntext ####1 }
1558 \exp_after:wN \@@_tmp:w \exp_after:wN { \l_@@_patch_tl }
1559 }
1560 % \end{macrocode}
1561 %
1562 % If \cs{@makefntext} contains \cs{hbox} then grab ``AAA'' as
1563 % \verb=#1= and ``BBB'' (up to the open \texttt{\{}) and return it as
1564 %\begin{verbatim}
1565 % AAA \@makefntext@processX { \hbox BBB }
1566 %\end{verbatim}
1567 %
1568 % \begin{macrocode}
1569 \cs_new:Npn \@@_patch_hbox:w #1 \hbox #2 #
1570 { \exp_stop_f: #1 \@makefntext@processX { \hbox #2 } }
1571 % \end{macrocode}
1572 % Same for the other cases.
1573 % \begin{macrocode}
1574 \cs_new:Npn \@@_patch_hb@xt@:w #1 \hb@xt@ #2 #
1575 { \exp_stop_f: #1 \@makefntext@processX { \hb@xt@ #2 } }
1576 % \end{macrocode}
1577 %
1578 % \begin{macrocode}
1579 \cs_new:Npn \@@_patch_makebox:w #1 \makebox #2 #
1580 { \exp_stop_f: #1 \@makefntext@processX { \makebox #2 } }
1581 % \end{macrocode}
1582 %
1583 % If the definition contains neither \cs{hbox}, \cs{hb@xt@} nor \cs{makebox},
1584 % we see if it contains \cs{@makefnmark} and if so put the socket
1585 % before that.
1586 % \begin{macrocode}
1587 \cs_new:Npn \@@_patch_@makefnmark:w #1 \@makefnmark
1588 { \exp_stop_f: #1 \@makefntext@processX { \use:n } { \@makefnmark } }
1589 % \end{macrocode}
1590 %
1591 % The code provided by Bruno above expects 2 arguments but we need a
1592 % different structure so this is a simple reshuffling. Would be
1593 % better if we can patch the right structure in directly, but I'm
1594 % not a patch person, so this is the simple way out for now:
1595 %
1596 % \begin{macrocode}
1597 \cs_new:Npn \@makefntext@processX #1#2
1598 {
1599 \socket_use:n{fntext/mark/link}
1600 \UseTaggingSocket{fntext/mark}{}{#1{#2}}
1601 }
1602 % \end{macrocode}
1603 %
1604 % At \verb=\begin{document}= check if the current definition is
1605 % that of the standard classes and if so replace it by
1606 % \cs{fnote_makefntext:n} otherwise try and patch the definition
1607 % made by some class or package using the approach above.
1608 % \changes{0.80}{2025-07-04}{Do nothing if is it already \cs{fnote_makefntext:n}}
1609 % \begin{macrocode}
1610
1611 \AddToHook{begindocument}
1612 {
1613 \cs_if_eq:NNF\@makefntext \fnote_makefntext:n
1614 {
1615 \cs_if_eq:NNTF \@makefntext \old@std@class@makefntext
1616 {
1617 \cs_set_eq:NN \@makefntext \fnote_makefntext:n
1618 }
1619 {
1620 % \end{macrocode}
1621 % If \cs{@makefntext} contains the definition from \pkg{footmisc}
1622 % we do nothing, otherwise we try to patch.
1623 % \begin{macrocode}
1624 \cs_if_eq:NNF \@makefntext \footmisc@hang@makefntext
1625 { \@@_patch: }
1626 }
1627 }
1628 }
1629
1630
1631 % possibly add the following to check for multiple \hbox in
1632 % the definition:
1633 %
1634 % \seq_set_split:NnV \l_@@_patch_seq { \hbox } \l_@@_patch_tl
1635 % \int_compare:nT { \seq_count:N \l_@@_patch_seq } > 2 \ERROR
1636 %
1637 % \end{macrocode}
1638 %
1639 % \subsection{Document-level commands}
1640 %
1641 % \begin{macro}[no-user-doc]{\footnotetext}
1642 % \begin{macrocode}
1643 \DeclareDocumentCommand\footnotetext {o+m}
1644 {
1645 \fnote_set_fnmark:nn {#1} \@mpfn
1646 \@footnotetext {#2}
1647 }
1648 % \end{macrocode}
1649 % \end{macro}
1650 %
1651 %
1652 % \begin{macro}[no-user-doc]{\footnote}
1653 % \begin{macrocode}
1654 \DeclareDocumentCommand\footnote {o+m}
1655 {
1656 \fnote_step_fnmark:nn {#1} \@mpfn
1657 \cs_set_eq:NN \@@_footnotemark_finish: \prg_do_nothing:
1658 \@footnotemark
1659 \cs_set_eq:NN \@@_footnotemark_finish: \@@_footnotemark_default_finish:
1660 \@footnotetext {#2}
1661 \@@_footnotemark_finish:
1662 }
1663 % \end{macrocode}
1664 % \end{macro}
1665 %
1666
1667 % \begin{macro}[no-user-doc]{\footnotemark}
1668 % \begin{macrocode}
1669 \DeclareDocumentCommand\footnotemark {o}
1670 {
1671 \fnote_step_fnmark:nn {#1} { footnote }
1672 \@footnotemark
1673 }
1674 % \end{macrocode}
1675 % \end{macro}
1676
1677 % \begin{macro}[no-user-doc]{\footref}
1678 % \cs{footref} used the starred \cs{ref} in \cs{@thefnmark}
1679 % as the linking is handled by the tagging code inside
1680 % the \cs{@footnotemark}.
1681 % \cs{footref} should not try to link to its related
1682 % note automatically but should instead use the label.
1683 % This is passed to \cs{@footnotemark} through
1684 % \cs{l__fnote_currentlabel_tl}.
1685 %
1686 % \begin{macrocode}
1687 \DeclareDocumentCommand\footref {m}
1688 {
1689 \begingroup
1690 \unrestored@protected@xdef\@thefnmark{\ref*{#1}}%
1691 \endgroup
1692 \bool_set_false:N \l_@@_autodetect_bool
1693 \tl_set:Nn \l_@@_currentlabel_tl {#1}
1694 \@footnotemark
1695 \bool_set_true:N \l_@@_autodetect_bool
1696 }
1697 % \end{macrocode}
1698 % \end{macro}
1699 %
1700 %
1701 % \subsection{Firstaid for packages and classes}
1702 %
1703 % \subsection{Kernel patches}
1704 % Tagging of footnotes in minipages require a change in the minipage commands
1705 % We define at first a local configuration command for minipage footnotes.
1706 %
1707 % \begin{macrocode}
1708 \NewSocketPlug{fntext/process}{mp}
1709 {
1710 \global\setbox\@mpfootins\vbox{%
1711 \unvbox\@mpfootins
1712 #1
1713 }
1714 }
1715 % \end{macrocode}
1716 %
1717 % \subsubsection{\pkg{memoir}}
1718 % The \pkg{memoir} class redefines various internal commands to inject its
1719 % hooks and additional code. The following reinstates the kernel command and
1720 % so probably breaks various options of \pkg{memoir}, but without the
1721 % changes it errors anyway. The \pkg{footmisc} package should be used to change
1722 % for example to para footnotes.
1723 %
1724 % \begin{macrocode}
1725 \AddToHook{class/memoir/before}
1726 { \let\new@std@class@makecol\@makecol }
1727 \AddToHook{class/memoir/after}
1728 {
1729 \cs_set_eq:NN \@footnotemark \fnote_footnotemark:
1730 \cs_set_eq:NN \@makefntext\old@std@class@makefntext
1731 \cs_set_eq:NN \@makecol\new@std@class@makecol
1732 }
1733 % \end{macrocode}
1734 %
1735 % \subsubsection{\pkg{setspace}}
1736 %
1737 % It should not overwrite it any longer but use a hook, so for now we
1738 % do just that here.
1739 % \begin{macrocode}
1740 \AddToHook{package/setspace/after}
1741 {\let \@footnotetext \fnote_footnotetext:n
1742 \AddToHook{fntext}[setspace]{\let\baselinestretch\setspace@singlespace}}
1743 % \end{macrocode}
1744 %
1745 %
1746 % \subsubsection{\pkg{hyperref}}
1747 %
1748 % We use the hyperref commands for now for links. To avoid
1749 % to have to test for hyperref we provide dummies.
1750 % TODO consider to use specials to get similar spacing.
1751 % \begin{macrocode}
1752 \AtBeginDocument
1753 {
1754 \providecommand\hyper@linkstart{\@gobbletwo}
1755 \providecommand\hyper@linkend{\@empty}
1756 }
1757 % \end{macrocode}
1758 %
1759 % It must be possible to suppress the hyperlinking, both locally
1760 % and globally. hyperref should set the boolean \cs{l_fnote_link_bool}.
1761 % For now we test for the hyperref boolean (so it can be suppressed only globally).
1762 % \begin{macrocode}
1763 \AtBeginDocument
1764 {
1765 \@ifpackageloaded{hyperref}
1766 {
1767 \AssignSocketPlug{fnmark/link}{link}
1768 \AssignSocketPlug{fntext/mark/link}{link}
1769 \legacy_if:nF{Hy@hyperfootnotes}{\bool_set_false:N \l_fnote_link_bool}
1770 }
1771 {
1772 \bool_set_false:N \l_fnote_link_bool
1773 }
1774 }
1775 % \end{macrocode}
1776 %
1777 % \subsection{Tagging and hyperlink code}
1778 %
1779 % \begin{variable}{\g_fnote_id_int}
1780 % For links we need an unique id to identify footnote marks and footnotes.
1781 % It is increased both for the mark in the text and the note below
1782 % (similar to the structure numbers).
1783 % We make it public to allow the implementation of other footnote commands,
1784 % see the test-tnote-setup test.
1785 % The int is increased in the fntext/before hook,
1786 % so that the following tagging socket can pick it up.
1787 % TODO: check if the hook is the right place or if this should be static code.
1788 % \begin{macrocode}
1789 \int_new:N \g_fnote_id_int
1790 \AddToHook{fntext/before}{\int_gincr:N\g_fnote_id_int}
1791 % \end{macrocode}
1792 % \end{variable}
1793 %
1794 % \begin{macrocode}
1795
1796 % \end{macrocode}
1797 % \subsubsection{Rolemap for structure tags}
1798 % We use role-mapping to get more speaking names
1799 % in the PDF and so ease debugging. These names are already
1800 % provided by tagpdf directly.
1801 %
1802 % \subsubsection{Extending the label system}
1803 % For \cs{footref} and (perhaps later for labeled footnotes)
1804 % we must extend the label system.
1805 % Beside the normal values we also need the structure number and id of the note.
1806 % We use the in-built label hook to record properties.
1807 % We define two suitable properties: the one stores the structure number as stored in
1808 % \cs{l_@@_currentstruct_tl}, the other the id.
1809 % \begin{macrocode}
1810 \property_new:nnnn {fnote/struct}{now}{1}{\l_@@_currentstruct_tl}
1811 \property_new:nnnn {fnote/id}{now}{1}{\int_use:N\g_fnote_id_int}
1812 % \end{macrocode}
1813 %
1814 % We add a hook to the label hook. By default it does nothing
1815 % \begin{macro}{\@@_label_hook:e}
1816 % \begin{macrocode}
1817 \cs_new_protected:Npn \@@_label_hook:e #1 {}
1818 \AddToHookWithArguments{label}{ \@@_label_hook:e{#1}}
1819 % \end{macrocode}
1820 % \end{macro}
1821 % Inside a footnotetext we change the hook to store the structure number and id too.
1822 % The name of label is provided as argument in the label hook.
1823 % \begin{macrocode}
1824 \AddToHook{fntext/begin}
1825 {
1826 \cs_set_protected:Npn \@@_label_hook:e #1
1827 {
1828 \property_record:ee {@@/#1} {fnote/struct,fnote/id}
1829 }
1830 }
1831 % \end{macrocode}
1832 %
1833 % \subsubsection{Storing and retrieving reference data}
1834 % To establish the connection between a mark and a note
1835 % the mark has to store its representation, and the
1836 % note has to analyse the stored representations to get
1837 % the structure numbers of its mark. This is done
1838 % with the public function to allow similar systems (e.g.
1839 % tabular notes, other footnote series) to make use of this.
1840 %
1841 %
1842 % \begin{macro}{\fnote_class_new:nn}
1843 % This sets up a new footnote type, the first argument
1844 % is the name, the second is meant for options. Currently
1845 % it does nothing at all.
1846 % It is not necessary to set up every footnote
1847 % command as its own type!
1848 %
1849 % \begin{macrocode}
1850 \cs_new_protected:Npn \fnote_class_new:nn #1 #2 % #1 name, #2 options
1851 {
1852 \prop_new:c { g_@@_currentmarks_struct_#1_prop }
1853 \prop_new:c { g_@@_currentmarks_id_#1_prop }
1854 }
1855
1856 \fnote_class_new:nn {default}{}
1857 % \end{macrocode}
1858 % \end{macro}
1859 %
1860 %
1861 % \begin{macro}{\fnote_mark_id_gput:nn,\fnote_mark_struct_gput:nn}
1862 % This commands takes as argument the
1863 % representation of the mark,
1864 % e.g., \cs{@thefnmark} and the type (typically default should work).
1865 % \begin{macrocode}
1866 \cs_new_protected:Npn \fnote_mark_struct_gput:nn #1 #2 % #1 the representation of the mark, #2 type
1867 {
1868 \prop_gput:cen { g_@@_currentmarks_struct_#2_prop }
1869 { \tag_get:n{struct_num} }
1870 { #1 }
1871 }
1872 \cs_new_protected:Npn \fnote_mark_id_gput:nn #1 #2 % #1 the representation of the mark, #2 type
1873 {
1874 \prop_gput:cen { g_@@_currentmarks_id_#2 _prop }
1875 { \int_use:N\g_fnote_id_int }
1876 { #1 }
1877 }
1878 \cs_generate_variant:Nn \fnote_mark_struct_gput:nn {no,oo}
1879 \cs_generate_variant:Nn \fnote_mark_id_gput:nn {no,oo}
1880 % \end{macrocode}
1881 % \end{macro}
1882 %
1883 %
1884 % \begin{macro}{\fnote_mark_gpop_all:nnnN}
1885 % This command takes as first argument either id or struct,
1886 % then representation of the mark
1887 % (e.g. the content of\cs{@thefnmark}), the class (typically |default| should work)
1888 % and a sequence into which every key in the property
1889 % is stored that has the same value as the mark. The sequence is cleared first.
1890 % \begin{macrocode}
1891 \cs_new_protected:Npn \fnote_mark_gpop_all:nnnN #1 #2 #3 #4
1892 {
1893 \seq_clear:N #4
1894 \prop_set_eq:Nc \l_@@_tmpa_prop { g_@@_currentmarks_#1_#3_prop }
1895 \prop_map_inline:Nn \l_@@_tmpa_prop
1896 {
1897 \tl_if_eq:nnT {#2} { ##2 }
1898 {
1899 % \end{macrocode}
1900 % store the key (struct num or id) in the seq
1901 % \begin{macrocode}
1902 \seq_put_right:Nn #4 { ##1 }
1903 % \end{macrocode}
1904 % remove entry as used from the global prop
1905 % \begin{macrocode}
1906 \prop_gremove:cn { g_@@_currentmarks_#1_#3_prop } {##1}
1907 }
1908 }
1909 }
1910 \cs_generate_variant:Nn\fnote_mark_gpop_all:nnnN {nooN}
1911 % \end{macrocode}
1912 % \end{macro}
1913 %
1914 %
1915 %
1916 %
1917 % \subsubsection{Enabling tagging and links for the mark command}
1918 %
1919 % \begin{socketdecl}{fnmark/link}
1920 % A socket that contains the code to surround the mark in the text with a link.
1921 % It should be used in the second argument of the tagging socket as we normally
1922 % want the link to be inside the Lbl structure.
1923 %
1924 % \begin{macrocode}
1925 \NewSocket{fnmark/link}{1}
1926 % \end{macrocode}
1927 % \end{socketdecl}
1928 %
1929 % \begin{plugdecl}{link}
1930 % To handle the link around the mark we define a plug for the socket fnmark/link
1931 % \begin{macrocode}
1932 \NewSocketPlug{fnmark/link}{link}
1933 {
1934 \int_gincr:N\g_fnote_id_int
1935 \bool_if:NTF \l_@@_autodetect_bool
1936 {
1937 \fnote_mark_id_gput:oo {\@thefnmark}{\l_fnote_type_tl}
1938 \tl_set:Ne \l_@@_linktarget_tl {footnote*.\int_use:N\g_fnote_id_int}
1939 }
1940 {
1941 \tl_set:Ne \l_@@_linktarget_tl
1942 {footnote*.\property_ref:ee {@@/\l_@@_currentlabel_tl} {fnote/id}}
1943 }
1944 \bool_if:NTF \l_fnote_link_bool
1945 {
1946 \exp_args:No
1947 \hyper@linkstart
1948 { \l_fnote_link_type_tl }
1949 { \l_@@_linktarget_tl }
1950 #1
1951 \hyper@linkend
1952 }
1953 { #1 }
1954 }
1955 % \end{macrocode}
1956 % \end{plugdecl}
1957 % \begin{plugdecl}{FEMark}
1958 %
1959 % To handle the mark in the text, we define a special plug for
1960 % the socket \socket{tagsupport/fnmark} that receives
1961 % \cs{@makefntext} as its argument. At this time \cs{@thefnmark}
1962 % is already set.
1963 % \changes{v0.8p}{2026-04-28}{Use symbolic names for the tags}
1964 % \begin{macrocode}
1965 \NewTaggingSocketPlug{fnmark}{FEMark}
1966 {
1967 % \end{macrocode}
1968 % End an open mc and start the structure.
1969 % \begin{macrocode}
1970 \tag_mc_end_push:
1971 \tag_struct_begin:n { tag=\UseStructureName{fnote/mark} }
1972 % \end{macrocode}
1973 % The associated note is either auto detected
1974 % or given by the user.
1975 % If there is no autodetecting we need some id,
1976 % currently it is called \cs{l_@@_currentlabel_tl}.
1977 % the Ref is set by looking at the label value.
1978 % We must also add the current structure number to the \texttt{/Ref} of the FEnote.
1979 % Both must be delayed as we don't know if the objects of the FEnote and the mark
1980 % have already been created.
1981 % \begin{macrocode}
1982 \bool_if:NF \l_@@_autodetect_bool
1983 {
1984 \hook_gput_code:nne {tagpdf/finish/before} {tagpdf/footnote}
1985 {
1986 \exp_not:N\fnote_gput_refs:ee
1987 { \tag_get:n{struct_num} }
1988 { \property_ref:ee{ @@/\l_@@_currentlabel_tl } {fnote/struct} }
1989 }
1990 }
1991 % \end{macrocode}
1992 % And now the actual content:
1993 % \begin{macrocode}
1994 \tag_mc_begin:n{}
1995 % \end{macrocode}
1996 % For the auto detecting we store the struct num
1997 % and \cs{@thefnmark} inside a prop
1998 % TODO: this should be usable for other footnote types
1999 % which means the name of the prop shouldn't be fix.
2000 % \begin{macrocode}
2001 \bool_if:NT \l_@@_autodetect_bool
2002 {
2003 \fnote_mark_struct_gput:oo {\@thefnmark}{\l_fnote_type_tl}
2004 }
2005 % \end{macrocode}
2006 % The target in the footnote will use the current id.
2007 % This part is needed even if tagging is deactivated.
2008 % \begin{macrocode}
2009 #2
2010 \tag_mc_end:
2011 \tag_struct_end:
2012 \tag_mc_begin_pop:n{}
2013 }
2014 % \end{macrocode}
2015 % At last assign the plug:
2016 % \begin{macrocode}
2017 \AssignTaggingSocketPlug{fnmark}{FEMark}
2018 % \end{macrocode}
2019 % \end{plugdecl}
2020 %
2021 %
2022 %
2023 %
2024 % \subsubsection{The footnote text}
2025
2026 % We need a public command to append values to the Ref keys
2027 % \begin{macro}[no-user-doc]{\@@_gput_ref:nn,\fnote_gput_refs:nn,\fnote_gput_refs:ee}
2028 % \begin{macrocode}
2029 \cs_new_protected:Npn \@@_gput_ref:nn #1 #2 %#1 the structure number receiving the ref #2
2030 {
2031 \tag_struct_gput:nnn {#1}{ref_num}{#2}
2032 }
2033 \cs_new_protected:Npn \fnote_gput_refs:nn #1 #2 % pair of structure numbers
2034 {
2035 \@@_gput_ref:nn {#1}{#2}
2036 \@@_gput_ref:nn {#2}{#1}
2037 }
2038 \cs_generate_variant:Nn \fnote_gput_refs:nn {ee}
2039 % \end{macrocode}
2040 % \end{macro}
2041 %
2042 % kernel hooks for tagging
2043 % this sets the structure around the whole text
2044 %
2045 %
2046 % \begin{plugdecl}{FENote}
2047 % \begin{macrocode}
2048 \NewTaggingSocketPlug{fntext/begin}{FENote}
2049 {
2050 % \end{macrocode}
2051 % The id has been increased in the previous fntext/before hook.
2052 % \begin{macrocode}
2053 \tag_mc_end_push:
2054 % \end{macrocode}
2055 % test if a footnote is allowed, if not move up to the next sect or
2056 % the document structure.
2057 % \begin{macrocode}
2058 \tag_check_child:nnTF {FENote}{pdf2}
2059 {
2060 \tag_struct_begin:n { tag=\UseStructureName{fnote/note}}
2061 }
2062 {
2063 \tag_struct_begin:n
2064 {
2065 tag=\UseStructureName{fnote/note},
2066 % \end{macrocode}
2067 % We add 0 for now to ensure to get a number even if the sec code is not loaded
2068 % or if the seq is empty (which it shouldn't unless there is an coding error)
2069 % \begin{macrocode}
2070 parent=\int_max:nn{2}{\tag_get:n{current_Sect}+0}
2071 }
2072 }
2073 % \end{macrocode}
2074 % Store the current structure number for labels.
2075 % \begin{macrocode}
2076 \tl_set:Ne \l_@@_currentstruct_tl { \tag_get:n{struct_num} }
2077 % \end{macrocode}
2078 %
2079 % After we have opened the structure we can use the |struct num| to
2080 % try to detect the connected marks. As with the marks we assume that sometimes
2081 % no auto detection is done.
2082 % \begin{macrocode}
2083 \bool_if:NTF \l_@@_autodetect_bool
2084 {
2085 % \end{macrocode}
2086 % Find open marks with identical \cs{@thefnmark}:
2087 % \begin{macrocode}
2088 \fnote_mark_gpop_all:nooN {struct}{ \@thefnmark }{ \l_fnote_type_tl } \l_@@_currentrefs_seq
2089 % \end{macrocode}
2090 % Then we store the object numbers of the marks in the /Ref of the FENote structure
2091 % and the number of the FEnote into the marks structure:
2092 % \begin{macrocode}
2093 \seq_map_inline:Nn \l_@@_currentrefs_seq
2094 {
2095 \fnote_gput_refs:ee {##1}{ \l_@@_currentstruct_tl }
2096 }
2097 }
2098 % \end{macrocode}
2099 % If no auto detection is done
2100 % \begin{NOTE}{UF}
2101 % TODO: decide what to do here: some label in the optional argument?
2102 % or refer to \cs{footref}
2103 % \end{NOTE}
2104 % \begin{macrocode}
2105 {%no auto
2106
2107 }
2108 }
2109 % \end{macrocode}
2110 % This finish the setup of the tagging structure.
2111 % \end{plugdecl}
2112 %
2113 % \begin{plugdecl}{FENote}
2114 % This is the plug for the socket at the end of the structure.
2115 % \begin{macrocode}
2116 \NewTaggingSocketPlug{fntext/end}{FENote}
2117 {
2118 \tag_struct_end:
2119 \tag_mc_begin_pop:n{}
2120 }
2121 % \end{macrocode}
2122 %\end{plugdecl}
2123 % At last assign the plugs:
2124 % \begin{macrocode}
2125 \AssignTaggingSocketPlug{fntext/begin}{FENote}
2126 \AssignTaggingSocketPlug{fntext/end}{FENote}
2127 % \end{macrocode}
2128 %
2129 %
2130 %
2131 % \begin{socketdecl}{fntext/mark/link}
2132 % This socket adds targets for links before the mark of the footnote in the note text.
2133 % It should be used in hmode.
2134 % \begin{macrocode}
2135 \NewSocket{fntext/mark/link}{0}
2136 % \end{macrocode}
2137 % \end{socketdecl}
2138 % \begin{plugdecl}{link}
2139 % We create a link target for every related mark. The name is
2140 % \texttt{footnote*.}\meta{id}. We also add a link
2141 % target for the current id (for \cs{footref}).
2142 % TODO: perhaps it should be always active.
2143 % \begin{macrocode}
2144 \NewSocketPlug{fntext/mark/link}{link}
2145 {
2146 \fnote_mark_gpop_all:nooN {id}{ \@thefnmark }{ \l_fnote_type_tl } \l_@@_currentrefs_seq
2147 \seq_map_inline:Nn\l_@@_currentrefs_seq {\MakeLinkTarget*{footnote*.##1}}
2148 \MakeLinkTarget*{footnote*.\int_use:N\g_fnote_id_int}
2149 }
2150 % \end{macrocode}
2151 % \end{plugdecl}
2152 %
2153 % The kernel socket \socket{tagsupport/fntext/mark} is responsible for
2154 % tagging the mark in the note. We use it to surround
2155 % the mark with the needed tagging commands.
2156 %
2157 % TODO check if additional kernel configuration points are needed.
2158 % If yes, what about the paragraph start and the paratagging??
2159
2160 % \begin{plugdecl}{FENoteLbl}
2161 % This plug creates the label in the note on the bottom.
2162 % It also adds link targets for the hyperlinking.
2163 % \begin{macrocode}
2164 \NewTaggingSocketPlug{fntext/mark}{FENoteLbl}
2165 {
2166 \tag_mc_end_push:
2167 % \end{macrocode}
2168 % Now we add the tagging commands. We move the structure of the label to
2169 % the begin of the footnote structure.
2170 % \begin{macrocode}
2171 \tag_struct_begin:n { tag=\UseStructureName{fnote/note/label},parent=\l_@@_currentstruct_tl,firstkid }
2172 \tag_mc_begin:n {}
2173 #2
2174 \tag_mc_end:
2175 \tag_struct_end:
2176 \tag_mc_begin_pop:n{}
2177 }
2178 % \end{macrocode}
2179 %
2180 % \begin{macrocode}
2181 \AssignSocketPlug{tagsupport/fntext/mark}{FENoteLbl}
2182 % \end{macrocode}
2183 % \end{plugdecl}
2184 %
2185 %
2186 % \begin{plugdecl}{FENotetext}
2187 %
2188 % This plug is for the kernel socket \socket{tagsupport/fntext/text}
2189 % around the actual note text when doing tagging.
2190 % Currently it only adds an MC chunk.
2191 %
2192 % TODO Should it set a mc or could it rely on the content?
2193 % \begin{macrocode}
2194 \NewTaggingSocketPlug{fntext/text}{FENotetext}
2195 {
2196 \tag_mc_end_push:
2197 \tag_mc_begin:n{}
2198 #2
2199 \tag_mc_end:
2200 \tag_mc_begin_pop:n{}
2201 }
2202 % \end{macrocode}
2203 %
2204 % \begin{macrocode}
2205 \AssignTaggingSocketPlug{fntext/text}{FENotetext}
2206 % \end{macrocode}
2207 % \end{plugdecl}
2208 %-------------------------------------
2209
2210 % \begin{macrocode}
2211 \ExplSyntaxOff
2212 %</kernel>
2213 % \end{macrocode}
2214 % \begin{macrocode}
2215 %<@@=>
2216 % \end{macrocode}
2217 %
2218 % \section{Reimplementing the \pkg{footmisc} package}
2219 % \changes{v0.8p}{2026-04-28}{Do not tag \cs{multfootsep} in \pkg{footmisc} as artifact, it is content}
2220 % \begin{macrocode}
2221 %<*footmisc>
2222 %%
2223 %% Copyright (c) 1995-2011 Robin Fairbairns
2224 %% Copyright (c) 2018-2023 Robin Fairbairns, Frank Mittelbach
2225 %%
2226 %% This file is part of the `latex-lab Bundle'.
2227 %% --------------------------------------------
2228 %%
2229 %% It may be distributed and/or modified under the
2230 %% conditions of the LaTeX Project Public License, either version 1.3c
2231 %% of this license or (at your option) any later version.
2232 %% The latest version of this license is in
2233 %% https://www.latex-project.org/lppl.txt
2234 %% and version 1.3c or later is part of all distributions of LaTeX
2235 %% version 2008 or later.
2236 %%
2237 %% This work has the LPPL maintenance status 'maintained'.
2238 %%
2239 \NeedsTeXFormat{LaTeX2e}
2240 \providecommand\DeclareRelease[3]{}
2241 \providecommand\DeclareCurrentRelease[2]{}
2242
2243 \DeclareRelease{v5}{2011-06-06}{footmisc-2011-06-06.sty}
2244 \DeclareCurrentRelease{}{2022-02-14}
2245 \ProvidesPackage{latex-lab-footmisc}%
2246 [2025/02/20 v6.0e
2247 a miscellany of footnote facilities -- latex-lab version%
2248 ]
2249
2250 \NeedsTeXFormat{LaTeX2e}[2020/10/01]
2251 \newtoks\FN@temptoken
2252 \providecommand\protected@writeaux{%
2253 \protected@write\@auxout
2254 }
2255 \def\l@advance@macro{\@@dvance@macro\edef}
2256 \def\@@dvance@macro#1#2#3{\expandafter\@tempcnta#2\relax
2257 \advance\@tempcnta#3\relax
2258 #1#2{\the\@tempcnta}%
2259 }
2260 \let\@advance@macro\l@advance@macro
2261 \DeclareOption{symbol}{\renewcommand\thefootnote{\fnsymbol{footnote}}}
2262 \newif\ifFN@robust \FN@robustfalse
2263 \DeclareOption{symbol*}{%
2264 \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
2265 \FN@robusttrue
2266 \AtEndOfPackage{\setfnsymbol{lamport*-robust}}%
2267 }
2268 \newif\ifFN@para \FN@parafalse
2269 \DeclareOption{para}{%
2270 % \end{macrocode}
2271 % Options are executed in the order of declaration, thus no point in
2272 % checking for side option as footmisc did in the past
2273 % \begin{macrocode}
2274 % \PackageError{footmisc}{Option "\CurrentOption" incompatible with
2275 % option "side"}%
2276 % {I shall ignore "\CurrentOption"}%
2277 \FN@paratrue
2278 \setlength\footnotemargin{-\maxdimen} % default when para is used
2279 }
2280 % \end{macrocode}
2281 %
2282 % \begin{macrocode}
2283 \DeclareOption{side}{\ifFN@para
2284 \PackageError{footmisc}{Option "\CurrentOption" incompatible with
2285 option "para"}%
2286 {I shall ignore "\CurrentOption"}%
2287 \else
2288 \AddToHook{fntext/para}{%
2289 \hsize\marginparwidth % correct the default \hsize
2290 \footnotesep\z@ % don't add a default separation
2291 }
2292 \AssignSocketPlug{fntext/process}{side}
2293 % \AssignSocketPlug{fntext/make}{default}
2294 \AssignSocketPlug{fntext/begin}{noop}
2295 \AssignSocketPlug{fntext/end}{noop}
2296 \fi
2297 }
2298 \let\footnotelayout\@empty
2299 \DeclareOption{ragged}{%
2300 \@ifundefined{RaggedRight}%
2301 {\renewcommand\footnotelayout{\linepenalty50 \raggedright}}%
2302 {\renewcommand\footnotelayout{\linepenalty50 \RaggedRight}}%
2303 }
2304 \newif\ifFN@perpage
2305 \FN@perpagefalse
2306 \DeclareOption{perpage}{%
2307 \FN@perpagetrue
2308 }
2309 \newif\ifFN@fixskip \FN@fixskipfalse
2310
2311 \let\FN@bottomcases\thr@@
2312 \newif\ifFN@abovefloats \FN@abovefloatstrue
2313 \DeclareOption{bottom}{%
2314 \let\FN@bottomcases\@ne
2315 \FN@abovefloatsfalse
2316 \FN@fixskiptrue
2317 }
2318 \DeclareOption{bottomfloats}{%
2319 \let\FN@bottomcases\tw@
2320 \FN@abovefloatstrue \FN@fixskiptrue
2321 }
2322 \DeclareOption{abovefloats}{\FN@abovefloatstrue \FN@fixskiptrue}
2323 \DeclareOption{belowfloats}{\FN@abovefloatsfalse \FN@fixskiptrue}
2324 \DeclareOption{marginal}{%
2325 \footnotemargin-0.8em\relax
2326 }
2327 \DeclareOption{flushmargin}{%
2328 \footnotemargin0pt\relax
2329 }
2330 \newif\ifFN@hangfoot \FN@hangfootfalse
2331 \DeclareOption{hang}{%
2332 \FN@hangfoottrue
2333 }
2334 \newcommand*\hangfootparskip{0.5\baselineskip}
2335 \newcommand*\hangfootparindent{0em}%
2336 \DeclareOption{norule}{%
2337 \renewcommand\footnoterule{}%
2338 \advance\skip\footins 4\p@\@plus2\p@\relax
2339 }
2340 \DeclareOption{splitrule}{%
2341 \gdef\split@prev{0}
2342 \let\pagefootnoterule\footnoterule
2343 \let\mpfootnoterule\footnoterule
2344 \def\splitfootnoterule{\kern-3\p@ \hrule \kern2.6\p@}
2345 \def\footnoterule{\relax
2346 \ifx \@listdepth\@mplistdepth
2347 \mpfootnoterule
2348 \else
2349 \ifnum\split@prev=\z@
2350 \pagefootnoterule
2351 \else
2352 \splitfootnoterule
2353 \fi
2354 \xdef\split@prev{\the\insertpenalties}%
2355 \fi
2356 }%
2357 }
2358 \newif\ifFN@stablefootnote \FN@stablefootnotefalse
2359 \DeclareOption{stable}{\FN@stablefootnotetrue}
2360 \newif\ifFN@multiplefootnote \FN@multiplefootnotefalse
2361 \DeclareOption{multiple}{\FN@multiplefootnotetrue}
2362 \ProcessOptions
2363 % \end{macrocode}
2364 %
2365 % Footnote box layout for para footnotes;
2366 % this would also be the hook to support dblfootnotes (from the
2367 % \texttt{dblfnote} package if we integrate that).
2368 % \begin{macrocode}
2369 \ifFN@para
2370 \NewSocketPlug{build/column/footnotes}{para}{%
2371 \global\setbox\footins\vbox{\FN@makefootnoteparagraph}%
2372 }
2373 \AssignSocketPlug{build/column/footnotes}{para}
2374 \fi
2375 % \end{macrocode}
2376 %
2377 % \begin{macrocode}
2378 \ifFN@fixskip
2379 \def\@outputbox@removebskip{%
2380 \ifx\@textbottom\relax \else
2381 \@outputbox@append{%
2382 \@tempskipa\lastskip
2383 \ifnum \gluestretchorder\@tempskipa>\z@
2384 \vskip-\@tempskipa
2385 \xdef\@outputbox@reinsertbskip
2386 {\noexpand\@outputbox@append{\vskip\the\@tempskipa}}%
2387 \else
2388 \global\let\@outputbox@reinsertbskip\relax
2389 \fi
2390 }%
2391 \fi
2392 }
2393 \let\@outputbox@reinsertbskip\relax
2394 \else
2395 \let\@outputbox@removebskip \relax
2396 \let\@outputbox@reinsertbskip\relax
2397 \fi
2398 % \end{macrocode}
2399 %
2400 %
2401 % \begin{macrocode}
2402 \ifcase \FN@bottomcases\relax
2403 \ERROR
2404 \or %1 bottom option
2405 \ifFN@abovefloats
2406 \AssignSocketPlug {build/column/outputbox}{space-footnotes-floats}
2407 \else
2408 \AssignSocketPlug {build/column/outputbox}{floats-space-footnotes}
2409 \fi
2410 \or %2 bottomfloats
2411 \ifFN@abovefloats
2412 \AssignSocketPlug {build/column/outputbox}{footnotes-space-floats}
2413 \else
2414 \AssignSocketPlug {build/column/outputbox}{space-floats-footnotes}
2415 \fi
2416 \or %3 neither bottom nor bottomfloats
2417 \ifFN@abovefloats
2418 \AssignSocketPlug {build/column/outputbox}{footnotes-floats}
2419 \else
2420 \AssignSocketPlug {build/column/outputbox}{floats-footnotes}
2421 \fi
2422 \else
2423 \ERROR
2424 \fi
2425
2426 % next can be dropped when cleaned up
2427 \newif\ifFN@setspace
2428 \@ifpackageloaded{setspace}%
2429 {%
2430 \FN@setspacetrue
2431 \@ifclassloaded{memoir}%
2432 {%
2433 \AddToHook{fntext}{\let\baselinestretch\m@m@singlespace}%
2434 \let\FN@baselinestretch\m@m@singlespace
2435 }%
2436 {%
2437 % \AddToHook{fntext}{\let\baselinestretch\setspace@singlespace}%
2438 \let\FN@baselinestretch\setspace@singlespace
2439 }%
2440 }%
2441 {%
2442 \FN@setspacefalse
2443 }
2444
2445
2446
2447 \ifFN@para
2448
2449 % \AssignSocketPlug{fntext/process}{default}
2450 \AssignSocketPlug{fntext/make}{para}
2451 \AssignSocketPlug{fntext/begin}{noop}
2452 \AssignSocketPlug{fntext/end}{para}
2453
2454 \fi
2455
2456
2457
2458 \ifFN@para
2459 \let\FN@tempboxa\@tempboxa
2460 \newbox\FN@tempboxb
2461 \newbox\FN@tempboxc
2462 \newskip\footglue \footglue=1em plus.3em minus.3em
2463
2464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2465 \newdimen\footnotebaselineskip
2466
2467 % establish late:
2468
2469 \AddToHook{begindocument/before} {%
2470 {%
2471 \footnotesize
2472 \global\footnotebaselineskip=\normalbaselineskip
2473 }%
2474 }
2475 % \end{macrocode}
2476 % The coding is based on David Kastrup's improvement to Don Knuth's
2477 % original implementation. You find in the \TeX{}book if you own
2478 % the latest edition.
2479 % \begin{macrocode}
2480
2481 \long\def\FN@makefootnoteparagraph{%
2482 \FN@setfootnoteparawidth
2483 \@parboxrestore
2484 \baselineskip=\footnotebaselineskip
2485 \unvbox\footins \FN@removehboxes
2486 \RawParEnd
2487 }
2488 \def\FN@removehboxes{\setbox\FN@tempboxa\lastbox
2489 \ifhbox\FN@tempboxa{\FN@removehboxes}%
2490 \unhbox\FN@tempboxa
2491 \else
2492 \RawNoindent
2493 \rule\z@\footnotesep
2494 \fi
2495 }
2496 \fi
2497
2498
2499 \@ifpackageloaded{multicol}
2500 {\def\FN@setfootnoteparawidth
2501 {\hsize\ifnum\doublecol@number>\@ne
2502 \textwidth
2503 \else \columnwidth \fi}}
2504 {\def\FN@setfootnoteparawidth{\hsize\columnwidth}}
2505
2506 \ifFN@perpage
2507 \RequirePackage{perpage}
2508 \MakePerPage{footnote}
2509 % \end{macrocode}
2510 % Fix a bug in perpage \ldots
2511 % \begin{macrocode}
2512 \def\@stpelt#1{\global\csname c@#1\endcsname \m@ne
2513 \stepcounter{#1}%
2514 \pp@fix@MakePerPage{#1}%
2515 }
2516 \def\pp@fix@MakePerPage#1{%
2517 \ifnum \value{#1}>\z@
2518 \addtocounter{#1}\m@ne\fi
2519 }
2520 % \end{macrocode}
2521 % The above code may look a bit odd: the \cs{stepcounter} sets the
2522 % counter to zero and then we alter it if it is not zero. The
2523 % reason is that \cs{stepcounter} resets other counters and when
2524 % perpage is loaded this results in updating counters on the reset
2525 % list to 1 (or to a higher starting value if \cs{MakePerPage} is
2526 % used with an optional argument, which is precisely the problem
2527 % here). By subtracting 1 in that case we set it back to 1 lower
2528 % than the starting value.
2529 %
2530 % But to make this fully work we also need to update a support
2531 % command in \pkg{perpage}:
2532 % \begin{macrocode}
2533 \def\pp@cl@end@iii\stepcounter#1\pp@fix@MakePerPage#2{}
2534 \fi
2535
2536
2537 \ifFN@para
2538
2539 % This can use the default interface, except that a negative value for
2540 % \footnotemargin makes little sense, so we test for this and warn if
2541 % necessary. But -\maxdimen is ok again, so would need to be a little bit more elaborate.
2542 %
2543
2544 %\AddToHook{fntext/para}{
2545 % \ifdim \footnotemargin >\z@ \else
2546 % \PackageWarningNoline{footmisc}{Option 'para' needs positive \noexpand\footnotemargin}%
2547 % \footnotemargin 1.8em\relax
2548 % \fi
2549 %}
2550
2551
2552 \AddToHook{fntext/begin}{\nobreak \hspace{.2em}}
2553
2554 \else
2555
2556 \ifFN@hangfoot
2557 \long\def\footmisc@hang@makefntext#1{%
2558 \bgroup
2559 \SuspendTagging{footmisc}%
2560 \setbox\@tempboxa\hbox{%
2561 \ifdim\footnotemargin>\z@
2562 \hb@xt@\footnotemargin{\@makefnmark\hss}%
2563 \else
2564 \@makefnmark
2565 \fi
2566 }%
2567 \leftmargin\wd\@tempboxa
2568 \rightmargin\z@
2569 \linewidth \columnwidth
2570 \advance \linewidth -\leftmargin
2571 \parshape \@ne \leftmargin \linewidth
2572 \footnotesize
2573 \parskip\hangfootparskip\relax
2574 % \end{macrocode}
2575 % The setting of \cs{parindent} has to happen prior to calling
2576 % \cs{leavevmode} (which happens below to support
2577 % tagging). Originally, this was done later so was moved here where
2578 % we haven't started hmode yet.
2579 % \begin{macrocode}
2580 \parindent\hangfootparindent\relax
2581 \@setpar{{\@@par}}%
2582 \ResumeTagging{footmisc}%
2583 \leavevmode
2584 % \end{macrocode}
2585 % after leaving the vmode we can set the link targets. They should
2586 % be in the footnote structure.
2587 % \begin{macrocode}
2588 \UseSocket{fntext/mark/link}%
2589 % \end{macrocode}
2590 % Typesetting the mark twice means that one can't have any material
2591 % inside that gets unhappy in that case. That shouldn't be a
2592 % problem, but perhaps we have to come up with a more elaborate
2593 % solution in the end.
2594 % \begin{macrocode}
2595 \UseTaggingSocket{fntext/mark}{}%
2596 {\llap{%
2597 \ifdim\footnotemargin>\z@
2598 \hb@xt@\footnotemargin{\@makefnmark\hss}%
2599 \else
2600 \@makefnmark
2601 \fi
2602 }}%
2603 \footnotelayout#1%
2604 \par
2605 \egroup
2606 }
2607 % \end{macrocode}
2608 % Defined in a roundabout way so that we can test for it when
2609 % patching classes that are not updated.
2610 % \begin{macrocode}
2611 \let \@makefntext \footmisc@hang@makefntext
2612
2613 \else
2614
2615 % This is now using the default interface:
2616 %
2617 % \long\def\@makefntext#1{%
2618 % \parindent1em
2619 % \noindent
2620 % \ifdim\footnotemargin>\z@
2621 % \hb@xt@ \footnotemargin{\hss\@makefnmark}%
2622 % \else
2623 % \ifdim\footnotemargin=\z@
2624 % \llap{\@makefnmark}%
2625 % \else
2626 % \llap{\hb@xt@ -\footnotemargin{\@makefnmark\hss}}%
2627 % \fi
2628 % \fi
2629 % \footnotelayout#1%
2630 % }
2631
2632 \fi
2633 \fi
2634
2635
2636
2637
2638 \ifFN@multiplefootnote
2639 \providecommand*{\multiplefootnotemarker}{3sp}
2640 \providecommand*{\multfootsep}{,}
2641 \AddToHook{fnmark} {\FN@mf@check}
2642 \AddToHook{fnmark/end} {\FN@mf@prepare}
2643 %
2644 \def\FN@mf@prepare{%
2645 \kern-\multiplefootnotemarker
2646 \kern\multiplefootnotemarker\relax
2647 }
2648 \def\FN@mf@check{%
2649 \ifdim\lastkern=\multiplefootnotemarker\relax
2650 %?? is that necessary or even correct ??
2651 \edef\@x@sf{\the\spacefactor}%
2652 %?? shouldn't that be 2 unkerns ?? (none would also be ok)
2653 \unkern % new
2654 \unkern
2655 \textsuperscript{\multfootsep}%
2656 \spacefactor\@x@sf\relax
2657 \fi
2658 }
2659 \else
2660 \let\FN@mf@prepare\relax
2661 \fi
2662 \ifFN@stablefootnote
2663 \let\FN@sf@@footnote\footnote
2664 \def\footnote{\ifx\protect\@typeset@protect
2665 \expandafter\FN@sf@@footnote
2666 \else
2667 \expandafter\FN@sf@gobble@opt
2668 \fi
2669 }
2670 \edef\FN@sf@gobble@opt{\noexpand\protect
2671 \expandafter\noexpand\csname FN@sf@gobble@opt \endcsname}
2672 \expandafter\def\csname FN@sf@gobble@opt \endcsname{%
2673 \@ifnextchar[%]
2674 \FN@sf@gobble@twobracket
2675 \@gobble
2676 }
2677 \def\FN@sf@gobble@twobracket[#1]#2{}
2678 \let\FN@sf@@footnotemark\footnotemark
2679 \def\footnotemark{\ifx\protect\@typeset@protect
2680 \expandafter\FN@sf@@footnotemark
2681 \else
2682 \expandafter\FN@sf@gobble@optonly
2683 \fi
2684 }
2685 \edef\FN@sf@gobble@optonly{\noexpand\protect
2686 \expandafter\noexpand\csname FN@sf@gobble@optonly \endcsname}
2687 \expandafter\def\csname FN@sf@gobble@optonly \endcsname{%
2688 \@ifnextchar[%]
2689 \FN@sf@gobble@bracket
2690 {}%
2691 }
2692 \def\FN@sf@gobble@bracket[#1]{}
2693 \fi
2694 \newcommand\setfnsymbol[1]{%
2695 \@bsphack
2696 \@ifundefined{FN@fnsymbol@#1}%
2697 {%
2698 \PackageError{footmisc}{Symbol style "#1" not known}%
2699 \@eha
2700 }{%
2701 \expandafter\let\expandafter\@fnsymbol\csname
2702 FN@fnsymbol@#1\endcsname
2703 }%
2704 \@esphack
2705 }
2706 \let\FN@fnsymbol@lamport\@fnsymbol
2707 \newif\if@tempswb
2708 \DeclareDocumentCommand\DefineFNsymbols {smO{text}m}{%
2709 \expandafter\ifx\csname FN@fnsymbol@#2\endcsname\relax
2710 \PackageInfo{footmisc}{Declaring symbol style #2}%
2711 \else
2712 \PackageWarning{footmisc}{Redeclaring symbol style #2}%
2713 \fi
2714 \toks@{}%
2715 \def\@tempb{\end}%
2716 \FN@build@symboldef#4\end
2717 \def\@tempc{math}%
2718 \def\@tempd{#3}%
2719 \expandafter\xdef\csname FN@fnsymbol@#2\endcsname##1{%
2720 \ifx\@tempc\@tempd
2721 \noexpand\ensuremath
2722 \else
2723 \noexpand\nfss@text
2724 \fi
2725 {%
2726 \noexpand\ifcase##1%
2727 \the\toks@
2728 \noexpand\else
2729 \IfBooleanTF#1{\noexpand\@ctrerr}%
2730 {\noexpand\FN@orange##1}%
2731 \noexpand\fi
2732 }%
2733 }%
2734 }
2735 \def\FN@build@symboldef#1{%
2736 \def\@tempa{#1}%
2737 \ifx\@tempa\@tempb
2738 \else
2739 \toks@\expandafter{\the\toks@\or#1}%
2740 \expandafter\FN@build@symboldef
2741 \fi
2742 }
2743 \DeclareDocumentCommand\DefineFNsymbolsTM {smm}{%
2744 \expandafter\ifx\csname FN@fnsymbol@#2\endcsname\relax
2745 \PackageInfo{footmisc}{Declaring symbol style #2}%
2746 \else
2747 \PackageWarning{footmisc}{Redeclaring symbol style #2}%
2748 \fi
2749 \toks@{}%
2750 \def\@tempb{\end}%
2751 \FN@build@symboldefTM#3\end\@null
2752 \expandafter\xdef\csname FN@fnsymbol@#2\endcsname##1{%
2753 \noexpand\ifcase##1%
2754 \the\toks@
2755 \noexpand\else
2756 \IfBooleanTF#1{\noexpand\@ctrerr}%
2757 {\noexpand\FN@orange##1}%
2758 \noexpand\fi
2759 }%
2760 }
2761 \def\FN@build@symboldefTM#1#2{%
2762 \def\@tempa{#1}%
2763 \ifx\@tempa\@tempb
2764 \else
2765 \toks@\expandafter{\the\toks@\or\TextOrMath{#1}{#2}}%
2766 \expandafter\FN@build@symboldefTM
2767 \fi
2768 }
2769 \def\FN@orange#1{%
2770 \ifFN@robust
2771 \@arabic#1%
2772 \@bsphack
2773 \PackageInfo{footmisc}{Footnote number \number#1 out of range}%
2774 \protect\@fnsymbol@orange
2775 \@esphack
2776 \else \@ctrerr \fi
2777 }
2778 \global\let\@diagnose@fnsymbol@orange\relax
2779 \AtEndDocument{\@diagnose@fnsymbol@orange}
2780 \def\@fnsymbol@orange{%
2781 \gdef\@diagnose@fnsymbol@orange{%
2782 \PackageWarningNoLine{footmisc}{Some footnote number(s)
2783 were out of range
2784 \MessageBreak
2785 see log for details%
2786 }%
2787 }%
2788 }
2789 \DefineFNsymbolsTM{bringhurst}{%
2790 \textasteriskcentered *%
2791 \textdagger \dagger
2792 \textdaggerdbl \ddagger
2793 \textsection \mathsection
2794 \textbardbl \|%
2795 \textparagraph \mathparagraph
2796 }%
2797 \DefineFNsymbolsTM{chicago}{%
2798 \textasteriskcentered *%
2799 \textdagger \dagger
2800 \textdaggerdbl \ddagger
2801 \textsection \mathsection
2802 \textbardbl \|%
2803 \#\#%
2804 }%
2805 \DefineFNsymbolsTM{wiley}{%
2806 \textasteriskcentered *%
2807 {\textasteriskcentered\textasteriskcentered}{**}%
2808 \textdagger \dagger
2809 \textdaggerdbl \ddagger
2810 \textsection \mathsection
2811 \textparagraph \mathparagraph
2812 \textbardbl \|%
2813 }%
2814 \DefineFNsymbolsTM{lamport-robust}{%
2815 \textasteriskcentered *%
2816 \textdagger \dagger
2817 \textdaggerdbl \ddagger
2818 \textsection \mathsection
2819 \textparagraph \mathparagraph
2820 \textbardbl \|%
2821 {\textasteriskcentered\textasteriskcentered}{**}%
2822 {\textdagger\textdagger}{\dagger\dagger}%
2823 {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
2824 }
2825 \DefineFNsymbolsTM*{lamport*}{%
2826 \textasteriskcentered *%
2827 \textdagger \dagger
2828 \textdaggerdbl \ddagger
2829 \textsection \mathsection
2830 \textparagraph \mathparagraph
2831 \textbardbl \|%
2832 {\textasteriskcentered\textasteriskcentered}{**}%
2833 {\textdagger\textdagger}{\dagger\dagger}%
2834 {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
2835 {\textsection\textsection}{\mathsection\mathsection}%
2836 {\textparagraph\textparagraph}{\mathparagraph\mathparagraph}%
2837 {\textasteriskcentered\textasteriskcentered\textasteriskcentered}{***}%
2838 {\textdagger\textdagger\textdagger}{\dagger\dagger\dagger}%
2839 {\textdaggerdbl\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger\ddagger}%
2840 {\textsection\textsection\textsection}%%
2841 {\mathsection\mathsection\mathsection}%
2842 {\textparagraph\textparagraph\textparagraph}%%
2843 {\mathparagraph\mathparagraph\mathparagraph}%
2844 }
2845 \setfnsymbol{lamport*}
2846 \DefineFNsymbolsTM{lamport*-robust}{%
2847 \textasteriskcentered *%
2848 \textdagger \dagger
2849 \textdaggerdbl \ddagger
2850 \textsection \mathsection
2851 \textparagraph \mathparagraph
2852 \textbardbl \|%
2853 {\textasteriskcentered\textasteriskcentered}{**}%
2854 {\textdagger\textdagger}{\dagger\dagger}%
2855 {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
2856 {\textsection\textsection}{\mathsection\mathsection}%
2857 {\textparagraph\textparagraph}{\mathparagraph\mathparagraph}%
2858 {\textasteriskcentered\textasteriskcentered\textasteriskcentered}{***}%
2859 {\textdagger\textdagger\textdagger}{\dagger\dagger\dagger}%
2860 {\textdaggerdbl\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger\ddagger}%
2861 {\textsection\textsection\textsection}%%
2862 {\mathsection\mathsection\mathsection}%
2863 {\textparagraph\textparagraph\textparagraph}%%
2864 {\mathparagraph\mathparagraph\mathparagraph}%
2865 }
2866 \newcommand\mpfootnotemark{%
2867 \@ifnextchar[%]
2868 \@xmpfootnotemark
2869 {%
2870 \stepcounter\@mpfn
2871 \protected@xdef\@thefnmark{\thempfn}%
2872 \@footnotemark
2873 }%
2874 }
2875 \def\@xmpfootnotemark[#1]{%
2876 \begingroup
2877 \csname c@\@mpfn\endcsname #1\relax
2878 \unrestored@protected@xdef\@thefnmark{\thempfn}%
2879 \endgroup
2880 \@footnotemark
2881 }
2882 % \end{macrocode}
2883 %
2884 % \begin{macrocode}
2885 \endinput
2886 %</footmisc>
2887 % \end{macrocode}
2888 % \Finale
2889 %