Debian Codegraph @

texmf-dist/source/latex/footnotehyper/footnotehyper.dtx

raw
1 % -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" ; time-stamp-active: nil -*-
2 %<*none>
3 \def\dtxtimestamp {Time-stamp: <15-11-2025 at 11:01:49 CET>}
4 %</none>
5 %<*!readme>
6 %%
7 %% Package: footnotehyper
8 %% Version: 1.1f (2025/11/15)
9 %% License: LPPL 1.3c
10 %% Copyright (C) 2016-2021, 2025 Jean-Francois Burnol
11 %% <jfbu at free dot fr>.
12 %%
13 %</!readme>
14 %<*tex>
15 \def\pkgname {footnotehyper}
16 \def\pkgdate {2025/11/15}
17 \def\docdate {2025/11/15}
18 \def\pkgversion {v1.1f}
19 \def\pkgdescription {hyperref aware footnote.sty (JFB)}
20 %</tex>
21 %<*none>
22 % Definition of \pkgLicense
23 \begingroup% cette méthode ne marcherait pas avec caractères en dehors de 32-127
24 \long\def\firstofone #1{#1}\catcode1=14\catcode2=0
25 \catcode`\%=12\catcode`\_=12\endlinechar13\catcode13=13 ^^A
26 \catcode32=13\catcode`\\=12^^Brelax^^A
27 ^^Bfirstofone{^^Bendgroup^^Bdef^^BpkgLicense^^A
28 {% Package: footnotehyper
29 % Version: 1.1f (2025/11/15)
30 % License: LPPL 1.3c
31 % Copyright (C) 2016-2021, 2025 Jean-Francois Burnol
32 %% <jfbu at free dot fr>.
33 %
34 % This Work may be distributed and/or modified under the conditions
35 % of the LaTeX Project Public License, version 1.3c. This version of
36 % this license is in:
37 %
38 % > <http://www.latex-project.org/lppl/lppl-1-3c.txt>
39 %
40 % and the latest version of this license is in:
41 %
42 % > <http://www.latex-project.org/lppl.txt>
43 %
44 % Version 1.3 or later is part of all distributions of
45 % LaTeX version 2005/12/01 or later.
46 %
47 % The Author of this Work is: Jean-Francois Burnol `<jfbu at free dot fr>`
48 %
49 % This Work consists of the main source file footnotehyper.dtx and the
50 % derived files footnotehyper.sty, footnotehyper.ins, footnotehyper.tex,
51 % footnotehyper.pdf, footnotehyper.dvi.
52 }}%
53 \begingroup\catcode1 0 \catcode`\\ 12
54 ^^Aiffalse
55 %</none>
56 %<*readme>
57 <!-- -->
58
59 Source: footnotehyper.dtx (v1.1f 2025/11/15)
60 Author: Jean-Francois Burnol
61 Info: hyperref aware footnote.sty
62 License: LPPL 1.3c
63 Copyright (C) 2016-2021, 2025 Jean-Francois Burnol
64 <jfbu at free dot fr>.
65
66
67 ABSTRACT
68 ========
69
70 The `footnote` package by Mark Wooding (`1997/01/28` `1.13`)
71 allows to gather footnotes (`\begin{savenotes}`) and later insert
72 them (after `\end{savenotes}`) at the bottom of the page, even
73 if the intervening material consists of tabulars, minipages or
74 framed contents for example. One can also use the
75 `\savenotes/\spewnotes` syntax.
76
77 Also, `footnote.sty` provides a `footnote` environment which
78 allows to insert verbatim material.
79
80 Earlier releases of the present `footnotehyper` package added
81 patches for `hyperref` compatibility and some bugfixes, addressing
82 in particular the incompatibility with `color/xcolor`, and with
83 `babel-frenchb`, and also fixing the `footnote` environment with
84 optional argument `[NUM]`. Since `v0.99` all macros are defined
85 internally and the `footnote` package is not loaded at all.
86
87 The same user interface is kept. Since `v1.0` it is possible to
88 use `footnotehyper` also in absence of `hyperref` or when the latter is
89 loaded with its `hyperfootnotes=false` option. The order of loading of
90 `footnotehyper` and `hyperref` is inconsequential.
91
92 INSTALLATION
93 ============
94
95 The recommended way is to first extract the package (.sty)
96 and driver (.tex) files from footnotehyper.dtx via
97
98 tex footnotehyper.dtx
99
100 and then produce the documentation via
101
102 latex footnotehyper.tex (twice)
103 dvipdfmx footnotehyper.dvi
104
105 It is also possible to produce simultaneously the package
106 and the documentation via one of these two routes:
107
108 pdflatex footnotehyper.dtx (twice)
109
110 or
111
112 latex footnotehyper.dtx (twice)
113 dvips
114 ps2pdf
115
116 The method using the extracted file footnotehyper.tex produces
117 the smallest pdf file and is the officially preferred one as
118 it allows to set options in footnotehyper.tex to customize the
119 footnotehyper.pdf file:
120
121 - scrartcl class options (paper size, font size, ...)
122 - with or without source code,
123 - with dvipdfmx or with latex+dvips or pdflatex.
124
125 Installation:
126
127 footnotehyper.sty -> TDS:tex/latex/footnotehyper/footnotehyper.sty
128 footnotehyper.dtx -> TDS:source/latex/footnotehyper/footnotehyper.dtx
129 footnotehyper.pdf -> TDS:doc/latex/footnotehyper/footnotehyper.pdf
130 README.md -> TDS:doc/latex/footnotehyper/README.md
131
132 The other files may be discarded.
133
134
135 LICENSE
136 =======
137
138 This Work may be distributed and/or modified under the conditions
139 of the LaTeX Project Public License, version 1.3c. This version of
140 this license is in:
141
142 > <http://www.latex-project.org/lppl/lppl-1-3c.txt>
143
144 and the latest version of this license is in:
145
146 > <http://www.latex-project.org/lppl.txt>
147
148 Version 1.3 or later is part of all distributions of
149 LaTeX version 2005/12/01 or later.
150
151 The Author of this Work is:
152
153 - Jean-Francois Burnol `<jfbu at free dot fr>`
154
155 This Work consists of the main source file footnotehyper.dtx
156 and the derived files footnotehyper.sty, footnotehyper.tex,
157 footnotehyper.pdf, footnotehyper.dvi.
158 %</readme>
159 %<*tex>-------------------------------------------------------------------------
160 %%
161 %% run latex twice on this file footnotehyper.tex then dvipdfmx on
162 %% footnotehyper.dvi to produce the documentation footnotehyper.pdf, with
163 %% source code included.
164 %%
165 \chardef\Withdvipdfmx 1 % replace 1 by 0 for using latex+dvips or pdflatex
166 \chardef\NoSourceCode 0 % replace 0 by 1 for the doc *without* the source code
167 \NeedsTeXFormat{LaTeX2e}
168 \ProvidesFile {\pkgname.tex}[Driver for \pkgname\space documentation]%
169 \PassOptionsToClass {a4paper,fontsize=11pt,oneside}{scrartcl}
170 \PassOptionsToPackage {english}{babel}
171 \input \pkgname.dtx
172 %%% Local Variables:
173 %%% mode: latex
174 %%% End:
175 %</tex>-------------------------------------------------------------------------
176 %<*none>------------------------------------------------------------------------
177 ^^Afi^^Aendgroup
178 %
179 \chardef\noetex 0
180 \ifx\numexpr\undefined\chardef\noetex 1 \fi
181 \ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop
182 \else
183 \ifx\ProvidesFile\undefined
184 \chardef\extractfiles 0 % etex etc.. on \pkgname.dtx, only file extraction.
185 \else % latex/pdflatex on \pkgname.tex or on \pkgname.dtx
186 \ifx\Withdvipdfmx\undefined
187 % latex/pdflatex run is on \pkgname.dtx
188 \chardef\extractfiles 1 % 1 = extract files and typeset manual, 2 = only typeset
189 \chardef\Withdvipdfmx 0 % 0 = pdflatex or latex+dvips, 1 = dvipdfmx
190 \chardef\NoSourceCode 0 % 0 = include source code, 1 = do not
191 \NeedsTeXFormat {LaTeX2e}%
192 \PassOptionsToClass {a4paper,fontsize=11pt,oneside}{scrartcl}%
193 \PassOptionsToPackage {english}{babel}%
194 \else % latex run is on \pkgname.tex
195 \chardef\extractfiles 2 % do not extract files, only typeset
196 \fi
197 \ProvidesFile{\pkgname.dtx}%
198 [\pkgname\space source and documentation (\dtxtimestamp)]%
199 \fi
200 \fi
201 \ifnum\extractfiles<2 % extract files
202 \def\MessageDeFin{\newlinechar10 \let\Msg\message
203 \Msg{********************************************************************^^J}%
204 \Msg{*^^J}%
205 \Msg{* To finish the installation you have to move the following^^J}%
206 \Msg{* file into a directory searched by TeX:^^J}%
207 \Msg{*^^J}%
208 \Msg{*\space\space\space\space \pkgname.sty^^J}%
209 \Msg{*^^J}%
210 \Msg{* To produce the documentation with source code included run latex^^J}%
211 \Msg{* twice on file \pkgname.tex and then dvipdfmx on \pkgname.dvi^^J}%
212 \Msg{*^^J}%
213 \Msg{* Happy TeXing!^^J}%
214 \Msg{*^^J}%
215 \Msg{********************************************************************^^J}%
216 }%
217 \begingroup
218 \input docstrip.tex
219 \askforoverwritefalse
220 \def\pkgpreamble{\defaultpreamble^^J\MetaPrefix^^J%
221 \string\NeedsTeXFormat{LaTeX2e}^^J%
222 \string\ProvidesPackage{\pkgname}\perCent^^J%
223 \space[\pkgdate\space\pkgversion\space\pkgdescription]}%
224 \generate{\nopreamble\nopostamble
225 \file{README.md}{\from{\pkgname.dtx}{readme}}%
226 \usepostamble\defaultpostamble
227 \file{\pkgname.tex}{\from{\pkgname.dtx}{tex}}%
228 \usepreamble\pkgpreamble
229 \file{\pkgname.sty}{\from{\pkgname.dtx}{package}}}%
230 \endgroup
231 \fi % end of file extraction (from etex/latex/pdflatex run on \pkgname.dtx)
232 \ifnum\extractfiles=0 % tex/etex/xetex/etc on \pkgname.dtx, files extracted, stop
233 \MessageDeFin\expandafter\end
234 \fi
235 % From this point on, run is necessarily with e-TeX.
236 % Check if \MessageDeFin got defined, if yes put it at end of run.
237 \ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi
238 %-------------------------------------------------------------------------------
239 % START OF USER MANUAL TEX SOURCE
240 \documentclass {scrartcl}
241 %%% START OF CUSTOM doc.sty LOADING
242 \usepackage{doc}[=v2]
243 \AtBeginDocument{\MakeShortVerb{\|}}
244 \DeclareFontShape{OT1}{cmtt}{bx}{n}{<-> ssub * cmtt/m/n}{}
245 \DeclareFontFamily{OMS}{cmtt}{\skewchar\font 48} % '60
246 \DeclareFontShape{OMS}{cmtt}{m}{n}{<-> ssub * cmsy/m/n}{}
247 \DeclareFontShape{OMS}{cmtt}{bx}{n}{<-> ssub * cmsy/b/n}{}
248 \DeclareFontShape{OT1}{cmss}{m}{it}{<->ssub*cmss/m/sl}{}
249 \ifnum\NoSourceCode=1
250 \OnlyDescription
251 \fi
252 \CodelineNumbered
253 \DisableCrossrefs
254 % \setcounter{StandardModuleDepth}{1} % we don't use this mechanism currently
255 \def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}}
256 \def\cmd@to@cs#1#2{\char\number`#2\relax}
257 % This is hyperref compatible (contrarily to using \bslash)
258 % I need the \detokenize due to usage in implementation part with names
259 % containing the underscore for example
260 \DeclareRobustCommand\cs[1]{\texttt{\textbackslash\detokenize{#1}}}
261 \providecommand\marg[1]{%
262 {\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}}
263 \providecommand\oarg[1]{%
264 {\ttfamily[}\meta{#1}{\ttfamily]}}
265 \providecommand\parg[1]{%
266 {\ttfamily(}\meta{#1}{\ttfamily)}}
267
268 % There is very little we seem to need from the scrdoc extras: page geometry
269 % is set by geometry package and a4paper option from bnumexpr.tex file. So it
270 % seems I only need the hologo loading:
271 \usepackage{hologo}
272 %\DeclareRobustCommand*{\eTeX}{\hologo{eTeX}}%
273 %\DeclareRobustCommand*{\LuaTeX}{\hologo{LuaTeX}}%
274 %
275 %%% end of ltxdoc+srcdoc emulation.
276
277 \ifnum\NoSourceCode=1 \OnlyDescription\fi
278
279 \usepackage{ifpdf}
280 \ifpdf\chardef\Withdvipdfmx 0 \fi
281
282 \makeatletter
283 \ifnum\Withdvipdfmx=1
284 \@for\@tempa:=hyperref,bookmark,graphicx,xcolor,pict2e\do
285 {\PassOptionsToPackage{dvipdfmx}\@tempa}
286 %
287 \PassOptionsToPackage{dvipdfm}{geometry}
288 \PassOptionsToPackage{bookmarks=true}{hyperref}
289 \PassOptionsToPackage{dvipdfmx-outline-open}{hyperref}
290 % obsolète
291 % \PassOptionsToPackage{dvipdfmx-outline-open}{bookmark}
292 %
293 \def\pgfsysdriver{pgfsys-dvipdfm.def}
294 \else
295 \PassOptionsToPackage{bookmarks=true}{hyperref}
296 \fi
297 \makeatother
298 \def\ctanpackage#1{\href{https://ctan.org/pkg/#1}{#1}}
299
300 \usepackage[T1]{fontenc}
301 \usepackage[utf8]{inputenc}
302 \usepackage {babel}
303
304 \usepackage[hscale=0.72,vscale=0.7]{geometry}
305
306 \def\MacroFont{\ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax}
307
308 \usepackage{amsmath}
309 \usepackage{newtxtext, newtxmath}
310 \usepackage[straightquotes, scaled=0.97]{newtxtt}
311 \usepackage{xspace}
312
313 \usepackage[dvipsnames]{xcolor}
314 \definecolor{joli}{RGB}{225,95,0}
315 \definecolor{JOLI}{RGB}{225,95,0}
316 \definecolor{BLUE}{RGB}{0,0,255}
317 \colorlet{niceone}{green!35!blue!75}
318
319 \usepackage{framed}
320
321 \usepackage[pdfencoding=pdfdoc]{hyperref}
322 \hypersetup{%
323 linktoc=all,%
324 breaklinks=true,%
325 colorlinks,%
326 linkcolor=RoyalBlue,%
327 urlcolor=OliveGreen,%
328 pdfauthor={Jean-Fran\c cois Burnol},%
329 pdftitle={The \pkgname\space package},%
330 pdfsubject={\pkgdescription},%
331 pdfkeywords={LaTeX, footnotes},%
332 pdfstartview=FitH,%
333 pdfpagemode=UseNone}
334 % added usage of package bookmark 2013/10/10
335 \usepackage{bookmark}
336 \usepackage{enumitem}
337 \usepackage{\pkgname}
338
339 \newcommand\fnh{%
340 \texorpdfstring{{\color{joli}\ttfamily\bfseries \pkgname}}{\pkgname}\xspace}
341
342 \frenchspacing
343
344 \renewcommand\familydefault\sfdefault
345 \pagestyle{headings}
346
347 \begin{document}\thispagestyle{empty}
348 % the \MacroFont valid at begin document will be the one used in Implementation
349 % the one defined here will be used by verbatim (not by \verb)
350 \def\MacroFont{\ttfamily\small}
351 \rmfamily
352 \bookmark[named=FirstPage,level=1]{Title page}
353
354 \begin{center}
355 {\normalfont\LARGE The \fnh package}\\
356 \textsc{\small Jean-François Burnol}\par
357 \footnotesize \ttfamily
358 jfbu (at) free (dot) fr\par
359 Package version: \pkgversion\ (\pkgdate)\par
360 From source file \texttt{\pkgname.dtx} of \dtxtimestamp.\par
361 \end{center}
362
363 \MakeShortVerb{\`}%
364 \begin{abstract}
365 The `footnote` package by \textsc{Mark~Wooding} (`1997/01/28` `1.13`)
366 allows to gather footnotes (`\begin{savenotes}`) and later insert
367 them (after `\end{savenotes}`) at the bottom of the page, even
368 if the intervening material consists of tabulars, minipages or
369 framed contents for example. One can also use the
370 `\savenotes/\spewnotes` syntax.
371
372 Also, `footnote.sty` provides a `footnote` environment which
373 allows to insert verbatim material.
374
375 Earlier releases of the present \fnh package added
376 patches for `hyperref` compatibility and some bugfixes, addressing
377 in particular the incompatibility with `color/xcolor`, and with
378 `babel-frenchb`, and also fixing the `footnote` environment with
379 optional argument `[NUM]`. Since `v0.99` all macros are defined
380 internally and the `footnote` package is not loaded at all.
381
382 The same user interface is kept. Since `v1.0` it is possible to
383 use \fnh also in absence of `hyperref` or when the latter is
384 loaded with its `hyperfootnotes=false` option. The order of loading of
385 \fnh and `hyperref` is inconsequential.
386 \end{abstract}
387 \DeleteShortVerb{\`}
388
389 \section{License}
390
391 \begingroup\ttfamily\footnotesize\hyphenchar\font -1
392 \parindent0pt
393 \obeyspaces\obeylines %
394 \pkgLicense\endgroup
395
396 \section{Changes}
397
398 \begin{description}
399 \item[v0.9c (2016/04/19)] First release: adapt original package to be
400 |hyperref| and |color/xcolor| compatible.
401
402 \item[v0.9e (2016/04/30)] Abort in absence of |hyperref|. Compatibility with
403 |babel-french|.
404
405 \item[v0.99 (2017/02/16)] Do not load package
406 |footnote.sty|\footnote{\url{http://ctan.org/pkg/footnote}} anymore.
407
408 From then on \fnh is
409 incompatible with it at it uses the same user interface.
410
411 \item[v1.0 (2017/03/07)] Be usable also in absence of |hyperref| or when the
412 latter was passed |hyperfootnotes=false| option.
413
414 \item[v1.1 (2018/01/23)] Fix bug which arose when |savenotes| environment was used
415 \emph{inside} a minipage: footnotes were disappearing!%
416 %
417 \footnote{Thanks to François Pantigny for reporting the bug. A later
418 suggestion of the same is to let the package do nothing under Beamer class,
419 and this is what |v1.1a 2019/11/07| does.}
420 %
421 See related remarks at end of \autoref{sec:notes}.
422
423 \item[v1.1a (2019/11/07)] Abort under |beamer| (difficulty with \cs{@makefntext}
424 and suspicion |beamer| does not need \fnh).
425
426 \item[v1.1b (2021/01/26)] Fix incompatibility with the combination |memoir| +
427 |babel-french|.
428
429 \item[v1.1c (2021/01/29)] Fix legacy bug of original package interfering with
430 \LaTeX2e mechanism to suppress indentation after mid-paragraph lists (when
431 |savenotes| environment directly wraps the enclosed list environment,
432 mid-paragraph).
433
434 \item[v1.1d (2021/02/04)] Fix regression at |v1.1b| which caused a build crash
435 whenever \fnh decided to raise a warning relative to |\@makefntext|.%
436 %
437 \footnote{Thanks to Leon Kiefer for reporting the bug.}
438
439 Refactor analysis of \cs{@makefntext} for simpler and better support of
440 |babel-french|.%
441 \footnote{Only basic
442 context has been tested with |babel-french|: standard classes, |KOMA|-script,
443 |memoir|. Extra packages may make the \fnh environments cause breakage.}
444 %
445 Better support
446 contexts such as presence of package |cleveref|.%
447
448 Add \verb=\iffootnotehyperparse= and \verb=\iffootnotehyperwarn= booleans.
449
450 \item[v1.1e (2021/08/13)] Use \LaTeX\ environment hooks if available
451 for |\makesavenoteenv|, in replacement of the original |footnote| package
452 code.
453 \item[v1.1f (2025/11/15)] Fix compatibility with \ctanpackage{babel-french},
454 which was broken since the latter |v3.7e 2025-08-15| split of its Lua\LaTeX{}
455 code from its \hologo{pdfLaTeX} and \hologo{XeLaTeX} code.
456 \end{description}
457 \section{Usage}
458
459 The package provides:
460 \begin{savenotes}% juste pour vérifier le fix à 1.1c
461 \begin{itemize}
462 \item a |savenotes| environment which re-routes footnotes and delivers them
463 at the end (there is also the |\savenotes/\spewnotes| syntax; which does
464 create a group like the environment),
465 \item |footnote| and |footnotetext| environments to allow footnotes with
466 verbatim material,
467 \item a macro to patch environments to let them apply the |savenotes| mechanism
468 automatically.
469 \end{itemize}
470 \end{savenotes}
471 The preliminary construction by the package of the |footnote| and
472 |footnotetext| environments goes via an automated analysis of the \LaTeX\
473 macro |\@makefntext|, as possibly customized by classes and/or
474 packages. This is a rather fragile step, and the next section discusses
475 problems which may arise.
476
477 \subsection{Potential difficulties with the footnote and footnotetext
478 environments}
479
480 What is discussed here only affects the \emph{environments} |footnote| and
481 |footnotetext| not the macros \cs{footnote} and \cs{footnotetext}.
482
483 \fnh inherits from |footnote| original package the aim to
484 convert |\@makefntext| into two parts, the first one to be inserted
485 at the start of a footnote in environment form, the second one (usually
486 empty) at its end.%
487 %
488 \begin{footnote}
489 \LaTeX\ inserts some stuff before and after the footnote text, even before
490 handing it over as argument to \cs{@makefntext}. These tokens are currently
491 hardcoded into the \fnh environments for footnotes.
492 \end{footnote}
493 %
494 It thus hopes that the replacement text of |\@makefntext| contains only once
495 its parameter token |#1|, and that it is used there unbraced. This is the case
496 with the |article| class.
497
498 Known bug (may be promoted to feature at some point): the analysis is done
499 only once at begin document, whereas the |article.cls|'s redefines
500 |\@makefntext| during execution of |\maketitle|. However, it does not look
501 really urgent to support at all costs usage of the environment |footnote| in
502 the |\author| etc... data which contributes to the |\maketitle| expansion.%
503 %
504 \begin{footnote}
505 \phantomsection\label{fn:texperts}%
506 \TeX perts note: |\def\FNH@prefntext{\@makefntext{}}| would make the
507 footnote environment dynamically adjust to circumstances, when
508 |\@makefntext| only adds some prefix and no postfix. In fact, this is
509 (in a more complicated form for compatibility with |KOMA|-script and to
510 obey the |FBFrenchFootnotes| setting and the additional extra stuff
511 inserted by |babel-french| before and after) basically what is done by
512 \fnh to handle
513 |babel-french|.
514
515 As it may cause instability if extra packages fiddle
516 with |\@makefntext|, or |\@makefntext| is radically re-defined in some
517 environments provided by the class, \fnh does not use this when its
518 begin document analysis concluded the argument was used unbraced and at
519 last position in replacement text of |\@makefntext|, but it freezes the
520 found prefix. However, when it is concluded that probably |\@makefntext|
521 has been redefined in an |<extra tokens>\old@makefntext| way (for
522 example, this is the case with |cleveref| package), then the
523 |\def\FNH@prefntext{\@makefntext{}}| approach is taken, despite the
524 risks inherent to it.
525
526 You can provide your own custom definitions for
527 \cs{FNH@prefntext} and \cs{FNH@postfntext}. Then add
528 to the preamble \cs{footnotehyperparsefalse}.
529 \end{footnote}
530
531 Some seemingly innocent redefinitions such as the one
532 of |beamer| which was last time I checked (that was in 2019):
533 \begin{verbatim}
534 macro:#1->\def \insertfootnotetext {#1}\def \insertfootnotemark {\@makefnmark }
535 \usebeamertemplate ***{footnote}
536 \end{verbatim}
537 are not (easily) compatible with environment forms for footnotes
538 allowing verbatim material, as they require fetching the footnote
539 contents.%
540 \footnote{%\phantomsection\label{fn:beamer}% test, ça marche!
541 Since |v1.1a|, \fnh simply aborts under |beamer| class.}
542
543 In case of such a problematic |\@makefntext| \fnh raises a warning, to explain
544 that footnotes typeset using the environment forms will use a fall-back layout
545 (inherited from the |article| document class). Footnotes using |\footnote| are
546 not impacted by this.
547
548 % See \ref{fn:beamer} % test, ça marche, aussi avec environnement
549
550 Also \fnh emits some info message if |\@makefntext| was not as simple as
551 expected but nevertheless there is some hope that the |footnote| and
552 |footnotetext| environments will be fully functional. This is currently the
553 case in presence of package |cleveref| (see the \TeX perts
554 footnote \ref{fn:texperts}).
555
556 You can turn off these messages by adding \cs{footnotehyperwarnfalse}
557 to the document preamble.
558
559 \subsection{Other potential or actual limitations}
560
561 It should be recalled that in case of |\footnotemark[N]| and
562 |\footnotetext[N]{...}| mark-up |hyperref| creates no hyperlink. This is not
563 changed by \fnh and applies also to the |\begin{footnotetext}[N]| case.
564 Without optional argument the link is created, and the link is created also
565 for |\footnote[N]| or |\begin{footnote}[N]|.
566
567 This package does not handle especially floating environments, except that one
568 can always surround them in the source in a |savenotes| environment and one
569 knows that the footnotes will be delivered at the |\end{savenotes}|\dots which
570 may well be one page earlier than the actual location of the floating material
571 in the produced document !
572
573 Environments typesetting multiple times their contents are the most hostile to
574 footnotes. Currently, \fnh only handles especially the |amsmath|
575 environments (as in |footnote.sty|.)
576
577 \subsection{The \cs{makesavenoteenv} macro}
578
579 Finally there is a |\makesavenoteenv| macro which takes as
580 argument an environment name and patches it to do the
581 |\savenotes/\spewnotes| automatically.%
582
583 The syntax is either |\makesavenoteenv{foo}| which patches environment |foo|
584 (since |1.1e|, via the hooks provided by \LaTeX\ since October 2020) to do
585 automatically \cs{savenotes}/\cs{spewnotes}, or |\makesavenoteenv[bar]{foo}|
586 which defines environment |bar| as |foo| inside a |savenotes| environment.
587
588 With \LaTeX\ earlier than October 2020, the macro is the same as in the
589 original |footnote| package and proceeds in a more brutal way than what is
590 described in previous paragraph. It is safer to avoid it, as one never knows
591 what happens with such patches: for example the |[H]| specifier provided by
592 the |float| package overwrites the |\end{table}| definition during the
593 execution of |\begin{table}|\dots!%
594 %
595 \footnote{By the way I have not checked if this |float| package feature
596 behaves nicely, or has been updated to be compatible, with the \LaTeX\ hook
597 mechanism of October 2020.}
598 As another example, |\makesavenoteenv{tcolorbox}| with the original |footnote|
599 package code breaks, but the new version activated with \LaTeX\ from October
600 2020 or later appears to work.
601
602 \subsection{Example of output, and of input}
603 \begin{savenotes}
604 \begin{framed}
605 \DeleteShortVerb{\|}\MakeShortVerb{\*}%
606 {\centering
607 \begin{tabular}{|c|c|}
608 \hline
609 \strut Inside\footnote{If the frame
610 extends to the next page,
611 the end of the *savenotes* environment delivers its intercepted
612 footnotes only there.} a & tabular\begin{footnote}Alternatively a
613 *\savenotes/\spewnotes* pair
614 could have been used.\end{footnote}\\\hline
615 \end{tabular}\par}
616 \DeleteShortVerb{\*}\MakeShortVerb{\|}%
617 Here is an illustrative example of usage of the |savenotes| environment:
618 \begin{verbatim}
619 \begin{savenotes}
620 \begin{framed}
621 Please refer to the documentation of the |footnote| package.%
622 \footnote{\url{http://ctan.org/pkg/footnote}}
623
624 Particularly you may check its |savenotes| environment.%
625 \footnote{% here is how to add anchor for hyperlink target:
626 \phantomsection\label{fn:floats}% (this % to avoid space at start of paragraph)
627 It doesn't bring any
628 feature to especially handle the issues related to footnotes in floating
629 environments, though.}
630 \end{framed}
631 \end{savenotes}
632 Here is a link to an interesting footnote: \ref{fn:floats}.
633 \end{verbatim}
634 and the present frame has \cs{footnote}'s from inside a |tabular| and is
635 inside a |savenotes| environment.%
636 \begin{footnote}\phantomsection\label{fn:minipage}% (attention à l'espace)
637 Here is an issue which has nothing (as I finally figured out) to
638 do with |footnote|, and only indirectly with \LaTeX: if you embed
639 a \emph{full-width} minipage (with initial \cs{noindent}) in any
640 environment not doing \cs{ignorespacesafterend}, be careful to add
641 a \% either immediately after the |\end{minipage}| (or a |\relax|
642 or a |\par|) or after the surrounding environment |\end{foo}| or
643 use |\end{minipage}\end{foo}| else the output may have an extra
644 blank line if the source has a blank line after the |foo| environment.
645 Here is a typical example, with a |tabular| rather:
646 \makeatletter
647
648 \medskip\noindent\hspace{1cm}\begin{minipage}{\dimexpr\linewidth-1cm}%
649 \def\MacroFont{\baselineskip10pt\relax}%
650 \begin{verbatim}
651 \newenvironment{foo}{}{}
652
653 \noindent\begin{tabular}{p{\dimexpr\linewidth-2\tabcolsep\relax}}
654 A\dotfill B
655 \end{tabular}
656
657 C
658
659 \begin{foo}
660 \noindent\begin{tabular}{p{\dimexpr\linewidth-2\tabcolsep\relax}}
661 A\dotfill B
662 \end{tabular}
663 \end{foo}
664
665 C
666 \end{verbatim}\end{minipage}\par\medskip
667
668 If you try it out you will see an extra blank line in PDF output above the
669 second C. Starting with |v0.99| the |\end{savenotes}| emits an
670 \cs{ignorespacesafterend} which avoids this generic \TeX/\LaTeX\
671 problem. For good measure there is now an \cs{ignorespaces} in
672 |\begin{savenotes}|.
673 \end{footnote}
674 Let's test an
675 |amsmath| environment with |\intertext|. As
676 \begin{align}
677 E&=mc^2\;,
678 \intertext{was too easy\footnote{There is also $E=h\nu$.}, let's
679 try:}
680 a^n + b^n &=c^n\;.
681 \end{align}
682 And a footnote with some verbatim material%
683 \begin{footnote}\phantomsection\label{fn:verb}%
684 The footnote environment allows verbatim contents: \verb|&$^%\[}$|
685 \end{footnote}.
686 \end{framed}
687 \end{savenotes}
688
689 The input for the footnote \ref{fn:verb} was coded as:
690 \begin{verbatim}
691 And a footnote with some verbatim material%
692 \begin{footnote}
693 The footnote environment allows verbatim contents: \verb|&$^%\[}$|
694 \end{footnote}.
695 \end{verbatim}
696 Now some use of |\footnotemark| followed by a |footnotetext| (here is the
697 mark: \footnotemark)
698 environment.% attention! sinon espace extra
699 %
700 \begin{footnotetext}
701 Notice that the hyperlinking works for |\footnotemark| associated to the
702 environment |footnotetext|.
703 \end{footnotetext}
704 And use of |\footnotemark[99]| in association with a
705 |footnotetext| environment using the same optional argument |[99]| (here is
706 the mark: \footnotemark[99], and you can see it is not an hyperlink).% !
707 %
708 \begin{footnotetext}[99]
709 |hyperref| creates no hyperlink in this case, or in the
710 |\footnotemark[N]/\footnotetext[N]{<foo>}| case. It does when
711 the |[N]| is absent or when it is used with a |\footnote| command
712 (or a |footnote| environment.)
713 \end{footnotetext}
714 And a final footnote, done with |\begin{footnote}[57]|%
715 \begin{footnote}[57]%\csname @minipagetrue\endcsname % to reduce
716 % % framed inserted vertical spacing
717 % \begin{framed}
718 % \noindent
719 \fnh works since |v1.0| also in absence of |hyperref| or when the
720 latter was passed |hyperfootnotes=false| option.
721 % \end{framed}
722 \end{footnote}.
723 There is no problem with the hyperlink, then.%
724 %
725 \footnote{Oh, and don't forget to read
726 this interesting footnote: \ref{fn:minipage} (just in case you skipped on
727 first reading).}
728
729 \section{Notes}\label{sec:notes}
730
731 A few items worth of mention:
732 \begin{itemize}[nosep]
733 \item the |footnote| package patches the \LaTeX\ kernel |\parbox|.
734 \fnh doesn't (but the code can be found commented-out at the
735 end of the present file).
736 \item the |footnote| package defines a |minipage*| environment
737 which is |minipage| patched by |\makesavenoteenv|, \fnh doesn't.
738 \item the |footnote| environment from |footnote.sty| does a
739 |\leavevmode\unskip| which \fnh doesn't: hence if one locates
740 |\begin{footnote}| at start of a line in the \LaTeX\ source, one will
741 typically need a \% at end of text on previous line to avoid the
742 end-of-line space.
743 \item the |hyperref| package inserts no hyperlink in case of
744 |\footnotemark[N]/\footnotetext[N]|. This is not modified by \fnh.
745 \item side-note: there is an interference between |hyperref| and |frenchb|
746 regarding the footnote marker when using the syntax |\footnotemark[NUM]|.
747 For the record here is a patch (last tested briefly with
748 % PUTAIN BORDEL ! LaTeX Error: Text for \verb command ended by end of
749 % line. À CHAQUE FOIS ÇA M'AGAÇE. Bon, je n'ai pas mon patch habituel ici.
750 |hyperref 2016/06/24 v6.83q| and |frenchb 2017/01/30 v3.2g|):
751 % pour le cas où mis dans commentaires de code
752 % \begingroup\makeatletter\let\check@percent\@gobble
753 \begin{verbatim}
754 \AtBeginDocument{%
755 \let\@xfootnotemarkORIFB \@xfootnotemark
756 \def\@xfootnotemarkFB {\leavevmode\unskip\unkern\,\@xfootnotemarkORIFB }%
757 \ifHy@hyperfootnotes\ifFBAutoSpaceFootnotes
758 \let\@xfootnotemark\@xfootnotemarkFB
759 \fi\fi
760 }%
761 \end{verbatim}
762 On |2021/01/29| the interference (lost of some |babel-french| customization)
763 is still there, as I checked now. This has nothing to do with \fnh.
764 % \endgroup
765 \item some environments typeset multiple times their contents,
766 which causes issues; \fnh takes provisions only to handle the
767 |amsmath| measuring step.
768 \item
769 \LaTeX2e has some ``features'' when using footnotes in |minipage|'s
770 which are themselves in a |minipage| which may also have footnotes externally
771 to the internal minipages... try it out with some |\fbox|es around the
772 sub-|minipages|, to see.
773
774 \fnh behaves like original package |footnote| when the |savenotes|
775 environment is used \emph{inside} a minipage. Only reasonable usage in case
776 of nested minipages seems to use only a single top level (i.e. external)
777 |savenotes| environment. But there will anyhow be collisions of the
778 alphabetic enumerations. These collisions are there with or without \fnh (or
779 |footnote.sty|.) I did not make any attempt, nor intend to in future, to
780 address in an automatized manner these problematic contexts.
781 \end{itemize}
782
783 \StopEventually{\end{document}\endinput}
784 \makeatletter
785 \let\check@percent\original@check@percent
786 \makeatother
787
788 \newgeometry{left=4cm, hscale=0.72}
789 \section{Implementation}
790
791 \small
792
793 \makeatletter
794 \noindent
795 \begingroup
796 \topsep\MacrocodeTopsep
797 \trivlist\parskip\z@\item[]
798 \macro@font
799 \leftskip\@totalleftmargin \advance\leftskip\MacroIndent
800 \rightskip\z@ \parindent\z@ \parfillskip\@flushglue
801 \global\@newlistfalse \global\@minipagefalse
802 \ifcodeline@index
803 \everypar{\global\advance\c@CodelineNo\@ne
804 \llap{\theCodelineNo\ \hskip\@totalleftmargin}}%
805 \fi
806 \string\NeedsTeXFormat\string{LaTeX2e\string}\par
807 \string\ProvidesPackage\string{\pkgname\string}\@percentchar\par
808 \noindent\space [\pkgdate\space\pkgversion\space\pkgdescription]\par
809 \nointerlineskip
810 \global\@inlabelfalse
811 \endtrivlist
812 \endgroup
813 \makeatother
814
815 % The catcode hackery next is to avoid to have <*package> to be listed
816 % in the commented source code...
817 % (c) 2012/11/19 jf burnol ;-)
818
819 \MakePercentIgnore
820
821 %
822 % \catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11
823 % \let</none>\relax
824 % \def<*package>{\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12}
825 %
826 %</none>
827 %<*package>
828 % \begin{macro}{no options}
829 % The package has no options. I am too lazy.
830 % \begin{macrocode}
831 \newif\iffootnotehyperparse\footnotehyperparsetrue
832 \newif\iffootnotehyperwarn \footnotehyperwarntrue
833 \def\FNH@msgbk{^^J(footnotehyper)\@spaces}% make room for message lines
834 \DeclareOption*%
835 {\PackageWarning{footnotehyper}{Option `\CurrentOption' is unknown}}%
836 \ProcessOptions\relax
837 % \end{macrocode}
838 % \end{macro}
839 % |v1.1a| lets the package abort under Beamer class and warn user.
840 % \begin{macrocode}
841 \@ifclassloaded{beamer}
842 {\PackageWarningNoLine{footnotehyper}{This package is
843 incompatible with the beamer class. Aborting input..}%
844 \endinput}
845 {}%
846 % \end{macrocode}
847 % Versions up to |v0.9f| loaded |footnote.sty|, with lots of patching
848 % afterwards. Starting with |v0.99|, \fnh does everything by itself with |FNH@|
849 % prefix. Brief overview of some of the fixed issues:
850 % \begin{itemize}[nosep]
851 % \item there was incompatibility with |hyperref|,
852 % \item and with |color|,
853 % \item if the \cs{@makefntext} at the time of loading of |footnote.sty|
854 % does not have its argument visible at top level in its meaning, or
855 % is used multiple times there, then the footnote environment will lead to low
856 % level \TeX\ error,
857 % \item |footnote.sty| modifies |\parbox|,
858 % \item |footnote.sty| does some too early |\let|,
859 % \item the footnote environment from |footnote.sty| does not work if used with
860 % optional argument |[N]|.
861 % \end{itemize}
862 %
863 % \noindent Starting with |v1.0|, \fnh may be used also in absence
864 % of |hyperref|.
865 % \begin{macrocode}
866 \newbox\FNH@notes
867 \newdimen\FNH@width
868 \newtoks\FNH@toks % 1.1c
869 \let\FNH@colwidth\columnwidth
870 \newif\ifFNH@savingnotes
871 \AtBeginDocument {%
872 \let\FNH@latex@footnote \footnote
873 \let\FNH@latex@footnotetext\footnotetext
874 \let\FNH@H@@footnotetext \@footnotetext
875 \let\FNH@H@@mpfootnotetext \@mpfootnotetext
876 \newenvironment{savenotes}
877 {\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
878 \let\spewnotes \FNH@spewnotes
879 \let\footnote \FNH@footnote
880 \let\footnotetext \FNH@footnotetext
881 \let\endfootnote \FNH@endfntext
882 \let\endfootnotetext\FNH@endfntext
883 \@ifpackageloaded{hyperref}
884 {\ifHy@hyperfootnotes
885 \let\FNH@H@@footnotetext\H@@footnotetext
886 \let\FNH@H@@mpfootnotetext\H@@mpfootnotetext
887 \else
888 \let\FNH@hyper@fntext\FNH@nohyp@fntext
889 \fi}%
890 {\let\FNH@hyper@fntext\FNH@nohyp@fntext}%
891 }%
892 % \end{macrocode}
893 % \begin{macro}{\FNH@hyper@fntext}
894 % \begin{macro}{\FNH@nohyp@fntext}
895 % \begin{macro}{\FNH@fntext}
896 % These are the \fnh replacement for |\@footnotetext| inside the
897 % |savenotes| environment. There is a version creating an hyperlink
898 % and another one not creating an hyperlink. The \cs{FNH@fntext}
899 % macro serves as general dispatch. This may be a place to customize if one
900 % wants to handle environments doing multiple passes: but the footnote counter
901 % must have been taken care of elsewhere. The code currently handles only
902 % the case of |amsmath| environments.
903 % \begin{macrocode}
904 \def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}%
905 \def\FNH@nohyp@fntext{\FNH@fntext\FNH@nohyp@fntext@i}%
906 \def\FNH@fntext #1{\ifx\ifmeasuring@\@undefined
907 \expandafter\@secondoftwo\else\expandafter\@firstofone\fi
908 {\ifmeasuring@\expandafter\@gobbletwo\fi}#1%
909 }%
910 % \end{macrocode}
911 % \end{macro}\end{macro}\end{macro}
912 % \begin{macro}{\FNH@hyper@fntext@i}
913 % We do the \cs{ifHy@nesting} test although hyperref's manual
914 % says ``Allows links to be nested; no drivers currently support this.''
915 % \begin{macrocode}
916 \long\def\FNH@hyper@fntext@i#1{%
917 \global\setbox\FNH@notes\vbox
918 {\unvbox\FNH@notes
919 \FNH@startnote
920 \@makefntext
921 {\rule\z@\footnotesep\ignorespaces
922 \ifHy@nesting\expandafter\ltx@firstoftwo
923 \else\expandafter\ltx@secondoftwo
924 \fi
925 {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}{#1}}%
926 {\Hy@raisedlink
927 {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}%
928 {\relax}}%
929 \let\@currentHref\Hy@footnote@currentHref
930 \let\@currentlabelname\@empty
931 #1}%
932 \@finalstrut\strutbox
933 }%
934 \FNH@endnote
935 }%
936 }%
937 % \end{macrocode}
938 % \end{macro}
939 % \begin{macro}{\FNH@nohyp@fntext@i}
940 % The original \cs{fn@fntext} had no \cs{long}.
941 % \begin{macrocode}
942 \long\def\FNH@nohyp@fntext@i#1{%
943 \global\setbox\FNH@notes\vbox
944 {\unvbox\FNH@notes
945 \FNH@startnote
946 \@makefntext{\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
947 \FNH@endnote
948 }%
949 }%
950 % \end{macrocode}
951 % \end{macro}
952 % \begin{macro}{\FNH@startnote}
953 % Same as original (the code comment is kept from original.)
954 % \begin{macrocode}
955 \def\FNH@startnote{%
956 \hsize\FNH@colwidth
957 \interlinepenalty\interfootnotelinepenalty
958 \reset@font\footnotesize
959 \floatingpenalty\@MM% Is this right???
960 \@parboxrestore
961 \protected@edef\@currentlabel{\csname p@\@mpfn\endcsname\@thefnmark}%
962 \color@begingroup
963 }%
964 % \end{macrocode}
965 % \end{macro}
966 % \begin{macro}{\FNH@endnote}
967 % Fixed from original.
968 % \begin{macrocode}
969 \def\FNH@endnote{\color@endgroup}%
970 % \end{macrocode}
971 % \end{macro}
972 % \begin{macro}{\FNH@savenotes}
973 % Same as original apart from using |hyperref|-aware \cs{FNH@hyper@fntext},
974 % and taking into account |hyperref|'s custom \cs{@xfootnotenext}. This was
975 % missed by |v0.9f| hence |\footnotetext[N]{..}| did not work
976 % inside |savenotes| environment. Fixed for |v0.99|.
977 %
978 % Maybe I should change the way \cs{@minipagerestore} is handled.
979 % \begin{macrocode}
980 \def\FNH@savenotes{%
981 \begingroup
982 \ifFNH@savingnotes\else
983 \FNH@savingnotestrue
984 \let\@footnotetext \FNH@hyper@fntext
985 \let\@mpfootnotetext \FNH@hyper@fntext
986 \let\H@@mpfootnotetext\FNH@nohyp@fntext % fool hyperref's \@xfootnotenext
987 \FNH@width\columnwidth
988 \let\FNH@colwidth\FNH@width
989 \global\setbox\FNH@notes\box\voidb@x
990 \let\FNH@thempfn\thempfn
991 \let\FNH@mpfn\@mpfn
992 \ifx\@minipagerestore\relax\let\@minipagerestore\@empty\fi
993 \expandafter\def\expandafter\@minipagerestore\expandafter{%
994 \@minipagerestore
995 \let\thempfn\FNH@thempfn
996 \let\@mpfn\FNH@mpfn
997 }%
998 \fi
999 }%
1000 % \end{macrocode}
1001 % \end{macro}
1002 % \begin{macro}{\FNH@spewnotes}
1003 % This uses \cs{FNH@H@@footnotetext} which is the
1004 % \cs{H@@footnotetext} |hyperref|'s preserved original
1005 % meaning of \cs{@footnotetext} not creating a link target.
1006 %
1007 % |v1.1| fixes the bug about disappearing footnotes if |savenotes| environment
1008 % is used inside a minipage. I had never really considered such usage, hence
1009 % missed realizing there was a bug.
1010 %
1011 % |v1.1c 2021/01/29| fixes a legacy bug from |footnote| package: if used
1012 % to enclose a list environment inside a paragraph, it broke the
1013 % mechanism which suppresses indentation following the list.
1014 %
1015 % Now, situation would be far simpler here if we did not have this extra
1016 % |\begingroup| |\endgroup| pair in |\FNH@savenotes/\FNH@spewnotes|.
1017 %
1018 % A priori, as far as I understand, testing the |\if@endpe| flag should be
1019 % enough, but let's be extra cautious and check that |\par| is not |\@@par|.
1020 % Attention here that this is not necessarily followed by |\end{savenotes}| and
1021 % we have to support the |\savenotes/\spewnotes| syntax. The complication is
1022 % added from it creating a group without being a genuine \LaTeX2e environment.
1023 % \begin{macrocode}
1024 \def\FNH@spewnotes {%
1025 \if@endpe\ifx\par\@@par\FNH@toks{}\else
1026 \FNH@toks\expandafter{\expandafter
1027 \def\expandafter\par\expandafter{\par}\@endpetrue}%
1028 \expandafter\expandafter\expandafter
1029 \FNH@toks
1030 \expandafter\expandafter\expandafter
1031 {\expandafter\the\expandafter\FNH@toks
1032 \expandafter\def\expandafter\@par\expandafter{\@par}}%
1033 \expandafter\expandafter\expandafter
1034 \FNH@toks
1035 \expandafter\expandafter\expandafter
1036 {\expandafter\the\expandafter\FNH@toks
1037 \expandafter\everypar\expandafter{\the\everypar}}\fi
1038 \else\FNH@toks{}\fi
1039 \expandafter
1040 \endgroup\the\FNH@toks
1041 \ifFNH@savingnotes\else
1042 \ifvoid\FNH@notes\else
1043 \begingroup
1044 \let\@makefntext\@empty
1045 \let\@finalstrut\@gobble
1046 \let\rule\@gobbletwo
1047 \ifx\@footnotetext\@mpfootnotetext
1048 \expandafter\FNH@H@@mpfootnotetext
1049 \else
1050 \expandafter\FNH@H@@footnotetext
1051 \fi{\unvbox\FNH@notes}%
1052 \endgroup
1053 \fi
1054 \fi
1055 }%
1056 % \end{macrocode}
1057 % \end{macro}
1058 % \begin{macro}{\FNH@footnote}
1059 % \begin{macro}{\FNH@footnotetext}
1060 % We now take care of |footnote.sty|'s |footnote| environment. The original
1061 % \cs{fn@endfntext} is lacking a \cs{fn@endnote}, and this meant that
1062 % |footnote.sty| was incompatible with |color/xcolor| packages. Also this
1063 % \cs{fn@endnote} was |\let| to |\color@endgroup| which is wrong.
1064 %
1065 % Furthermore, independently of presence of the |\color/xcolor| issue, the
1066 % |footnote.sty|'s |footnote| environment raised an error if used with an
1067 % optional argument. |v0.9f| addresses this issue.
1068 %
1069 % The |footnotetext| environment adds a complication, in case of optional
1070 % argument we should not try to set up a link due to the fact that |hyperref|
1071 % does not support it for the |\footnotemark[N]/\footnotetext[N]| syntax.
1072 % And we need to make sure that the |footnote| and |footnotetext| environments
1073 % obey the |\savenotes/\spewnotes| mechanism.
1074 %
1075 % To handle all of this we code things completely differently from
1076 % |footnote.sty|.
1077 %
1078 % The |v0.9f| |\begin{footnotetext}[N]| inside |savenotes| tried to create
1079 % an hyperref target. Fixed for |v0.99|.
1080 %
1081 % Note: the |footnote.sty| code did a |\leavevmode\unskip| at entrance of
1082 % |footnote| environment, which \fnh has not kept.
1083 % \begin{macrocode}
1084 \def\FNH@footnote@envname {footnote}%
1085 \def\FNH@footnotetext@envname{footnotetext}%
1086 \def\FNH@footnote{%
1087 \ifx\@currenvir\FNH@footnote@envname
1088 \expandafter\FNH@footnoteenv
1089 \else
1090 \expandafter\FNH@latex@footnote
1091 \fi
1092 }%
1093 \def\FNH@footnoteenv{%
1094 \@ifnextchar[%
1095 \FNH@footnoteenv@i %]
1096 {\stepcounter\@mpfn
1097 \protected@xdef\@thefnmark{\thempfn}%
1098 \@footnotemark
1099 \def\FNH@endfntext@fntext{\@footnotetext}%
1100 \FNH@startfntext}%
1101 }%
1102 \def\FNH@footnoteenv@i[#1]{%
1103 \begingroup
1104 \csname c@\@mpfn\endcsname #1\relax
1105 \unrestored@protected@xdef\@thefnmark{\thempfn}%
1106 \endgroup
1107 \@footnotemark
1108 \def\FNH@endfntext@fntext{\@footnotetext}%
1109 \FNH@startfntext
1110 }%
1111 \def\FNH@footnotetext{%
1112 \ifx\@currenvir\FNH@footnotetext@envname
1113 \expandafter\FNH@footnotetextenv
1114 \else
1115 \expandafter\FNH@latex@footnotetext
1116 \fi
1117 }%
1118 \def\FNH@footnotetextenv{%
1119 \@ifnextchar[%
1120 \FNH@footnotetextenv@i %]
1121 {\protected@xdef\@thefnmark{\thempfn}%
1122 \def\FNH@endfntext@fntext{\@footnotetext}%
1123 \FNH@startfntext}%
1124 }%
1125 \def\FNH@footnotetextenv@i[#1]{%
1126 \begingroup
1127 \csname c@\@mpfn\endcsname #1\relax
1128 \unrestored@protected@xdef\@thefnmark{\thempfn}%
1129 \endgroup
1130 \ifFNH@savingnotes
1131 \def\FNH@endfntext@fntext{\FNH@nohyp@fntext}%
1132 \else
1133 \def\FNH@endfntext@fntext{\FNH@H@@footnotetext}%
1134 \fi
1135 \FNH@startfntext
1136 }%
1137 % \end{macrocode}
1138 % \end{macro}\end{macro}
1139 % \begin{macro}{\FNH@startfntext}
1140 % \begin{macro}{\FNH@endfntext}
1141 % \begin{macro}{\FNH@endfntext@fntext}
1142 % This is used for the environmental form of the footnote environments.
1143 % The use of |\box\z@| originates in |footnote.sty|, should I change that ?
1144 %
1145 % Both of \cs{endfootnote} and \cs{endfootnotetext} are aliases for
1146 % \cs{FNH@endfntext}.
1147 %
1148 % The \cs{FNH@endfntext@fntext} may be \cs{@footnotetext} (which will be
1149 % \cs{FNH@hyper@fntext} in |savenotes| environment), or
1150 % \cs{FNH@H@@footnotetext}, or \cs{FNH@nohyp@fntext} if in |savenotes| scope.
1151 % \begin{macrocode}
1152 \def\FNH@startfntext{%
1153 \setbox\z@\vbox\bgroup
1154 \FNH@startnote
1155 \FNH@prefntext
1156 \rule\z@\footnotesep\ignorespaces
1157 }%
1158 \def\FNH@endfntext {%
1159 \@finalstrut\strutbox
1160 \FNH@postfntext
1161 \FNH@endnote
1162 \egroup
1163 \begingroup
1164 \let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo
1165 \FNH@endfntext@fntext {\unvbox\z@}%
1166 \endgroup
1167 }%
1168 % \end{macrocode}
1169 % \end{macro}\end{macro}\end{macro}
1170 % \begin{macro}{\@makefntext}
1171 % \begin{macro}{\FNH@prefntext}
1172 % \begin{macro}{\FNH@postfntext}
1173 % \begin{macro}{\FNH@check}
1174 % The definitions of |\FNH@prefntext| and |\FNH@postfntext| (which are needed
1175 % for the |footnote| environment, |\FNH@startfntext| and |\FNH@endfntext|)
1176 % are extracted from a somewhat daring analysis of |\@makefntext|.
1177 % Contrarily to |footnote.sty|'s original code (which may result in low level
1178 % \TeX\ errors when the |footnote| environment is executed)
1179 % the method here will alert the user if the argument
1180 % of |\@makefntext| is not visible at top level in its meaning or is used
1181 % there multiple times. We also insert here some code to handle especially
1182 % the case of |babel-frenchb|.
1183 %
1184 % Refactoring at |v1.1d|. This will make \fnh compatible with |cleveref| for
1185 % example, if nothing else interferes. Not all combinations of classes and
1186 % packages can be handled and we can not hardcode a pre-analysis for all
1187 % possible cases. Of course, one can not expect \fnh to be compatible with
1188 % other footnote dedicated packages, but at best only with slight
1189 % modifications of \LaTeX's defaults. At |v1.1d| the |babel-french| context
1190 % is handled especially (to support it better with KOMAscript classes and
1191 % simplify handling the |memoir| situation); there was no real other way
1192 % than hardcode it more or less, but it can possibly break in presence of
1193 % additional footnote packages.
1194 %
1195 % Also the \cs{iffootnotehyperparse} and \cs{iffootnotehyperwarn} booleans
1196 % were added.
1197 %
1198 % Provide at least some definitions for \cs{FNH@prefntext} and
1199 % \cs{FNH@postfntext} in case of \cs{footnotehyperparsefalse} in preamble.
1200 % \begin{macrocode}
1201 \let\FNH@prefntext\@empty
1202 \let\FNH@postfntext\@empty
1203 \AtBeginDocument{\iffootnotehyperparse\expandafter\FNH@check\fi}%
1204 % \end{macrocode}
1205 %
1206 % As |\ifFBFrenchFootnotes| is not a \TeX\ boolean if |babel-frenchb| isn't
1207 % loaded, we have to work around this for |\if..\fi| pairs.
1208 %
1209 % |v1.1d| fixes a |v1.1b| bug: any situation in |\FNH@check@a| causing the
1210 % |\FNH@bad@makefntext@alert| branch to be chosen crashed the build due
1211 % precisely to this problem with |\ifFBFrenchFootnotes| status. I had taken
1212 % precautions for the |\else| branch but not for the ``warning'' branch.
1213 %
1214 % So let's fix this, and do it in such a way (with \cs{FNH@safeif}) that the
1215 % \TeX\ |\if..\fi| balancing count does not perturbate enclosing the package
1216 % loading in a \TeX\ conditional. Why I am bothering, I don't know.
1217 %
1218 % Finally, I refactored entirely the way |frenchb| context is handled,
1219 % (using multiple times \cs{FNH@safeif} although now only for the artistic
1220 % aim of balanced conditionals, as all |frenchb|-related stuff being in
1221 % their dedicated macro, direct usage of |\ifFB...| is possible).
1222 %
1223 % As long as nothing else interferes |babel-french| should be ok with
1224 % standard classes, KOMA and memoir.
1225 %
1226 % |v1.1f| fixes compatibility with \ctanpackage{babel-french} under
1227 % \hologo{pdfLaTeX} and \hologo{XeLaTeX}, broken since its |v3.7e| release.
1228 % \begin{macrocode}
1229 \def\FNH@safeif#1{%
1230 \iftrue\csname if#1\endcsname\csname fi\endcsname\expandafter\@firstoftwo
1231 \else\csname fi\endcsname\expandafter\@secondoftwo
1232 \fi
1233 }%
1234 \def\FNH@check{%
1235 \ifx\@makefntextFB\@undefined
1236 \expandafter\FNH@check@
1237 \else
1238 \providecommand\localleftbox[1]{}%
1239 \expandafter\FNH@frenchb@
1240 \fi
1241 }%
1242 \def\FNH@frenchb@{%
1243 \def\FNH@prefntext{%
1244 \localleftbox{}%
1245 \let\FBeverypar@save\FBeverypar@quote
1246 \let\FBeverypar@quote\relax
1247 \FNH@safeif{FB@koma}%
1248 {\FNH@safeif{FBFrenchFootnotes}%
1249 {\ifx\footnote\thanks
1250 \let\@@makefnmark\@@makefnmarkTH
1251 \@makefntextTH{} % space as in french.ldf
1252 \else
1253 \let\@@makefnmark\@@makefnmarkFB
1254 \@makefntextFB{} % space as in french.ldf
1255 \fi
1256 }{\let\@@makefnmark\@@makefnmarkORI
1257 \@makefntextORI{}% no space as in french.ldf
1258 }%
1259 }%
1260 {\FNH@safeif{FBFrenchFootnotes}%
1261 {\@makefntextFB{}}%
1262 {\@makefntextORI{}}%
1263 }%
1264 }%
1265 \def\FNH@postfntext{%
1266 \let\FBeverypar@quote\FBeverypar@save
1267 \localleftbox{\FBeveryline@quote}%
1268 }%
1269 \iffootnotehyperwarn
1270 \PackageInfo{footnotehyper}%
1271 {babel-french compatibility patch activated.\FNH@msgbk
1272 It may not work with all combinations of classes/packages.\FNH@msgbk
1273 In case of problems with the `footnote' or `footnotetext'\FNH@msgbk
1274 environments, you may try sending to the author a small\FNH@msgbk
1275 file demonstrating the problem.\FNH@msgbk
1276 To turn off this message, add \string\footnotehyperwarnfalse\FNH@msgbk
1277 to the preamble\@gobble}%
1278 \fi
1279 }%
1280 % \end{macrocode}
1281 % \end{macro}
1282 % ``Daring analysis'' is un understatement. At |v1.1b| we added a dangerous
1283 % twist to fix a memoir + frenchb triggered issue: if the
1284 % |\@makefntext|, as in memoir + frenchb situation, uses |\def| syntax to
1285 % define a macro with parameter we had a problem with the |#| token not
1286 % being doubled in the replacement fetched by
1287 % |\FNH@check@a|. As expedient work-around we fixed this by adding a
1288 % |\scantokens| wrapper.
1289 %
1290 % At |v1.1d| I refactored the |babel-french| situation, moving it to an
1291 % entirely dedicated \cs{FNH@frenchb@}, and dropped the |v1.1b| usage of
1292 % |\scantokens|.
1293 %
1294 % |v1.1d| adds \cs{FNH@checkagain@} which will identify circumstances likely
1295 % to be safe for the approach via |\def\FNH@prefntext{\@makefntext{}}|. For
1296 % example this is what will happen with |cleveref| (if not modified by other
1297 % packages).
1298 % \begin{macrocode}
1299 \def\FNH@check@{%
1300 \expandafter\FNH@check@a\@makefntext{1.2!3?4,}%
1301 \FNH@@@1.2!3?4,\FNH@@@\relax
1302 }%
1303 \long\def\FNH@check@a #11.2!3?4,#2\FNH@@@#3{%
1304 \ifx\relax#3\expandafter\FNH@checkagain@
1305 \else
1306 \def\FNH@prefntext{#1}\def\FNH@postfntext{#2}%
1307 \expandafter\FNH@check@b
1308 \fi
1309 }%
1310 % \end{macrocode}
1311 % The argument was not seen unbraced at top. Maybe it is not fetched, or it was
1312 % but was left at the end, braced. If this is the case we use the fallback
1313 % |\def\FNH@prefntext{\@makefntext{}}|, which may work.
1314 % \begin{macrocode}
1315 \def\FNH@checkagain@{%
1316 \expandafter\FNH@checkagain@a
1317 \detokenize\expandafter{\@makefntext{1.2!3?4,}}\relax\FNH@@@
1318 }%
1319 \edef\FNH@temp{\noexpand\FNH@checkagain@a ##1\string{1.2!3?4,\string}}%
1320 \expandafter\def\FNH@temp#2#3\FNH@@@{%
1321 \ifx\relax#2%
1322 \def\FNH@prefntext{\@makefntext{}}%
1323 \iffootnotehyperwarn
1324 \PackageInfo{footnotehyper}%
1325 {Using the \string\@makefntext{} approach (see doc).\FNH@msgbk
1326 In case of dysfunctional footnote environments, you can\FNH@msgbk
1327 try sending the author a small illustrative document.\FNH@msgbk
1328 To turn off this message, add \string\footnotehyperwarnfalse\FNH@msgbk
1329 to the preamble\@gobble}% "noline"
1330 \fi
1331 \else\FNH@bad@makefntext@alert
1332 \fi
1333 }%
1334 % \end{macrocode}
1335 % Let's check that |pre| and |post| do not
1336 % contain some weird stuff caused from an original |\@makefntext{#1}| containing
1337 % |#1| multiple times.
1338 % \begin{macrocode}
1339 \def\FNH@check@b #1\relax{%
1340 \expandafter\expandafter\expandafter\FNH@check@c
1341 \expandafter\meaning\expandafter\FNH@prefntext
1342 \meaning\[email protected]!3?4,\FNH@check@c\relax
1343 }%
1344 \def\FNH@check@c #11.2!3?4,#2#3\relax{%
1345 \ifx\FNH@check@c#2\else\FNH@bad@makefntext@alert\fi
1346 }%
1347 % \end{macrocode}
1348 % Hard to decipher |\@makefntext|, so warn user and (|1.1e|) use as
1349 % fall-back the code from the |article| class with a safety |\@nameuse| layer.
1350 % \begin{macrocode}
1351 \def\FNH@bad@makefntext@alert{%
1352 \iffootnotehyperwarn
1353 \PackageWarningNoLine{footnotehyper}%
1354 {\FNH@msgbk
1355 Failed to analyse \string\@makefntext\space into something usable.\FNH@msgbk
1356 Using as fall-back the article class code.\FNH@msgbk
1357 You may try to email the author this problematic meaning:\FNH@msgbk
1358 \meaning\@makefntext\FNH@msgbk
1359 together with the document preamble (in particular if\FNH@msgbk
1360 footnote numbers do not show at bottom of page)}%
1361 \fi
1362 \let\FNH@prefntext \FNH@prefntext@fallback
1363 \let\FNH@postfntext\FNH@postfntext@fallback
1364 }%
1365 \def\FNH@prefntext@fallback{% from article class code with \@nameuse added
1366 \parindent 1em\noindent
1367 \hb@[email protected]{\hss\@textsuperscript{\normalfont\@nameuse{@thefnmark}}}%
1368 }%
1369 \let\FNH@postfntext@fallback\@empty
1370 % \end{macrocode}
1371 % \end{macro}\end{macro}\end{macro}
1372 % \begin{macro}{\makesavenoteenv}
1373 % \begin{itemize}
1374 % \item with LaTeX prior to October 2020 release, this is the same as
1375 % original. Not recommended. Safer to use explicitely |savenotes|
1376 % environment.
1377 % \item with LaTeX from October 2020 or later, a safer approach is applied which
1378 % goes either via the hook mechanism (for the use case with no optional
1379 % argument), or via a |\newenvironment| and cautious
1380 % use of the public |\begin| and |\end| interface (for the use case with an
1381 % optional argument), rather than fiddling with |\foo| and |\endfoo| macros.
1382 % \end{itemize}
1383 % \begin{macrocode}
1384 \def\makesavenoteenv{\@ifnextchar[\FNH@msne@ii\FNH@msne@i}%]
1385 \def\FNH@msne@i #1{%
1386 \expandafter\let\csname FNH$#1\expandafter\endcsname %$
1387 \csname #1\endcsname
1388 \expandafter\let\csname endFNH$#1\expandafter\endcsname %$
1389 \csname end#1\endcsname
1390 \FNH@msne@ii[#1]{FNH$#1}%$
1391 }%
1392 \def\FNH@msne@ii[#1]#2{%
1393 \expandafter\edef\csname#1\endcsname{%
1394 \noexpand\savenotes
1395 \expandafter\noexpand\csname#2\endcsname
1396 }%
1397 \expandafter\edef\csname end#1\endcsname{%
1398 \expandafter\noexpand\csname end#2\endcsname
1399 \noexpand\expandafter
1400 \noexpand\spewnotes
1401 \noexpand\if@endpe\noexpand\@endpetrue\noexpand\fi
1402 }%
1403 }%
1404 \@ifl@t@r\fmtversion{2020/10/01}{%
1405 \def\FNH@msne@i#1{%
1406 \AddToHook{env/#1/before}{\savenotes}%
1407 \AddToHook{env/#1/after}{\spewnotes}%
1408 }%
1409 \def\FNH@msne@ii[#1]#2{%
1410 \newenvironment{#1}{\begin{savenotes}\begin{#2}}%
1411 {\end{#2}\end{savenotes}}%
1412 }%
1413 }%
1414 {}%
1415 % \end{macrocode}
1416 % \end{macro}
1417 % Original footnote.sty patches |\parbox|, we don't touch it. Also it defines a
1418 % |minipage*| environment, we don't do it.
1419 % \begin{macrocode}
1420 % \makesavenoteenv[minipage*]{minipage}
1421 % \let\fn@parbox\parbox
1422 % \def\parbox{\@ifnextchar[{\fn@parbox@i{}}{\fn@parbox@ii{}}}
1423 % \def\fn@parbox@i#1[#2]{%
1424 % \@ifnextchar[{\fn@parbox@i{#1[#2]}}{\fn@parbox@ii{#1[#2]}}%
1425 % }
1426 % \long\def\fn@parbox@ii#1#2#3{\savenotes\fn@parbox#1{#2}{#3}\spewnotes}
1427 \endinput
1428 % \end{macrocode}
1429 % \MakePercentComment
1430 \Finale
1431 %%
1432 %% End of file `footnotehyper.dtx'.