summaryrefslogtreecommitdiff
path: root/sphinx/texinputs/footnotehyper-sphinx.sty
blob: 763ce7323219891ac014a5574512b9c9f0dceabf (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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{footnotehyper-sphinx}%
 [2017/01/16 v1.5.2 hyperref aware footnote.sty for sphinx (JFB)]
%%
%% Package: footnotehyper-sphinx
%% Version: based on footnotehyper.sty v0.9f (2016/10/03)
%% as available at http://www.ctan.org/pkg/footnotehyper
%% License: the one applying to Sphinx
%%
%% Differences from footnotehyper v0.9f (2016/10/03):
%% 1. hyperref is assumed in use (with default hyperfootnotes=true),
%% 2. no need to check if footnote.sty was loaded,
%% 3. a special tabulary compatibility layer added, (partial but enough for
%% Sphinx),
%% 4. \sphinxfootnotemark, and use of \spx@opt@BeforeFootnote from sphinx.sty.
%% Note: with \footnotemark[N]/\footnotetext[N] syntax, hyperref
%% does not insert an hyperlink. This is _not_ improved here.
%% 5. use of \sphinxunactivateextrasandspace for parsed literals
%%
\DeclareOption*{\PackageWarning{footnotehyper}{Option `\CurrentOption' is unknown}}%
\ProcessOptions\relax
\let\FNH@@makefntext\@makefntext\let\@makefntext\@firstofone
\RequirePackage{footnote}
\let\fnparbox\parbox\let\parbox\fn@parbox\let\@makefntext\FNH@@makefntext
\let\FNH@fn@footnote    \footnote     % buggy footnote.sty's \footnote
\let\FNH@fn@footnotetext\footnotetext % will be redefined later
\let\footnote    \fn@latex@@footnote  % meaning of \footnote before footnote.sty
\let\footnotetext\fn@latex@@footnotetext
\def\fn@endnote  {\color@endgroup}%
\AtBeginDocument {%
    \let\fn@latex@@footnote    \footnote % meaning of \footnote at end of preamble
    \let\fn@latex@@footnotetext\footnotetext
    \let\fn@fntext \FNH@hyper@fntext
    \let\spewnotes \FNH@hyper@spewnotes
    \let\endsavenotes\spewnotes
    \let\fn@endfntext\FNH@fixed@endfntext
    \let\footnote    \FNH@fixed@footnote
    \let\footnotetext\FNH@fixed@footnotetext
    \let\endfootnote\fn@endfntext
    \let\endfootnotetext\endfootnote
}%
\def\FNH@hyper@fntext {%
%% amsmath compatibility
  \ifx\ifmeasuring@\undefined\expandafter\@secondoftwo
                                      \else\expandafter\@firstofone\fi
    {\ifmeasuring@\expandafter\@gobbletwo\else\expandafter\@firstofone\fi}%
%% partial tabulary compatibility, [N] must be used, but Sphinx does it
    {\ifx\equation$\expandafter\@gobbletwo\fi\FNH@hyper@fntext@i }%$
}%
\long\def\FNH@hyper@fntext@i #1{\global\setbox\fn@notes\vbox
     {\unvbox\fn@notes
      \fn@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 }%
      \fn@endnote }%
}%
\def\FNH@hyper@spewnotes {\endgroup
    \if@savingnotes\else\ifvoid\fn@notes\else
    \begingroup\let\@makefntext\@empty
               \let\@finalstrut\@gobble
               \let\rule\@gobbletwo
               \H@@footnotetext{\unvbox\fn@notes}%
    \endgroup\fi\fi
}%
\def\FNH@fixed@endfntext {%
    \@finalstrut\strutbox
    \fn@postfntext
    \fn@endnote
    \egroup\FNH@endfntext@next % will decide if link or no link
}%
\def\FNH@endfntext@link {\begingroup
    \let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo
    \@footnotetext {\unvbox\z@}%
    \endgroup
}%
\def\FNH@endfntext@nolink {\begingroup
    \let\@makefntext\@empty\let\@finalstrut\@gobble
    \let\rule\@gobbletwo
    \if@savingnotes\expandafter\fn@fntext\else\expandafter\H@@footnotetext\fi
    {\unvbox\z@}\endgroup
}%
%% \spx@opt@BeforeFootnote is defined in sphinx.sty
\def\FNH@fixed@footnote {\spx@opt@BeforeFootnote\ifx\@currenvir\fn@footnote
    \expandafter\FNH@footnoteenv\else\expandafter\fn@latex@@footnote\fi }%
\def\FNH@footnoteenv {\catcode13=5\sphinxunactivateextrasandspace
    \@ifnextchar[\FNH@xfootnoteenv%]
    {\stepcounter\@mpfn
     \protected@xdef\@thefnmark{\thempfn}\@footnotemark
     \def\FNH@endfntext@next{\FNH@endfntext@link}\fn@startfntext}}%
\def\FNH@xfootnoteenv [#1]{%
    \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup\@footnotemark\def\FNH@endfntext@next{\FNH@endfntext@link}%
    \fn@startfntext}%
\def\FNH@fixed@footnotetext {\ifx\@currenvir\fn@footnotetext
  \expandafter\FNH@footnotetextenv\else\expandafter\fn@latex@@footnotetext\fi}%
\def\FNH@footnotetextenv {\@ifnextchar[\FNH@xfootnotetextenv%]
    {\protected@xdef\@thefnmark{\thempfn}%
     \def\FNH@endfntext@next{\FNH@endfntext@link}\fn@startfntext}}%
\def\FNH@xfootnotetextenv [#1]{%
    \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup\def\FNH@endfntext@next{\FNH@endfntext@nolink}%
    \fn@startfntext }%
% Now some checks in case some package has modified \@makefntext.
\AtBeginDocument
{% compatibility with French module of LaTeX babel
 \ifx\@makefntextFB\undefined
                   \expandafter\@gobble\else\expandafter\@firstofone\fi
 {\ifFBFrenchFootnotes \let\FNH@@makefntext\@makefntextFB \else
                       \let\FNH@@makefntext\@makefntextORI\fi}%
 \expandafter\FNH@check@a\FNH@@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\@firstoftwo\else\expandafter\@secondoftwo\fi
     \FNH@bad@footnote@env
     {\def\fn@prefntext{#1}\def\fn@postfntext{#2}\FNH@check@b}%
}%
\def\FNH@check@b #1\relax
{%
    \expandafter\expandafter\expandafter\FNH@check@c
    \expandafter\meaning\expandafter\fn@prefntext
                            \meaning\fn@postfntext1.2!3?4,\FNH@check@c\relax
}%
\def\FNH@check@c #11.2!3?4,#2#3\relax
   {\ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@footnote@env}%
\def\FNH@bad@footnote@env
{\PackageWarningNoLine{footnotehyper}%
 {The footnote environment from package footnote^^J
  will be dysfunctional, sorry (not my fault...). You may try to make a bug^^J
  report at https://github.com/sphinx-doc/sphinx including the next lines:}%
    \typeout{\meaning\@makefntext}%
    \let\fn@prefntext\@empty\let\fn@postfntext\@empty
}%
%% \sphinxfootnotemark: usable in section titles and silently removed from
%% TOCs.
\def\sphinxfootnotemark [#1]%
   {\ifx\thepage\relax\else \protect\spx@opt@BeforeFootnote
                            \protect\footnotemark[#1]\fi}%
\AtBeginDocument % let hyperref less complain
   {\pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}}%
\endinput
%%
%% End of file `footnotehyper-sphinx.sty'.