elog2labfolder/_build/latex/footnotehyper-sphinx.sty
changeset 3 b71be85a294c
equal deleted inserted replaced
2:5e51ce17f274 3:b71be85a294c
       
     1 \NeedsTeXFormat{LaTeX2e}
       
     2 \ProvidesPackage{footnotehyper-sphinx}%
       
     3  [2017/03/07 v1.6 hyperref aware footnote.sty for sphinx (JFB)]
       
     4 %%
       
     5 %% Package: footnotehyper-sphinx
       
     6 %% Version: based on footnotehyper.sty 2017/03/07 v1.0
       
     7 %% as available at http://www.ctan.org/pkg/footnotehyper
       
     8 %% License: the one applying to Sphinx
       
     9 %%
       
    10 %% Refer to the PDF documentation  at http://www.ctan.org/pkg/footnotehyper for
       
    11 %% the code comments.
       
    12 %%
       
    13 %% Differences:
       
    14 %% 1. a partial tabulary compatibility layer added (enough for Sphinx mark-up),
       
    15 %% 2. use of \spx@opt@BeforeFootnote from sphinx.sty,
       
    16 %% 3. use of \sphinxunactivateextrasandspace from sphinx.sty,
       
    17 %% 4. macro definition \sphinxfootnotemark,
       
    18 %% 5. macro definition \sphinxlongtablepatch
       
    19 \DeclareOption*{\PackageWarning{footnotehyper-sphinx}{Option `\CurrentOption' is unknown}}%
       
    20 \ProcessOptions\relax
       
    21 \newbox\FNH@notes
       
    22 \newdimen\FNH@width
       
    23 \let\FNH@colwidth\columnwidth
       
    24 \newif\ifFNH@savingnotes
       
    25 \AtBeginDocument {%
       
    26     \let\FNH@latex@footnote    \footnote
       
    27     \let\FNH@latex@footnotetext\footnotetext
       
    28     \let\FNH@H@@footnotetext   \@footnotetext
       
    29     \newenvironment{savenotes}
       
    30         {\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
       
    31     \let\spewnotes      \FNH@spewnotes
       
    32     \let\footnote       \FNH@footnote
       
    33     \let\footnotetext   \FNH@footnotetext
       
    34     \let\endfootnote    \FNH@endfntext
       
    35     \let\endfootnotetext\FNH@endfntext
       
    36     \@ifpackageloaded{hyperref}
       
    37      {\ifHy@hyperfootnotes
       
    38          \let\FNH@H@@footnotetext\H@@footnotetext
       
    39       \else
       
    40          \let\FNH@hyper@fntext\FNH@nohyp@fntext
       
    41       \fi}%
       
    42      {\let\FNH@hyper@fntext\FNH@nohyp@fntext}%
       
    43 }%
       
    44 \def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}%
       
    45 \def\FNH@nohyp@fntext{\FNH@fntext\FNH@nohyp@fntext@i}%
       
    46 \def\FNH@fntext #1{%
       
    47   \ifx\ifmeasuring@\@undefined
       
    48     \expandafter\@secondoftwo\else\expandafter\@firstofone\fi
       
    49 % these two lines modified for Sphinx (tabulary compatibility):
       
    50     {\ifmeasuring@\expandafter\@gobbletwo\else\expandafter\@firstofone\fi}%
       
    51     {\ifx\equation$\expandafter\@gobbletwo\fi #1}%$
       
    52 }%
       
    53 \long\def\FNH@hyper@fntext@i#1{%
       
    54   \global\setbox\FNH@notes\vbox
       
    55   {\unvbox\FNH@notes
       
    56    \FNH@startnote
       
    57    \@makefntext
       
    58     {\rule\z@\footnotesep\ignorespaces
       
    59      \ifHy@nesting\expandafter\ltx@firstoftwo
       
    60              \else\expandafter\ltx@secondoftwo
       
    61      \fi
       
    62      {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}{#1}}%
       
    63      {\Hy@raisedlink
       
    64        {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}%
       
    65        {\relax}}%
       
    66       \let\@currentHref\Hy@footnote@currentHref
       
    67       \let\@currentlabelname\@empty
       
    68       #1}%
       
    69      \@finalstrut\strutbox
       
    70     }%
       
    71    \FNH@endnote
       
    72   }%
       
    73 }%
       
    74 \long\def\FNH@nohyp@fntext@i#1{%
       
    75   \global\setbox\FNH@notes\vbox
       
    76   {\unvbox\FNH@notes
       
    77    \FNH@startnote
       
    78    \@makefntext{\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
       
    79    \FNH@endnote
       
    80   }%
       
    81 }%
       
    82 \def\FNH@startnote{%
       
    83   \hsize\FNH@colwidth
       
    84   \interlinepenalty\interfootnotelinepenalty
       
    85   \reset@font\footnotesize
       
    86   \floatingpenalty\@MM
       
    87   \@parboxrestore
       
    88   \protected@edef\@currentlabel{\csname p@\@mpfn\endcsname\@thefnmark}%
       
    89   \color@begingroup
       
    90 }%
       
    91 \def\FNH@endnote{\color@endgroup}%
       
    92 \def\FNH@savenotes{%
       
    93   \begingroup
       
    94   \ifFNH@savingnotes\else
       
    95     \FNH@savingnotestrue
       
    96     \let\@footnotetext    \FNH@hyper@fntext
       
    97     \let\@mpfootnotetext  \FNH@hyper@fntext
       
    98     \let\H@@mpfootnotetext\FNH@nohyp@fntext
       
    99     \FNH@width\columnwidth
       
   100     \let\FNH@colwidth\FNH@width
       
   101     \global\setbox\FNH@notes\box\voidb@x
       
   102     \let\FNH@thempfn\thempfn
       
   103     \let\FNH@mpfn\@mpfn
       
   104     \ifx\@minipagerestore\relax\let\@minipagerestore\@empty\fi
       
   105     \expandafter\def\expandafter\@minipagerestore\expandafter{%
       
   106       \@minipagerestore
       
   107       \let\thempfn\FNH@thempfn
       
   108       \let\@mpfn\FNH@mpfn
       
   109     }%
       
   110   \fi
       
   111 }%
       
   112 \def\FNH@spewnotes {%
       
   113   \endgroup
       
   114   \ifFNH@savingnotes\else
       
   115    \ifvoid\FNH@notes\else
       
   116     \begingroup
       
   117      \let\@makefntext\@empty
       
   118      \let\@finalstrut\@gobble
       
   119      \let\rule\@gobbletwo
       
   120      \FNH@H@@footnotetext{\unvbox\FNH@notes}%
       
   121     \endgroup
       
   122    \fi
       
   123   \fi
       
   124 }%
       
   125 \def\FNH@footnote@envname    {footnote}%
       
   126 \def\FNH@footnotetext@envname{footnotetext}%
       
   127 \def\FNH@footnote{%
       
   128 % this line added for Sphinx:
       
   129     \spx@opt@BeforeFootnote
       
   130     \ifx\@currenvir\FNH@footnote@envname
       
   131         \expandafter\FNH@footnoteenv
       
   132     \else
       
   133         \expandafter\FNH@latex@footnote
       
   134     \fi
       
   135 }%
       
   136 \def\FNH@footnoteenv{%
       
   137 % this line added for Sphinx (footnotes in parsed literal blocks):
       
   138     \catcode13=5 \sphinxunactivateextrasandspace
       
   139     \@ifnextchar[%
       
   140       \FNH@footnoteenv@i %]
       
   141       {\stepcounter\@mpfn
       
   142        \protected@xdef\@thefnmark{\thempfn}%
       
   143        \@footnotemark
       
   144        \def\FNH@endfntext@fntext{\@footnotetext}%
       
   145        \FNH@startfntext}%
       
   146 }%
       
   147 \def\FNH@footnoteenv@i[#1]{%
       
   148     \begingroup
       
   149      \csname c@\@mpfn\endcsname #1\relax
       
   150      \unrestored@protected@xdef\@thefnmark{\thempfn}%
       
   151     \endgroup
       
   152     \@footnotemark
       
   153     \def\FNH@endfntext@fntext{\@footnotetext}%
       
   154     \FNH@startfntext
       
   155 }%
       
   156 \def\FNH@footnotetext{%
       
   157     \ifx\@currenvir\FNH@footnotetext@envname
       
   158         \expandafter\FNH@footnotetextenv
       
   159     \else
       
   160         \expandafter\FNH@latex@footnotetext
       
   161     \fi
       
   162 }%
       
   163 \def\FNH@footnotetextenv{%
       
   164     \@ifnextchar[%
       
   165       \FNH@footnotetextenv@i %]
       
   166       {\protected@xdef\@thefnmark{\thempfn}%
       
   167        \def\FNH@endfntext@fntext{\@footnotetext}%
       
   168        \FNH@startfntext}%
       
   169 }%
       
   170 \def\FNH@footnotetextenv@i[#1]{%
       
   171     \begingroup
       
   172      \csname c@\@mpfn\endcsname #1\relax
       
   173      \unrestored@protected@xdef\@thefnmark{\thempfn}%
       
   174     \endgroup
       
   175     \ifFNH@savingnotes
       
   176       \def\FNH@endfntext@fntext{\FNH@nohyp@fntext}%
       
   177     \else
       
   178       \def\FNH@endfntext@fntext{\FNH@H@@footnotetext}%
       
   179     \fi
       
   180     \FNH@startfntext
       
   181 }%
       
   182 \def\FNH@startfntext{%
       
   183   \setbox\z@\vbox\bgroup
       
   184     \FNH@startnote
       
   185     \FNH@prefntext
       
   186     \rule\z@\footnotesep\ignorespaces
       
   187 }%
       
   188 \def\FNH@endfntext {%
       
   189     \@finalstrut\strutbox
       
   190     \FNH@postfntext
       
   191     \FNH@endnote
       
   192     \egroup
       
   193   \begingroup
       
   194     \let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo
       
   195     \FNH@endfntext@fntext {\unvbox\z@}%
       
   196   \endgroup
       
   197 }%
       
   198 \AtBeginDocument{%
       
   199    \let\FNH@@makefntext\@makefntext
       
   200    \ifx\@makefntextFB\undefined
       
   201    \expandafter\@gobble\else\expandafter\@firstofone\fi
       
   202    {\ifFBFrenchFootnotes \let\FNH@@makefntext\@makefntextFB \else
       
   203                          \let\FNH@@makefntext\@makefntextORI\fi}%
       
   204    \expandafter\FNH@check@a\FNH@@makefntext{1.2!3?4,}%
       
   205                \FNH@@@1.2!3?4,\FNH@@@\relax
       
   206 }%
       
   207 \long\def\FNH@check@a #11.2!3?4,#2\FNH@@@#3{%
       
   208     \ifx\relax#3\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
       
   209     \FNH@bad@makefntext@alert
       
   210     {\def\FNH@prefntext{#1}\def\FNH@postfntext{#2}\FNH@check@b}%
       
   211 }%
       
   212 \def\FNH@check@b #1\relax{%
       
   213     \expandafter\expandafter\expandafter\FNH@check@c
       
   214     \expandafter\meaning\expandafter\FNH@prefntext
       
   215     \meaning\FNH@postfntext1.2!3?4,\FNH@check@c\relax
       
   216 }%
       
   217 \def\FNH@check@c #11.2!3?4,#2#3\relax{%
       
   218     \ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@makefntext@alert
       
   219 }%
       
   220 % slight reformulation for Sphinx
       
   221 \def\FNH@bad@makefntext@alert{%
       
   222   \PackageWarningNoLine{footnotehyper-sphinx}%
       
   223     {Footnotes will be sub-optimal, sorry. This is due to the document class or^^J
       
   224   some package modifying macro \string\@makefntext.^^J
       
   225   You can try to report this incompatibility at^^J
       
   226   https://github.com/sphinx-doc/sphinx with this info:}%
       
   227     \typeout{\meaning\@makefntext}%
       
   228     \let\FNH@prefntext\@empty\let\FNH@postfntext\@empty
       
   229 }%
       
   230 % this macro from original footnote.sty is not used anymore by Sphinx
       
   231 % but for simplicity sake let's just keep it as is
       
   232 \def\makesavenoteenv{\@ifnextchar[\FNH@msne@ii\FNH@msne@i}%]
       
   233 \def\FNH@msne@i #1{%
       
   234   \expandafter\let\csname FNH$#1\expandafter\endcsname %$
       
   235                   \csname #1\endcsname
       
   236   \expandafter\let\csname endFNH$#1\expandafter\endcsname %$
       
   237                   \csname end#1\endcsname
       
   238   \FNH@msne@ii[#1]{FNH$#1}%$
       
   239 }%
       
   240 \def\FNH@msne@ii[#1]#2{%
       
   241   \expandafter\edef\csname#1\endcsname{%
       
   242     \noexpand\savenotes
       
   243     \expandafter\noexpand\csname#2\endcsname
       
   244   }%
       
   245   \expandafter\edef\csname end#1\endcsname{%
       
   246     \expandafter\noexpand\csname end#2\endcsname
       
   247     \noexpand\expandafter
       
   248     \noexpand\spewnotes
       
   249     \noexpand\if@endpe\noexpand\@endpetrue\noexpand\fi
       
   250   }%
       
   251 }%
       
   252 % end of footnotehyper 2017/02/16 v0.99
       
   253 % some extras for Sphinx :
       
   254 % \sphinxfootnotemark: usable in section titles and silently removed from TOCs.
       
   255 \def\sphinxfootnotemark [#1]%
       
   256    {\ifx\thepage\relax\else\protect\spx@opt@BeforeFootnote
       
   257                              \protect\footnotemark[#1]\fi}%
       
   258 \AtBeginDocument{%
       
   259    % let hyperref less complain
       
   260    \pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}%
       
   261    % to obtain hyperlinked footnotes in longtable environment we must replace
       
   262    % hyperref's patch of longtable's patch of \@footnotetext by our own
       
   263    \let\LT@p@ftntext\FNH@hyper@fntext
       
   264    % this *requires* longtable to be used always wrapped in savenotes environment
       
   265 }%
       
   266 \endinput
       
   267 %%
       
   268 %% End of file `footnotehyper-sphinx.sty'.