summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/footnotehyper/footnotehyper.dtx
blob: b42e003c2b18a410811adba50c143487885cd610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
% -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" -*-
%<*none>
\def\dtxtimestamp {Time-stamp: <04-02-2021 at 12:57:09 CET>}
%</none>
%<*!readme>
%%
%% Package: footnotehyper
%% Version: 1.1d (2021/02/04)
%% License: LPPL 1.3c
%% Copyright (C) 2016-2021 Jean-Francois Burnol <jfbu at free dot fr>.
%%
%</!readme>
%<*tex>
\def\pkgname        {footnotehyper}
\def\pkgdate        {2021/02/04}
\def\docdate        {2021/02/04}
\def\pkgversion     {v1.1d}
\def\pkgdescription {hyperref aware footnote.sty (JFB)}
%</tex>
%<*none>
% Definition of \pkgLicense
\begingroup% cette méthode ne marcherait pas avec caractères en dehors de 32-127
    \long\def\firstofone #1{#1}\catcode1=14\catcode2=0
    \catcode`\%=12\catcode`\_=12\endlinechar13\catcode13=13 ^^A
    \catcode32=13\catcode`\\=12^^Brelax^^A
^^Bfirstofone{^^Bendgroup^^Bdef^^BpkgLicense^^A
{% Package: footnotehyper
% Version: 1.1d (2021/02/04)
% License: LPPL 1.3c
% Copyright (C) 2016-2021 Jean-Francois Burnol <jfbu at free dot fr>.
%
% This Work may be distributed and/or modified under the conditions
% of the LaTeX Project Public License, version 1.3c. This version of
% this license is in:
%
% > <http://www.latex-project.org/lppl/lppl-1-3c.txt>
%
% and the latest version of this license is in:
%
% > <http://www.latex-project.org/lppl.txt>
%
% Version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% The Author of this Work is: Jean-Francois Burnol `<jfbu at free dot fr>`
%
% This Work consists of the main source file footnotehyper.dtx and the
% derived files footnotehyper.sty, footnotehyper.ins, footnotehyper.tex,
% footnotehyper.pdf, footnotehyper.dvi.
}}%
\begingroup\catcode1 0 \catcode`\\ 12 
^^Aiffalse
%</none>
%<*readme>
<!-- -->

    Source:  footnotehyper.dtx (v1.1d 2021/02/04)
    Author:  Jean-Francois Burnol
    Info:    hyperref aware footnote.sty
    License: LPPL 1.3c
    Copyright (C) 2016-2021 Jean-Francois Burnol <jfbu at free dot fr>.


ABSTRACT
========

The `footnote` package by Mark Wooding (`1997/01/28` `1.13`)
allows to gather footnotes (`\begin{savenotes}`) and later insert
them (after `\end{savenotes}`) at the bottom of the page, even
if the intervening material consists of tabulars, minipages or
framed contents for example. One can also use the
`\savenotes/\spewnotes` syntax.

Also, `footnote.sty` provides a `footnote` environment which
allows to insert verbatim material.

Earlier releases of the present `footnotehyper` package added
patches for `hyperref` compatibility and some bugfixes, addressing
in particular the incompatibility with `color/xcolor`, and with
`babel-frenchb`, and also fixing the `footnote` environment with
optional argument `[NUM]`. Since `v0.99` all macros are defined
internally and the `footnote` package is not loaded at all.

The same user interface is kept. Since `v1.0` it is possible to
use `footnotehyper` also in absence of `hyperref` or when the latter is
loaded with its `hyperfootnotes=false` option. The order of loading of
`footnotehyper` and `hyperref` is inconsequential.

INSTALLATION
============

The recommended way is to first extract the package (.sty)
and driver (.tex) files from footnotehyper.dtx via

    tex footnotehyper.dtx

and then produce the documentation via

    latex footnotehyper.tex (twice)
    dvipdfmx footnotehyper.dvi

It is also possible to produce simultaneously the package
and the documentation via one of these two routes:

    pdflatex footnotehyper.dtx (twice)

or

    latex footnotehyper.dtx (twice)
    dvips
    ps2pdf

The method using the extracted file footnotehyper.tex produces
the smallest pdf file and is the officially preferred one as
it allows to set options in footnotehyper.tex to customize the
footnotehyper.pdf file:

- scrdoc class options (paper size, font size, ...)
- with or without source code,
- with dvipdfmx or with latex+dvips or pdflatex.

Installation:

    footnotehyper.sty    -> TDS:tex/latex/footnotehyper/footnotehyper.sty
    footnotehyper.dtx    -> TDS:source/latex/footnotehyper/footnotehyper.dtx
    footnotehyper.pdf    -> TDS:doc/latex/footnotehyper/footnotehyper.pdf
    README.md            -> TDS:doc/latex/footnotehyper/README.md

The other files may be discarded.


LICENSE
=======

This Work may be distributed and/or modified under the conditions
of the LaTeX Project Public License, version 1.3c. This version of
this license is in:

> <http://www.latex-project.org/lppl/lppl-1-3c.txt>

and the latest version of this license is in:

> <http://www.latex-project.org/lppl.txt>

Version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.

The Author of this Work is:

- Jean-Francois Burnol `<jfbu at free dot fr>`

This Work consists of the main source file footnotehyper.dtx
and the derived files footnotehyper.sty, footnotehyper.tex,
footnotehyper.pdf, footnotehyper.dvi.
%</readme>
%<*tex>-------------------------------------------------------------------------
%%
%% run latex twice on this file footnotehyper.tex then dvipdfmx on
%% footnotehyper.dvi to produce the documentation footnotehyper.pdf, with
%% source code included.
%%
\chardef\Withdvipdfmx 1 % replace 1 by 0 for using latex+dvips or pdflatex
\chardef\NoSourceCode 0 % replace 0 by 1 for the doc *without* the source code
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile {\pkgname.tex}[Driver for \pkgname\space documentation]%
\PassOptionsToClass   {a4paper,fontsize=11pt,oneside}{scrdoc}
\PassOptionsToPackage {english}{babel}
\input \pkgname.dtx
%%% Local Variables:
%%% mode: latex
%%% End:
%</tex>-------------------------------------------------------------------------
%<*none>------------------------------------------------------------------------
^^Afi^^Aendgroup
%
\chardef\noetex 0
\ifx\numexpr\undefined\chardef\noetex 1 \fi
\ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop
\else
    \ifx\ProvidesFile\undefined
      \chardef\extractfiles 0 % etex etc.. on \pkgname.dtx, only file extraction.
    \else % latex/pdflatex on \pkgname.tex or on \pkgname.dtx
      \ifx\Withdvipdfmx\undefined
        % latex/pdflatex run is on \pkgname.dtx
        \chardef\extractfiles 1 % 1 = extract files and typeset manual, 2 = only typeset
        \chardef\Withdvipdfmx 0 % 0 = pdflatex or latex+dvips, 1 = dvipdfmx
        \chardef\NoSourceCode 0 % 0 =  include source code, 1 = do not
        \NeedsTeXFormat {LaTeX2e}%
        \PassOptionsToClass   {a4paper,fontsize=11pt,oneside}{scrdoc}%
        \PassOptionsToPackage {english}{babel}%
      \else % latex run is on \pkgname.tex
        \chardef\extractfiles 2 % do not extract files, only typeset
      \fi
      \ProvidesFile{\pkgname.dtx}%
        [\pkgname\space source and documentation (\dtxtimestamp)]%
    \fi
\fi
\ifnum\extractfiles<2 % extract files
\def\MessageDeFin{\newlinechar10 \let\Msg\message
\Msg{********************************************************************^^J}%
\Msg{*^^J}%
\Msg{* To finish the installation you have to move the following^^J}%
\Msg{* file into a directory searched by TeX:^^J}%
\Msg{*^^J}%
\Msg{*\space\space\space\space \pkgname.sty^^J}%
\Msg{*^^J}%
\Msg{* To produce the documentation with source code included run latex^^J}%
\Msg{* twice on file \pkgname.tex and then dvipdfmx on \pkgname.dvi^^J}%
\Msg{*^^J}%
\Msg{* Happy TeXing!^^J}%
\Msg{*^^J}%
\Msg{********************************************************************^^J}%
}%
\begingroup
    \input docstrip.tex
    \askforoverwritefalse
    \def\pkgpreamble{\defaultpreamble^^J\MetaPrefix^^J%
    \string\NeedsTeXFormat{LaTeX2e}^^J%
    \string\ProvidesPackage{\pkgname}\perCent^^J%
    \space[\pkgdate\space\pkgversion\space\pkgdescription]}%
    \generate{\nopreamble\nopostamble
    \file{README.md}{\from{\pkgname.dtx}{readme}}%
    \usepostamble\defaultpostamble
    \file{\pkgname.tex}{\from{\pkgname.dtx}{tex}}%
    \usepreamble\pkgpreamble
    \file{\pkgname.sty}{\from{\pkgname.dtx}{package}}}%
\endgroup
\fi % end of file extraction (from etex/latex/pdflatex run on \pkgname.dtx)
\ifnum\extractfiles=0 % tex/etex/xetex/etc on \pkgname.dtx, files extracted, stop
      \MessageDeFin\expandafter\end
\fi
% From this point on, run is necessarily with e-TeX.
% Check if \MessageDeFin got defined, if yes put it at end of run.
\ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi
%-------------------------------------------------------------------------------
% START OF USER MANUAL TEX SOURCE
\documentclass[abstract]{scrdoc}

\ifnum\NoSourceCode=1 \OnlyDescription\fi

\usepackage{ifpdf}
\ifpdf\chardef\Withdvipdfmx 0 \fi

\makeatletter
\ifnum\Withdvipdfmx=1
   \@for\@tempa:=hyperref,bookmark,graphicx,xcolor,pict2e\do
            {\PassOptionsToPackage{dvipdfmx}\@tempa}
   %
   \PassOptionsToPackage{dvipdfm}{geometry}
   \PassOptionsToPackage{bookmarks=true}{hyperref}
   \PassOptionsToPackage{dvipdfmx-outline-open}{hyperref}
% obsolète
%   \PassOptionsToPackage{dvipdfmx-outline-open}{bookmark}
   %
   \def\pgfsysdriver{pgfsys-dvipdfm.def}
\else
   \PassOptionsToPackage{bookmarks=true}{hyperref}
\fi
\makeatother

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage {babel}

\usepackage[hscale=0.72,vscale=0.7]{geometry}

\def\MacroFont{\ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax}

\usepackage{amsmath}
\usepackage{newtxtext, newtxmath}
\usepackage[straightquotes, scaled=0.97]{newtxtt}
\usepackage{xspace}

\usepackage[dvipsnames]{xcolor}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\definecolor{BLUE}{RGB}{0,0,255}
\colorlet{niceone}{green!35!blue!75}

\usepackage{framed}

\usepackage[pdfencoding=pdfdoc]{hyperref}
\hypersetup{%
linktoc=all,%
breaklinks=true,%
colorlinks,%
linkcolor=RoyalBlue,%
urlcolor=OliveGreen,%
pdfauthor={Jean-Fran\c cois Burnol},%
pdftitle={The \pkgname\space package},%
pdfsubject={\pkgdescription},%
pdfkeywords={LaTeX, footnotes},%
pdfstartview=FitH,%
pdfpagemode=UseNone}
% added usage of package bookmark 2013/10/10
\usepackage{bookmark}
\usepackage{enumitem}
\usepackage{\pkgname}

\newcommand\fnh{%
        \texorpdfstring{{\color{joli}\ttfamily\bfseries \pkgname}}{\pkgname}\xspace}

\frenchspacing

\renewcommand\familydefault\sfdefault
\pagestyle{headings}

\begin{document}\thispagestyle{empty}
% the \MacroFont valid at begin document will be the one used in Implementation
% the one defined here will be used by verbatim (not by \verb)
\def\MacroFont{\ttfamily\small}
\rmfamily
\bookmark[named=FirstPage,level=1]{Title page}

\begin{center}
  {\normalfont\LARGE The \fnh  package}\\
\textsc{\small Jean-François Burnol}\par
  \footnotesize \ttfamily
  jfbu (at) free (dot) fr\par
  Package version: \pkgversion\ (\pkgdate)\par
  From source file \texttt{\pkgname.dtx} of \dtxtimestamp.\par
\end{center}

\MakeShortVerb{\`}%
\begin{abstract}
The `footnote` package by \textsc{Mark~Wooding} (`1997/01/28` `1.13`)
allows to gather footnotes (`\begin{savenotes}`) and later insert
them (after `\end{savenotes}`) at the bottom of the page, even
if the intervening material consists of tabulars, minipages or
framed contents for example. One can also use the
`\savenotes/\spewnotes` syntax.

Also, `footnote.sty` provides a `footnote` environment which
allows to insert verbatim material.

Earlier releases of the present \fnh package added
patches for `hyperref` compatibility and some bugfixes, addressing
in particular the incompatibility with `color/xcolor`, and with
`babel-frenchb`, and also fixing the `footnote` environment with
optional argument `[NUM]`. Since `v0.99` all macros are defined
internally and the `footnote` package is not loaded at all.

The same user interface is kept. Since `v1.0` it is possible to
use \fnh also in absence of `hyperref` or when the latter is
loaded with its `hyperfootnotes=false` option. The order of loading of
\fnh and `hyperref` is inconsequential.
\end{abstract}
\DeleteShortVerb{\`}

\section{License}

\begingroup\ttfamily\footnotesize\hyphenchar\font -1
           \parindent0pt 
           \obeyspaces\obeylines %
\pkgLicense\endgroup

\section{Changes}

\begin{description}
\item[v0.9c (2016/04/19)] First release: adapt original package to be
  |hyperref| and |color/xcolor| compatible.

\item[v0.9e (2016/04/30)] Abort in absence of |hyperref|. Compatibility with
  |babel-french|.

\item[v0.99 (2017/02/16)] Do not load package
  |footnote.sty|\footnote{\url{http://ctan.org/pkg/footnote}} anymore. 

  From then on \fnh is
  incompatible with it at it uses the same user interface.

\item[v1.0 (2017/03/07)] Be usable also in absence of |hyperref| or when the
  latter was passed |hyperfootnotes=false| option.

\item[v1.1 (2018/01/23)] Fix bug which arose when |savenotes| environment was used
  \emph{inside} a minipage: footnotes were disappearing!%
%
\footnote{Thanks to François Pantigny for reporting the bug. A later
  suggestion of the same is to let the package do nothing under Beamer class,
  and this is what |v1.1a 2019/11/07| does.}
%
See related remarks at end of \autoref{sec:notes}.

\item[v1.1a (2019/11/07)] Abort under |beamer| (difficulty with |@makefntext|
  and suspicion |beamer| does not need \fnh).

\item[v1.1b (2021/01/26)] Fix incompatibility with the combination |memoir| +
  |babel-french|.

\item[v1.1c (2021/01/29)] Fix legacy bug of original package interfering with
  \LaTeX2e mechanism to suppress indentation after mid-paragraph lists (when
  |savenotes| environment directly wraps the enclosed list environment,
  mid-paragraph).

\item[v1.1d (2021/02/04)] Fix regression at |v1.1b| which caused a build crash
  whenever \fnh decided to raise a warning relative to |\@makefntext|.%
%
\footnote{Thanks to Leon K. for reporting the bug.}

  Refactor analysis of \cs{@makefntext} for simpler and better support of
  |babel-french|.%
\footnote{Only basic
  context has been tested with |babel-french|: standard classes, |KOMA|-script,
  |memoir|. Extra packages may make the \fnh environments cause breakage.}
%
  Better support
  contexts such as presence of package |cleveref|.%

  Add \verb=\iffootnotehyperparse= and \verb=\iffootnotehyperwarn= booleans.

\end{description}
\section{Usage}

As summarized in the abstract, the package provides:
\begin{savenotes}% juste pour vérifier le fix à 1.1c
  \begin{itemize}
  \item a |savenotes| environment which re-routes footnotes and delivers them
    at the end (there is also the |\savenotes/\spewnotes| syntax; which does
    create a group like the environment),
  \item |footnote| and |footnotetext| environments to allow footnotes with
    verbatim material.
  \end{itemize}
\end{savenotes}
Setting-up the environments proceeds from an analysis of the pre-existing
internal \LaTeX\ macro |\@makefntext|. The next section discusses problems
which may arise.

\subsection{Potential difficulties with the footnote and footnotetext
  environments}

  What is discussed here only affects the \emph{environments} |footnote| and
  |footnotetext| not the macros \cs{footnote} and \cs{footnotetext}.

  \fnh inherits from |footnote| original package the aim to
  convert |\@makefntext| into two parts, the first one to be inserted
  at the start of a footnote in environment form, the second one (usually
  empty) at its end.%
%
\begin{footnote}
  \LaTeX\ inserts some stuff before and after the footnote text, even before
  handing it over as argument to \cs{@makefntext}. These tokens are currently
  hardcoded into the \fnh environments for footnotes.
\end{footnote}
%
  It thus hopes that the replacement text of |\@makefntext| contains only once
  its parameter token |#1|, and that it is used there unbraced. This is the case
  with the |article| class.

  Known bug (may be promoted to feature at some point): the analysis is done
  only once at begin document, whereas the |article.cls|'s redefines
  |\@makefntext| during execution of |\maketitle|. However, it does not look
  really urgent to support at all costs usage of the environment |footnote| in
  the |\author| etc... data which contributes to the |\maketitle| expansion.%
%
    \begin{footnote}
\phantomsection\label{fn:texperts}%
      \TeX perts note: |\def\FNH@prefntext{\@makefntext{}}| would make the
      footnote environment dynamically adjust to circumstances, when
      |\@makefntext| only adds some prefix and no postfix. In fact, this is
      (in a more complicated form for compatibility with |KOMA|-script and to
      obey the |FBFrenchFootnotes| setting and the additional extra stuff
      inserted by |babel-french| before and after) basically what is done by
      \fnh to handle
      |babel-french|.

      As it may cause instability if extra packages fiddle
      with |\@makefntext|, or |\@makefntext| is radically re-defined in some
      environments provided by the class, \fnh does not use this when its
      begin document analysis concluded the argument was used unbraced and at
      last position in replacement text of |\@makefntext|, but it freezes the
      found prefix. However, when it is concluded that probably |\@makefntext|
      has been redefined in an |<extra tokens>\old@makefntext| way (for
      example, this is the case with |cleveref| package), then the
      |\def\FNH@prefntext{\@makefntext{}}| approach is taken, despite the
      risks inherent to it.

      You can provide your own definitions of
      \cs{FNH@prefntext} and \cs{FNH@postfntext}. Then add
      \cs{footnotehyperparsefalse} to the preamble.
    \end{footnote}

  Some seemingly innocent redefinitions such as the one
  of |beamer| which was last time I checked (that was in 2019):
\begin{verbatim}
macro:#1->\def \insertfootnotetext {#1}\def \insertfootnotemark
{\@makefnmark }
\usebeamertemplate ***{footnote}
\end{verbatim}
  are not (easily) compatible with environment forms for footnotes
  allowing verbatim material, as they require fetching the footnote
  contents.%
  \footnote{%\phantomsection\label{fn:beamer}% test, ça marche!
  Since |v1.1a|, \fnh simply aborts under |beamer| class.}

  In case of such a problematic |\@makefntext| \fnh raises a warning, to
  explain that footnotes typeset using the environment forms will be
  dysfunctional (the footnote marker at bottom of page will be missing,
  probably). Footnotes using |\footnote| are not impacted by this.

  % See \ref{fn:beamer} % test, ça marche, aussi avec environnement

  Also \fnh emits some info message if |\@makefntext| was not as simple as
  expected but nevertheless there is some hope that the |footnote| and
  |footnotetext| environments will be fully functional. This is currently the
  case in presence of package |cleveref| (see the \TeX perts
  footnote \ref{fn:texperts}).

  You can turn off these messages by adding \cs{footnotehyperwarnfalse}
  to the document preamble.

\subsection{Other potential or actual limitations}

It should be recalled that in case of |\footnotemark[N]| and
|\footnotetext[N]{...}| mark-up |hyperref| creates no hyperlink. This is not
changed by \fnh and applies also to the |\begin{footnotetext}[N]| case.
Without optional argument the link is created, and the link is created also
for |\footnote[N]| or |\begin{footnote}[N]|.

This package does not handle especially floating environments, except that one
can always surround them in the source in a |savenotes| environment and one
knows that the footnotes will be delivered at the |\end{savenotes}|\dots which
may well be one page earlier than the actual location of the floating material
in the produced document !

Environments typesetting multiple times their contents are the most hostile to
footnotes. Currently, \fnh only handles especially the |amsmath|
environments (as in |footnote.sty|.)

\subsection{A legacy macro from the original package, usage not recommended}

Finally there is a |\makesavenoteenv| command which takes as
argument an environment name and patches it to do the
|\savenotes/\spewnotes| automatically.%
\begin{footnote}
  For the
record the syntax is either |\makesavenoteenv{foo}| which patches
environment |foo| or |\makesavenoteenv[bar]{foo}| which defines
environment |bar| as this patched version of |foo|.
\end{footnote}
It is safer to avoid it, as
one never knows what happens with such patches: for example the |[H]|
specifier provided by the |float| package overwrites the |\end{table}|
definition during the execution of |\begin{table}|\dots !

\subsection{Example of use}
\begin{savenotes}
\begin{framed}
\DeleteShortVerb{\|}\MakeShortVerb{\*}%
{\centering
  \begin{tabular}{|c|c|}
    \hline
    \strut Inside\footnote{If the frame
      extends to the next page,
      the end of the *savenotes* environment delivers its intercepted
      footnotes only there.} a & tabular\begin{footnote}Alternatively a
      *\savenotes/\spewnotes* pair
      could have been used.\end{footnote}\\\hline
\end{tabular}\par}
\DeleteShortVerb{\*}\MakeShortVerb{\|}%
Here is an illustrative example of usage of the |savenotes| environment:
\begin{verbatim}
\begin{savenotes}
\begin{framed}
  Please refer to the documentation of the |footnote| package.%
  \footnote{\url{http://ctan.org/pkg/footnote}}

  Particularly you may check its |savenotes| environment.%
  \footnote{\phantomsection\label{fn:floats}It doesn't bring any
  feature to especially handle the issues related to footnotes in floating
  environments, though.}
\end{framed}
\end{savenotes}
Here is a link to an interesting footnote: \ref{fn:floats}.
\end{verbatim}
and the present frame has \cs{footnote}'s from inside a |tabular| and is
inside a |savenotes| environment.%
\begin{footnote}\phantomsection\label{fn:minipage}
  Here is an issue which has nothing (as I finally figured out) to
  do with |footnote|, and only indirectly with \LaTeX: if you embed
  a \emph{full-width} minipage (with initial \cs{noindent}) in any
  environment not doing \cs{ignorespacesafterend}, be careful to add
  a \% either immediately after the |\end{minipage}| (or a |\relax|
  or a |\par|) or after the surrounding environment |\end{foo}| or
  use |\end{minipage}\end{foo}| else the output may have an extra
  blank line if the source has a blank line after the |foo| environment.
  Here is a typical example, with a |tabular| rather:
  \makeatletter

  \medskip\noindent\hspace{1cm}\begin{minipage}{\dimexpr\linewidth-1cm}%
  \def\MacroFont{\baselineskip10pt\relax}%
\begin{verbatim}
\newenvironment{foo}{}{}

\noindent\begin{tabular}{p{\dimexpr\linewidth-2\tabcolsep\relax}}
  A\dotfill B
\end{tabular}

C

\begin{foo}
\noindent\begin{tabular}{p{\dimexpr\linewidth-2\tabcolsep\relax}}
  A\dotfill B
\end{tabular}
\end{foo}

C
\end{verbatim}\end{minipage}\par\medskip

  If you try it out you will see an extra blank line in PDF output above the
  second C. Starting with |v0.99| the |\end{savenotes}| emits an
  \cs{ignorespacesafterend} which avoids this generic \TeX/\LaTeX\
  problem. For good measure there is now an \cs{ignorespaces} in
  |\begin{savenotes}|.
\end{footnote}
Let's test an
|amsmath| environment with |\intertext|. As
\begin{align}
  E&=mc^2\;,
\intertext{was too easy\footnote{There is also $E=h\nu$.}, let's
  try:}
  a^n + b^n &=c^n\;.
\end{align}
And a footnote with some verbatim material%
\begin{footnote}
  \verb|&$^%\[}$|
\end{footnote}.
\end{framed}
\end{savenotes}

The last one was coded as:
\begin{verbatim}
And a footnote with some verbatim material%
\begin{footnote}
  \verb|&$^%\[}$|
\end{footnote}.
\end{verbatim}
Now some use of |\footnotemark|\footnotemark\ followed by a |footnotetext|
environment.
\begin{footnotetext}
  This one uses the normal footnote counter and the hyperlink works.
\end{footnotetext}
And use of |\footnotemark[99]|\footnotemark[99] in association with a
|footnotetext| environment using the same optional argument |[99]|.
No hyperfootnote link was inserted.%
\begin{footnotetext}[99]
  |hyperref| creates no hyperlink in this case, or in the
  |\footnotemark[N]/\footnotetext[N]{<foo>}| case. It does when
  the |[N]| is absent or when it is used with a |\footnote| command
  (or a |footnote| environment.)
\end{footnotetext}
And a final footnote, done with |\begin{footnote}[57]|%
\begin{footnote}[57]%\csname @minipagetrue\endcsname % to reduce
%                                % framed inserted vertical spacing
%  \begin{framed}
%    \noindent
    \fnh works since |v1.0| also in absence of |hyperref| or when the
    latter was passed |hyperfootnotes=false| option.
%  \end{framed}
\end{footnote}.
There is no problem with the hyperlink, then. Oh, and don't forget to read
this interesting footnote: \ref{fn:minipage} (just in case you skipped on
first reading).

\section{Notes}\label{sec:notes}

A few items worth of mention:
\begin{itemize}[nosep]
\item the |footnote| package patches the \LaTeX\ kernel |\parbox|.
  \fnh doesn't (but the code can be found commented-out at the
  end of the present file).
\item the |footnote| package defines a |minipage*| environment
  which is |minipage| patched by |\makesavenoteenv|, \fnh doesn't.
\item the |footnote| environment from |footnote.sty| does a
  |\leavevmode\unskip| which \fnh doesn't: hence if one locates
  |\begin{footnote}| at start of a line in the \LaTeX\ source, one will
    typically need a \% at end of text on previous line to avoid the
    end-of-line space.
\item the |hyperref| package inserts no hyperlink in case of
  |\footnotemark[N]/\footnotetext[N]|. This is not modified by \fnh.
\item side-note: there is an interference between |hyperref| and |frenchb|
  regarding the footnote marker when using the syntax |\footnotemark[NUM]|.
  For the record here is a patch (last tested briefly with
% PUTAIN BORDEL ! LaTeX Error: Text for \verb command ended by end of
% line. À CHAQUE FOIS ÇA M'AGAÇE. Bon, je n'ai pas mon patch habituel ici.
  |hyperref 2016/06/24 v6.83q| and |frenchb 2017/01/30 v3.2g|):
% pour le cas où mis dans commentaires de code
% \begingroup\makeatletter\let\check@percent\@gobble
\begin{verbatim}
  \AtBeginDocument{%
   \let\@xfootnotemarkORIFB \@xfootnotemark
   \def\@xfootnotemarkFB {\leavevmode\unskip\unkern\,\@xfootnotemarkORIFB }%
   \ifHy@hyperfootnotes\ifFBAutoSpaceFootnotes
       \let\@xfootnotemark\@xfootnotemarkFB
   \fi\fi
  }%
\end{verbatim}
On |2021/01/29| the interference (lost of some |babel-french| customization)
is still there, as I checked now. This has nothing to do with \fnh.
% \endgroup
\item some environments typeset multiple times their contents,
  which causes issues; \fnh takes provisions only to handle the
  |amsmath| measuring step.
\item
  \LaTeX2e has some ``features'' when using footnotes in |minipage|'s
  which are themselves in a |minipage| which may also have footnotes externally
  to the internal minipages... try it out with some |\fbox|es around the
  sub-|minipages|, to see.

  \fnh behaves like original package |footnote| when the |savenotes|
  environment is used \emph{inside} a minipage. Only reasonable usage in case
  of nested minipages seems to use only a single top level (i.e. external)
  |savenotes| environment. But there will anyhow be collisions of the
  alphabetic enumerations. These collisions are there with or without \fnh (or
  |footnote.sty|.) I did not make any attempt, nor intend to in future, to
  address in an automatized manner these problematic contexts.
\end{itemize}

\StopEventually{\end{document}\endinput}
\makeatletter
    \let\check@percent\original@check@percent
\makeatother

\newgeometry{left=4cm, hscale=0.72}
\section{Implementation}

\small

\makeatletter
\noindent
\begingroup
\topsep\MacrocodeTopsep
\trivlist\parskip\z@\item[]
\macro@font
\leftskip\@totalleftmargin  \advance\leftskip\MacroIndent
\rightskip\z@  \parindent\z@  \parfillskip\@flushglue
\global\@newlistfalse \global\@minipagefalse
\ifcodeline@index
  \everypar{\global\advance\c@CodelineNo\@ne
  \llap{\theCodelineNo\ \hskip\@totalleftmargin}}%
\fi
\string\NeedsTeXFormat\string{LaTeX2e\string}\par
\string\ProvidesPackage\string{\pkgname\string}\@percentchar\par
\noindent\space [\pkgdate\space\pkgversion\space\pkgdescription]\par
\nointerlineskip
\global\@inlabelfalse
\endtrivlist
\endgroup
\makeatother

% The catcode hackery next is to avoid to have <*package> to be listed
% in the commented source code...
% (c) 2012/11/19 jf burnol ;-)

\MakePercentIgnore

%
% \catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11
% \let</none>\relax
% \def<*package>{\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12}
%
%</none>
%<*package>
% \begin{macro}{no options}
% The package has no options. I am too lazy.
%    \begin{macrocode}
\newif\iffootnotehyperparse\footnotehyperparsetrue
\newif\iffootnotehyperwarn \footnotehyperwarntrue
\DeclareOption*%
    {\PackageWarning{footnotehyper}{Option `\CurrentOption' is unknown}}%
\ProcessOptions\relax
%    \end{macrocode}
% \end{macro}
% |v1.1a| lets the package abort under Beamer class and warn user.
%    \begin{macrocode}
\@ifclassloaded{beamer}
    {\PackageWarningNoLine{footnotehyper}{This package is
        incompatible with the beamer class. Aborting input..}%
     \endinput}
    {}%
%    \end{macrocode}
% Versions up to |v0.9f| loaded |footnote.sty|, with lots of patching
% afterwards. Starting with |v0.99|, \fnh does everything by itself with |FNH@|
% prefix. Brief overview of some of the fixed issues:
% \begin{itemize}[nosep]
% \item there was incompatibility with |hyperref|,
% \item and with |color|,
% \item if the \cs{@makefntext} at the time of loading of |footnote.sty|
%   does not have its argument visible at top level in its meaning, or
%   is used multiple times there, then the footnote environment will lead to low
%   level \TeX\ error,
% \item |footnote.sty| modifies |\parbox|,
% \item |footnote.sty| does some too early |\let|,
% \item the footnote environment from |footnote.sty| does not work if used with
% optional argument |[N]|.
% \end{itemize}
%
% \noindent Starting with |v1.0|, \fnh may be used also in absence
% of |hyperref|.
%    \begin{macrocode}
\newbox\FNH@notes
\newdimen\FNH@width
\newtoks\FNH@toks % 1.1c
\let\FNH@colwidth\columnwidth
\newif\ifFNH@savingnotes
\AtBeginDocument {%
    \let\FNH@latex@footnote    \footnote
    \let\FNH@latex@footnotetext\footnotetext
    \let\FNH@H@@footnotetext   \@footnotetext
    \let\FNH@H@@mpfootnotetext \@mpfootnotetext
    \newenvironment{savenotes}
        {\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
    \let\spewnotes      \FNH@spewnotes
    \let\footnote       \FNH@footnote
    \let\footnotetext   \FNH@footnotetext
    \let\endfootnote    \FNH@endfntext
    \let\endfootnotetext\FNH@endfntext
    \@ifpackageloaded{hyperref}
     {\ifHy@hyperfootnotes
         \let\FNH@H@@footnotetext\H@@footnotetext
         \let\FNH@H@@mpfootnotetext\H@@mpfootnotetext
      \else
         \let\FNH@hyper@fntext\FNH@nohyp@fntext
      \fi}%
     {\let\FNH@hyper@fntext\FNH@nohyp@fntext}%
}%
%    \end{macrocode}
% \begin{macro}{\FNH@hyper@fntext}
% \begin{macro}{\FNH@nohyp@fntext}
% \begin{macro}{\FNH@fntext}
% These are the \fnh replacement for |\@footnotetext| inside the
% |savenotes| environment. There is a version creating an hyperlink
% and another one not creating an hyperlink. The \cs{FNH@fntext}
% macro serves as general dispatch. This may be a place to customize if one
% wants to handle environments doing multiple passes: but the footnote counter
% must have been taken care of elsewhere. The code currently handles only
% the case of |amsmath| environments.
%    \begin{macrocode}
\def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}%
\def\FNH@nohyp@fntext{\FNH@fntext\FNH@nohyp@fntext@i}%
\def\FNH@fntext #1{\ifx\ifmeasuring@\@undefined
    \expandafter\@secondoftwo\else\expandafter\@firstofone\fi
    {\ifmeasuring@\expandafter\@gobbletwo\fi}#1%
}%
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
% \begin{macro}{\FNH@hyper@fntext@i}
% We do the \cs{ifHy@nesting} test although hyperref's manual
% says ``Allows links to be nested; no drivers currently support this.''
%    \begin{macrocode}
\long\def\FNH@hyper@fntext@i#1{%
  \global\setbox\FNH@notes\vbox
  {\unvbox\FNH@notes
   \FNH@startnote
   \@makefntext
    {\rule\z@\footnotesep\ignorespaces
     \ifHy@nesting\expandafter\ltx@firstoftwo
             \else\expandafter\ltx@secondoftwo
     \fi
     {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}{#1}}%
     {\Hy@raisedlink
       {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}%
       {\relax}}%
      \let\@currentHref\Hy@footnote@currentHref
      \let\@currentlabelname\@empty
      #1}%
     \@finalstrut\strutbox
    }%
   \FNH@endnote
  }%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@nohyp@fntext@i}
% The original \cs{fn@fntext} had no \cs{long}.
%    \begin{macrocode}
\long\def\FNH@nohyp@fntext@i#1{%
  \global\setbox\FNH@notes\vbox
  {\unvbox\FNH@notes
   \FNH@startnote
   \@makefntext{\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
   \FNH@endnote
  }%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@startnote}
% Same as original (the code comment is kept from original.)
%    \begin{macrocode}
\def\FNH@startnote{%
  \hsize\FNH@colwidth
  \interlinepenalty\interfootnotelinepenalty
  \reset@font\footnotesize
  \floatingpenalty\@MM% Is this right???
  \@parboxrestore
  \protected@edef\@currentlabel{\csname p@\@mpfn\endcsname\@thefnmark}%
  \color@begingroup
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@endnote}
% Fixed from original.
%    \begin{macrocode}
\def\FNH@endnote{\color@endgroup}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@savenotes}
% Same as original apart from using |hyperref|-aware \cs{FNH@hyper@fntext},
% and taking into account |hyperref|'s custom \cs{@xfootnotenext}. This was
% missed by |v0.9f| hence |\footnotetext[N]{..}| did not work
% inside |savenotes| environment. Fixed for |v0.99|.
% 
% Maybe I should change the way \cs{@minipagerestore} is handled.
%    \begin{macrocode}
\def\FNH@savenotes{%
  \begingroup
  \ifFNH@savingnotes\else
    \FNH@savingnotestrue
    \let\@footnotetext    \FNH@hyper@fntext
    \let\@mpfootnotetext  \FNH@hyper@fntext
    \let\H@@mpfootnotetext\FNH@nohyp@fntext % fool hyperref's \@xfootnotenext
    \FNH@width\columnwidth
    \let\FNH@colwidth\FNH@width
    \global\setbox\FNH@notes\box\voidb@x
    \let\FNH@thempfn\thempfn
    \let\FNH@mpfn\@mpfn
    \ifx\@minipagerestore\relax\let\@minipagerestore\@empty\fi
    \expandafter\def\expandafter\@minipagerestore\expandafter{%
      \@minipagerestore
      \let\thempfn\FNH@thempfn
      \let\@mpfn\FNH@mpfn
    }%
  \fi
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@spewnotes}
% This uses \cs{FNH@H@@footnotetext} which is the
% \cs{H@@footnotetext} |hyperref|'s preserved original
% meaning of \cs{@footnotetext} not creating a link target.
%
% |v1.1| fixes the bug about disappearing footnotes if |savenotes| environment
% is used inside a minipage. I had never really considered such usage, hence
% missed realizing there was a bug.
%
% |v1.1c 2021/01/29| fixes a legacy bug from |footnote| package: if used
% to enclose a list environment inside a paragraph, it broke the
% mechanism which suppresses indentation following the list.
%
% Now, situation would be far simpler here if we did not have this extra
% |\begingroup| |\endgroup| pair in |\FNH@savenotes/\FNG@spewnotes|.
%
% A priori, as far as I understand, testing the |\if@endpe| flag should be
% enough, but let's be extra cautious and check that |\par| is not |\@@par|.
% Attention here that this is not necessarily followed by |\end{savenotes}| and
% we have to support the |\savenotes/\spewnotes| syntax. The complication is
% added from it creating a group without being a genuine \LaTeX2e environment.
%    \begin{macrocode}
\def\FNH@spewnotes {%
  \if@endpe\ifx\par\@@par\FNH@toks{}\else
     \FNH@toks\expandafter{\expandafter
              \def\expandafter\par\expandafter{\par}\@endpetrue}%
     \expandafter\expandafter\expandafter
     \FNH@toks
     \expandafter\expandafter\expandafter
     {\expandafter\the\expandafter\FNH@toks
      \expandafter\def\expandafter\@par\expandafter{\@par}}%
     \expandafter\expandafter\expandafter
     \FNH@toks
     \expandafter\expandafter\expandafter
     {\expandafter\the\expandafter\FNH@toks
      \expandafter\everypar\expandafter{\the\everypar}}\fi
  \else\FNH@toks{}\fi
  \expandafter
  \endgroup\the\FNH@toks
  \ifFNH@savingnotes\else
   \ifvoid\FNH@notes\else
    \begingroup
     \let\@makefntext\@empty
     \let\@finalstrut\@gobble
     \let\rule\@gobbletwo
     \ifx\@footnotetext\@mpfootnotetext
        \expandafter\FNH@H@@mpfootnotetext
     \else
        \expandafter\FNH@H@@footnotetext
     \fi{\unvbox\FNH@notes}%
    \endgroup
   \fi
  \fi
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\FNH@footnote}
% \begin{macro}{\FNH@footnotetext}
%   We now take care of |footnote.sty|'s |footnote| environment. The original
%   \cs{fn@endfntext} is lacking a \cs{fn@endnote}, and this meant that
%   |footnote.sty| was incompatible with |color/xcolor| packages. Also this
%   \cs{fn@endnote} was |\let| to |\color@endgroup| which is wrong.
%
%   Furthermore, independently of presence of the |\color/xcolor| issue, the
%   |footnote.sty|'s |footnote| environment raised an error if used with an
%   optional argument. |v0.9f| addresses this issue.
%
%   The |footnotetext| environment adds a complication, in case of optional
%   argument we should not try to set up a link due to the fact that |hyperref|
%   does not support it for the |\footnotemark[N]/\footnotetext[N]| syntax.
%   And we need to make sure that the |footnote| and |footnotetext| environments
%   obey the |\savenotes/\spewnotes| mechanism.
%
%   To handle all of this we code things completely differently from
%   |footnote.sty|.
% 
%   The |v0.9f| |\begin{footnotetext}[N]| inside |savenotes| tried to create
%   an hyperref target. Fixed for |v0.99|.
%
%   Note: the |footnote.sty| code did a |\leavevmode\unskip| at entrance of
%   |footnote| environment, which \fnh has not kept.
%    \begin{macrocode}
\def\FNH@footnote@envname    {footnote}%
\def\FNH@footnotetext@envname{footnotetext}%
\def\FNH@footnote{%
    \ifx\@currenvir\FNH@footnote@envname
        \expandafter\FNH@footnoteenv
    \else
        \expandafter\FNH@latex@footnote
    \fi
}%
\def\FNH@footnoteenv{%
    \@ifnextchar[%
      \FNH@footnoteenv@i %]
      {\stepcounter\@mpfn
       \protected@xdef\@thefnmark{\thempfn}%
       \@footnotemark
       \def\FNH@endfntext@fntext{\@footnotetext}%
       \FNH@startfntext}%
}%
\def\FNH@footnoteenv@i[#1]{%
    \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
    \@footnotemark
    \def\FNH@endfntext@fntext{\@footnotetext}%
    \FNH@startfntext
}%
\def\FNH@footnotetext{%
    \ifx\@currenvir\FNH@footnotetext@envname
        \expandafter\FNH@footnotetextenv
    \else
        \expandafter\FNH@latex@footnotetext
    \fi
}%
\def\FNH@footnotetextenv{%
    \@ifnextchar[%
      \FNH@footnotetextenv@i %]
      {\protected@xdef\@thefnmark{\thempfn}%
       \def\FNH@endfntext@fntext{\@footnotetext}%
       \FNH@startfntext}%
}%
\def\FNH@footnotetextenv@i[#1]{%
    \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
    \ifFNH@savingnotes
      \def\FNH@endfntext@fntext{\FNH@nohyp@fntext}%
    \else
      \def\FNH@endfntext@fntext{\FNH@H@@footnotetext}%
    \fi
    \FNH@startfntext
}%
%    \end{macrocode}
% \end{macro}\end{macro}
% \begin{macro}{\FNH@startfntext}
% \begin{macro}{\FNH@endfntext}
% \begin{macro}{\FNH@endfntext@fntext}
% This is used for the environmental form of the footnote environments.
% The use of |\box\z@| originates in |footnote.sty|, should I change that ?
%
% Both of \cs{endfootnote} and \cs{endfootnotetext} are aliases for
% \cs{FNH@endfntext}.
%
% The \cs{FNH@endfntext@fntext} may be \cs{@footnotetext} (which will be
% \cs{FNH@hyper@fntext} in |savenotes| environment), or
% \cs{FNH@H@@footnotetext}, or \cs{FNH@nohyp@fntext} if in |savenotes| scope.
%    \begin{macrocode}
\def\FNH@startfntext{%
  \setbox\z@\vbox\bgroup
    \FNH@startnote
    \FNH@prefntext
    \rule\z@\footnotesep\ignorespaces
}%
\def\FNH@endfntext {%
    \@finalstrut\strutbox
    \FNH@postfntext
    \FNH@endnote
    \egroup
  \begingroup
    \let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo
    \FNH@endfntext@fntext {\unvbox\z@}%
  \endgroup
}%
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
% \begin{macro}{\@makefntext}
% \begin{macro}{\FNH@prefntext}
% \begin{macro}{\FNH@postfntext}
% \begin{macro}{\FNH@check}
%   The definitions of |\FNH@prefntext| and |\FNH@postfntext| (which are needed
%   for the |footnote| environment, |\FNH@startfntext| and |\FNH@endfntext|)
%   are extracted from a somewhat daring analysis of |\@makefntext|.
%   Contrarily to |footnote.sty|'s original code (which may result in low level
%   \TeX\ errors when the |footnote| environment is executed)
%   the method here will alert the user if the argument
%   of |\@makefntext| is not visible at top level in its meaning or is used
%   there multiple times. We also insert here some code to handle especially
%   the case of |babel-frenchb|.
%
%   Refactoring at |v1.1d|. This will make \fnh compatible with |cleveref| for
%   example, if nothing else interferes. Not all combinations of classes and
%   packages can be handled and we can not hardcode a pre-analysis for all
%   possible cases. Of course, one can not expect \fnh to be compatible with
%   other footnote dedicated packages, but at best only with slight
%   modifications of \LaTeX's defaults. At |v1.1d| the |babel-french| context
%   is handled especially (to support it better with KOMAscript classes and
%   simplify handling the |memoir| situation); there was no real other way
%   than hardcode it more or less, but it can possibly break in presence of
%   additional footnote packages.
%
%   Also the \cs{iffootnotehyperparse} and \cs{iffootnotehyperwarn} booleans
%   were added.
%
%   Provide at least some definitions for \cs{FNH@prefntext} and
%   \cs{FNH@postfntext} in case of \cs{footnotehyperparsefalse} in preamble.
%    \begin{macrocode}
\let\FNH@prefntext\@empty
\let\FNH@postfntext\@empty
\AtBeginDocument{\iffootnotehyperparse\expandafter\FNH@check\fi}%
%    \end{macrocode}
%
%   As |\ifFBFrenchFootnotes| is not a \TeX\ boolean if |babel-frenchb| isn't
%   loaded, we have to work around this for |\if..\fi| pairs.
%
%   |v1.1d| fixes a |v1.1b| bug: any situation in |\FNH@check@a| causing the
%   |\FNH@bad@makefntext@alert| branch to be chosen crashed the build due
%   precisely to this problem with |\ifFBFrenchFootnotes| status. I had taken
%   precautions for the |\else| branch but not for the ``warning'' branch.
%
%   So let's fix this, and do it in such a way (with \cs{FNH@safeif}) that the
%   \TeX\ |\if..\fi| balancing count does not perturbate enclosing the package
%   loading in a \TeX\ conditional. Why I am bothering, I don't know.
%
%   Finally, I refactored entirely the way |frenchb| context is handled,
%   (using multiple times \cs{FNH@safeif} although now only for the artistic
%   aim of balanced conditionals, as all |frenchb|-related stuff being in
%   their dedicated macro, direct usage of |\ifFB...| is possible).
%
%   As long as nothing else interferes |babel-french| should be ok with
%   standard classes, KOMA and memoir.
%
%    \begin{macrocode}
\def\FNH@safeif#1{%
   \iftrue\csname if#1\endcsname\csname fi\endcsname\expandafter\@firstoftwo
   \else\csname fi\endcsname\expandafter\@secondoftwo
   \fi
}%
\def\FNH@check{%
   \ifx\@makefntextFB\@undefined\expandafter\FNH@check@
                           \else\expandafter\FNH@frenchb@
   \fi
}%
\def\FNH@frenchb@{%
   \def\FNH@prefntext{%
     \localleftbox{}%
     \let\FBeverypar@save\FBeverypar@quote
     \let\FBeverypar@quote\relax
     \FNH@safeif{FB@koma}%
       {\FNH@safeif{FBFrenchFootnotes}%
          {\ifx\footnote\thanks
             \let\@@makefnmark\@@makefnmarkTH
             \@makefntextTH{} % space as in french.ldf
           \else
             \let\@@makefnmark\@@makefnmarkFB
             \@makefntextFB{} % space as in french.ldf
             \fi
          }{\let\@@makefnmark\@@makefnmarkORI
             \@makefntextORI{}% no space as in french.ldf
          }%
       }%
       {\FNH@safeif{FBFrenchFootnotes}%
          {\@makefntextFB{}}%
          {\@makefntextORI{}}%
       }%
   }%
   \def\FNH@postfntext{%
     \let\FBeverypar@quote\FBeverypar@save
     \localleftbox{\FBeveryline@quote}%
   }%
   \iffootnotehyperwarn
    \PackageInfo{footnotehyper}%
      {frenchb compatibility patch activated.^^J It will not work in
       all circumstances.^^J In case of problems with the `footnote' or
       `footnotetext' environments,^^J please send to the author a small
       file demonstrating the problem.^^J To turn off this message, add
       \string\footnotehyperwarnfalse\space to the preamble.^^J}%
   \fi
}%
%    \end{macrocode}
% \end{macro}
%   ``Daring analysis'' is un understatement. At |v1.1b| we added a dangerous
%   twist to fix a memoir + frenchb triggered issue: if the
%   |\@makefntext|, as in memoir + frenchb situation, uses |\def| syntax to
%   define a macro with parameter we had a problem with the |#| token not
%   being doubled in the replacement fetched by
%   |\FNH@check@a|. As expedient work-around we fixed this by adding a
%   |\scantokens| wrapper.
%
%   At |v1.1d| I refactored the |babel-french| situation, moving it to an
%   entirely dedicated \cs{FNH@frenchb@}, and dropped the |v1.1b| usage of
%   |\scantokens|.
%
%   |v1.1d| adds \cs{FNH@checkagain@} which will identify circumstances likely
%   to be safe for the approach via |\def\FNH@prefntext{\@makefntext{}}|. For
%   example this is what will happen with |cleveref| (if not modified by other
%   packages).
%    \begin{macrocode}
\def\FNH@check@{%
    \expandafter\FNH@check@a\@makefntext{1.2!3?4,}%
                \FNH@@@1.2!3?4,\FNH@@@\relax
}%
\long\def\FNH@check@a #11.2!3?4,#2\FNH@@@#3{%
    \ifx\relax#3\expandafter\FNH@checkagain@
    \else
      \def\FNH@prefntext{#1}\def\FNH@postfntext{#2}%
      \expandafter\FNH@check@b
    \fi
}%
%    \end{macrocode}
% The argument was not seen unbraced at top. Maybe it is not fetched, or it was
% but was left at the end, braced. If this is the case we use the fallback
% |\def\FNH@prefntext{\@makefntext{}}|, which may work.
%    \begin{macrocode}
\def\FNH@checkagain@{%
    \expandafter\FNH@checkagain@a
    \detokenize\expandafter{\@makefntext{1.2!3?4,}}\relax\FNH@@@
}%
\edef\FNH@temp{\noexpand\FNH@checkagain@a ##1\string{1.2!3?4,\string}}%
\expandafter\def\FNH@temp#2#3\FNH@@@{%
    \ifx\relax#2%
      \def\FNH@prefntext{\@makefntext{}}%
      \iffootnotehyperwarn
        \PackageInfo{footnotehyper}%
        {using \string\@makefntext{} approach.^^J
         In case of problems with the footnote environments, please send^^J
         to the author a small document source illustrating them. To turn^^J
         off this message, add
         \string\footnotehyperwarnfalse\space to preamble.^^J}%
      \fi
    \else\FNH@bad@makefntext@alert
    \fi
}%
%    \end{macrocode}
% Back to non |babel-french| context. Let's check that |pre| and |post| do not
% contain some weird stuff from original |\@makefntext{#1}| containing
% multiple times |#1|.
%    \begin{macrocode}
\def\FNH@check@b #1\relax{%
    \expandafter\expandafter\expandafter\FNH@check@c
    \expandafter\meaning\expandafter\FNH@prefntext
    \meaning\FNH@postfntext1.2!3?4,\FNH@check@c\relax
}%
\def\FNH@check@c #11.2!3?4,#2#3\relax{%
    \ifx\FNH@check@c#2\else\FNH@bad@makefntext@alert\fi
}%
\def\FNH@bad@makefntext@alert{%
    \iffootnotehyperwarn
    \PackageWarningNoLine{footnotehyper}%
      {^^J The footnote environments will probably lack footnote numbers at^^J
       bottom of pages, sorry.^^J
       You may try to email the author this meaning of \string\@makefntext:^^J
       \meaning\@makefntext^^J
       together with the document preamble}%
    \fi
    \let\FNH@prefntext\@empty\let\FNH@postfntext\@empty
}%
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
% \begin{macro}{\makesavenoteenv}
% Same as original. Not recommended. Safer to use explicitely
% |savenotes| environment.
%    \begin{macrocode}
\def\makesavenoteenv{\@ifnextchar[\FNH@msne@ii\FNH@msne@i}%]
\def\FNH@msne@i #1{%
  \expandafter\let\csname FNH$#1\expandafter\endcsname %$
                  \csname #1\endcsname
  \expandafter\let\csname endFNH$#1\expandafter\endcsname %$
                  \csname end#1\endcsname
  \FNH@msne@ii[#1]{FNH$#1}%$
}%
\def\FNH@msne@ii[#1]#2{%
  \expandafter\edef\csname#1\endcsname{%
    \noexpand\savenotes
    \expandafter\noexpand\csname#2\endcsname
  }%
  \expandafter\edef\csname end#1\endcsname{%
    \expandafter\noexpand\csname end#2\endcsname
    \noexpand\expandafter
    \noexpand\spewnotes
    \noexpand\if@endpe\noexpand\@endpetrue\noexpand\fi
  }%
}%
%    \end{macrocode}
% \end{macro}
% Original footnote.sty patches |\parbox|, we don't touch it. Also it defines a
% |minipage*|  environment, we don't do it.
%    \begin{macrocode}
% \makesavenoteenv[minipage*]{minipage}
% \let\fn@parbox\parbox
% \def\parbox{\@ifnextchar[{\fn@parbox@i{}}{\fn@parbox@ii{}}}
% \def\fn@parbox@i#1[#2]{%
%   \@ifnextchar[{\fn@parbox@i{#1[#2]}}{\fn@parbox@ii{#1[#2]}}%
% }
% \long\def\fn@parbox@ii#1#2#3{\savenotes\fn@parbox#1{#2}{#3}\spewnotes}
\endinput
%    \end{macrocode}
% \MakePercentComment
\Finale
%%
%% End of file `footnotehyper.dtx'.