sync with upstream footnotehyper-sphinx, stop loading footnote.sty

This commit is contained in:
jfbu 2017-02-25 20:53:28 +01:00
parent dbf960884d
commit 517b6bda3c
3 changed files with 234 additions and 158 deletions

View File

@ -90,10 +90,9 @@ Deprecated
- ``BuildEnvironment.create_index()`` - ``BuildEnvironment.create_index()``
Please use ``sphinx.environment.adapters`` modules instead. Please use ``sphinx.environment.adapters`` modules instead.
* The LaTeX package ``footnote.sty`` will not be loaded anymore at Sphinx 1.7, * latex package ``footnote`` is not loaded anymore by its bundled replacement
as Sphinx's ``footnotehyper-sphinx.sty`` will define all macros rather than ``footnotehyper-sphinx``. The redefined macros keep the same names as in the
patch them. In particular the ``\makesavenoteenv`` macro is not in use anymore original package.
and its definition will be removed at Sphinx 1.7.
Release 1.5.3 (in development) Release 1.5.3 (in development)
============================== ==============================
@ -289,6 +288,8 @@ Incompatible changes
The non-modified package is used. The non-modified package is used.
* #3057: By default, footnote marks in latex PDF output are not preceded by a * #3057: By default, footnote marks in latex PDF output are not preceded by a
space anymore, ``\sphinxBeforeFootnote`` allows user customization if needed. space anymore, ``\sphinxBeforeFootnote`` allows user customization if needed.
* LaTeX target requires that option ``hyperfootnotes`` of package ``hyperref``
be left unchanged to its default (i.e. ``true``) (refs: #3022)
1.5 final 1.5 final

View File

@ -1,194 +1,270 @@
\NeedsTeXFormat{LaTeX2e} \NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{footnotehyper-sphinx}% \ProvidesPackage{footnotehyper-sphinx}%
[2017/02/15 v1.6 hyperref aware footnote.sty for sphinx (JFB)] [2017/02/25 v1.6 hyperref aware footnote.sty for sphinx (JFB)]
%% %%
%% Package: footnotehyper-sphinx %% Package: footnotehyper-sphinx
%% Version: based on footnotehyper.sty v0.9f (2016/10/03) %% Version: based on footnotehyper.sty 2017/02/16 v0.99
%% as available at http://www.ctan.org/pkg/footnotehyper %% as available at http://www.ctan.org/pkg/footnotehyper
%% License: the one applying to Sphinx %% License: the one applying to Sphinx
%% %%
%% Differences from footnotehyper v0.9f (2016/10/03): %% Refer to the PDF documentation at http://www.ctan.org/pkg/footnotehyper for
%% 1. hyperref is assumed in use (with default hyperfootnotes=true), %% the code comments.
%% 2. no need to check if footnote.sty was loaded, %%
%% 3. a tabulary compatibility layer added, (partial but enough for Sphinx), %% Differences:
%% 4. \sphinxfootnotemark, and use of \spx@opt@BeforeFootnote from sphinx.sty, %% 1. Error message if hyperref not loaded or with hyperfootnotes=false,
%% 5. use of \sphinxunactivateextrasandspace for parsed literals %% 2. a partial tabulary compatibility layer added (enough for Sphinx mark-up),
%% 6. macro \sphinxlongtablepatch %% 3. use of \spx@opt@BeforeFootnote from sphinx.sty,
%% 7. some import from future footnotehyper v0.99 (\FNH@fn@fntext) %% 4. use of \sphinxunactivateextrasandspace from sphinx.sty,
%% 8. deprecation of \makesavenoteenv. %% 5. macro definition \sphinxfootnotemark,
%% Future version of footnotehyper will not load footnote.sty and it will define %% 6. macro definition \sphinxlongtablepatch
%% all macros rather than adding hyperref awareness and fixing bugs. \DeclareOption*{\PackageWarning{footnotehyper-sphinx}{Option `\CurrentOption' is unknown}}%
\DeclareOption*{\PackageWarning{footnotehyper}{Option `\CurrentOption' is unknown}}%
\ProcessOptions\relax \ProcessOptions\relax
\let\FNH@@makefntext\@makefntext\let\@makefntext\@firstofone \newbox\FNH@notes
\RequirePackage{footnote} \newdimen\FNH@width
\let\fnparbox\parbox\let\parbox\fn@parbox\let\@makefntext\FNH@@makefntext \let\FNH@colwidth\columnwidth
\let\FNH@fn@footnote \footnote % buggy footnote.sty's \footnote \newif\ifFNH@savingnotes
\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 {% \AtBeginDocument {%
\let\fn@latex@@footnote \footnote % meaning of \footnote at end of preamble \@ifpackageloaded{hyperref}
\let\fn@latex@@footnotetext\footnotetext {\ifHy@hyperfootnotes
\let\fn@fntext \FNH@hyper@fntext \let\FNH@latex@footnote \footnote
\let\savenotes \FNH@savenotes \let\FNH@latex@footnotetext\footnotetext
\let\spewnotes \FNH@hyper@spewnotes \newenvironment{savenotes}
\let\endsavenotes\spewnotes {\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
\let\fn@endfntext\FNH@fixed@endfntext \let\spewnotes \FNH@spewnotes
\let\footnote \FNH@fixed@footnote \let\footnote \FNH@footnote
\let\footnotetext\FNH@fixed@footnotetext \let\footnotetext \FNH@footnotetext
\let\endfootnote\fn@endfntext \let\endfootnote \FNH@endfntext
\let\endfootnotetext\endfootnote \let\endfootnotetext\FNH@endfntext
\else
\PackageError{sphinx}
{^^J\@spaces\@spaces******^^J%
hyperref option "hyperfootnotes=false" is incompatible with Sphinx!^^J}%
\fi}%
{\PackageError{sphinx}{^^J\@spaces\@spaces******^^J%
hyperref is required by Sphinx!^^J}%
}%
}% }%
%% patch \savenotes for good functioning of \footnotetext[N]{..} syntax even
%% though Sphinx now uses only environment form. In future, will simply copy
%% over full footnotehyper v0.99.
\toks@\expandafter\expandafter\expandafter{\expandafter\@gobble\savenotes}%
\edef\FNH@savenotes{\begingroup
\unexpanded{\if@savingnotes\else\let\H@@mpfootnotetext\FNH@fn@fntext\fi}%
\the\toks@ }%
\def\FNH@fn@fntext {\FNH@fntext\FNH@fn@fntext@i}%
\def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}% \def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}%
\def\FNH@nohyp@fntext{\FNH@fntext\FNH@nohyp@fntext@i}%
\def\FNH@fntext #1{% \def\FNH@fntext #1{%
%% amsmath compatibility \ifx\ifmeasuring@\@undefined
\ifx\ifmeasuring@\undefined\expandafter\@secondoftwo \expandafter\@secondoftwo\else\expandafter\@firstofone\fi
\else\expandafter\@firstofone\fi % these two lines modified for Sphinx (tabulary compatibility):
{\ifmeasuring@\expandafter\@gobbletwo\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 #1}%$ {\ifx\equation$\expandafter\@gobbletwo\fi #1}%$
}% }%
%% footnote.sty's replacement for \@footnotetext \long\def\FNH@hyper@fntext@i#1{%
\long\def\FNH@fn@fntext@i #1{\global\setbox\fn@notes\vbox \global\setbox\FNH@notes\vbox
{\unvbox\fn@notes {\unvbox\FNH@notes
\fn@startnote \FNH@startnote
\@makefntext \@makefntext
{\rule\z@\footnotesep\ignorespaces {\rule\z@\footnotesep\ignorespaces
#1% \ifHy@nesting\expandafter\ltx@firstoftwo
\@finalstrut\strutbox \else\expandafter\ltx@secondoftwo
}% \fi
\fn@endnote }% {\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
}%
}% }%
\long\def\FNH@hyper@fntext@i #1{\global\setbox\fn@notes\vbox \long\def\FNH@nohyp@fntext@i#1{%
{\unvbox\fn@notes \global\setbox\FNH@notes\vbox
\fn@startnote {\unvbox\FNH@notes
\@makefntext \FNH@startnote
{\rule\z@\footnotesep\ignorespaces \@makefntext{\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
\ifHy@nesting\expandafter\ltx@firstoftwo \FNH@endnote
\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 \def\FNH@startnote{%
\if@savingnotes\else\ifvoid\fn@notes\else \hsize\FNH@colwidth
\begingroup\let\@makefntext\@empty \interlinepenalty\interfootnotelinepenalty
\let\@finalstrut\@gobble \reset@font\footnotesize
\let\rule\@gobbletwo \floatingpenalty\@MM
\H@@footnotetext{\unvbox\fn@notes}% \@parboxrestore
\endgroup\fi\fi \protected@edef\@currentlabel{\csname p@\@mpfn\endcsname\@thefnmark}%
\color@begingroup
}% }%
\def\FNH@fixed@endfntext {% \def\FNH@endnote{\color@endgroup}%
\@finalstrut\strutbox \def\FNH@savenotes{%
\fn@postfntext \begingroup
\fn@endnote \ifFNH@savingnotes\else
\egroup\FNH@endfntext@next % will decide if link or no link \FNH@savingnotestrue
\let\@footnotetext \FNH@hyper@fntext
\let\@mpfootnotetext \FNH@hyper@fntext
\let\H@@mpfootnotetext\FNH@nohyp@fntext
\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
}% }%
\def\FNH@endfntext@link {\begingroup \def\FNH@spewnotes {%
\let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo \endgroup
\@footnotetext {\unvbox\z@}% \ifFNH@savingnotes\else
\ifvoid\FNH@notes\else
\begingroup
\let\@makefntext\@empty
\let\@finalstrut\@gobble
\let\rule\@gobbletwo
\H@@footnotetext{\unvbox\FNH@notes}%
\endgroup \endgroup
\fi
\fi
}% }%
\def\FNH@endfntext@nolink {\begingroup \def\FNH@footnote@envname {footnote}%
\let\@makefntext\@empty\let\@finalstrut\@gobble \def\FNH@footnotetext@envname{footnotetext}%
\let\rule\@gobbletwo \def\FNH@footnote{%
\if@savingnotes\expandafter\FNH@fn@fntext\else\expandafter\H@@footnotetext\fi % this line added for Sphinx:
{\unvbox\z@}\endgroup \spx@opt@BeforeFootnote
\ifx\@currenvir\FNH@footnote@envname
\expandafter\FNH@footnoteenv
\else
\expandafter\FNH@latex@footnote
\fi
}% }%
%% \spx@opt@BeforeFootnote is defined in sphinx.sty \def\FNH@footnoteenv{%
\def\FNH@fixed@footnote {\spx@opt@BeforeFootnote\ifx\@currenvir\fn@footnote % this line added for Sphinx (footnotes in parsed literal blocks):
\expandafter\FNH@footnoteenv\else\expandafter\fn@latex@@footnote\fi }% \catcode13=5\sphinxunactivateextrasandspace
\def\FNH@footnoteenv {\catcode13=5\sphinxunactivateextrasandspace \@ifnextchar[%
\@ifnextchar[\FNH@xfootnoteenv%] \FNH@footnoteenv@i %]
{\stepcounter\@mpfn {\stepcounter\@mpfn
\protected@xdef\@thefnmark{\thempfn}\@footnotemark \protected@xdef\@thefnmark{\thempfn}%
\def\FNH@endfntext@next{\FNH@endfntext@link}\fn@startfntext}}% \@footnotemark
\def\FNH@xfootnoteenv [#1]{% \def\FNH@endfntext@fntext{\@footnotetext}%
\FNH@startfntext}%
}%
\def\FNH@footnoteenv@i[#1]{%
\begingroup \begingroup
\csname c@\@mpfn\endcsname #1\relax \csname c@\@mpfn\endcsname #1\relax
\unrestored@protected@xdef\@thefnmark{\thempfn}% \unrestored@protected@xdef\@thefnmark{\thempfn}%
\endgroup\@footnotemark\def\FNH@endfntext@next{\FNH@endfntext@link}% \endgroup
\fn@startfntext}% \@footnotemark
\def\FNH@fixed@footnotetext {\ifx\@currenvir\fn@footnotetext \def\FNH@endfntext@fntext{\@footnotetext}%
\expandafter\FNH@footnotetextenv\else\expandafter\fn@latex@@footnotetext\fi}% \FNH@startfntext
\def\FNH@footnotetextenv {\@ifnextchar[\FNH@xfootnotetextenv%] }%
{\protected@xdef\@thefnmark{\thempfn}% \def\FNH@footnotetext{%
\def\FNH@endfntext@next{\FNH@endfntext@link}\fn@startfntext}}% \ifx\@currenvir\FNH@footnotetext@envname
\def\FNH@xfootnotetextenv [#1]{% \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 \begingroup
\csname c@\@mpfn\endcsname #1\relax \csname c@\@mpfn\endcsname #1\relax
\unrestored@protected@xdef\@thefnmark{\thempfn}% \unrestored@protected@xdef\@thefnmark{\thempfn}%
\endgroup\def\FNH@endfntext@next{\FNH@endfntext@nolink}% \endgroup
\fn@startfntext }% \ifFNH@savingnotes
% Now some checks in case some package has modified \@makefntext. \def\FNH@endfntext@fntext{\FNH@nohyp@fntext}%
\AtBeginDocument \else
{% compatibility with French module of LaTeX babel \def\FNH@endfntext@fntext{\H@@footnotetext}%
\ifx\@makefntextFB\undefined \fi
\expandafter\@gobble\else\expandafter\@firstofone\fi \FNH@startfntext
{\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% \def\FNH@startfntext{%
{% \setbox\z@\vbox\bgroup
\ifx\relax#3\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi \FNH@startnote
\FNH@bad@footnote@env \FNH@prefntext
{\def\fn@prefntext{#1}\def\fn@postfntext{#2}\FNH@check@b}% \rule\z@\footnotesep\ignorespaces
}% }%
\def\FNH@check@b #1\relax \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
}%
\AtBeginDocument{%
\let\FNH@@makefntext\@makefntext
\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@makefntext@alert
{\def\FNH@prefntext{#1}\def\FNH@postfntext{#2}\FNH@check@b}%
}%
\def\FNH@check@b #1\relax{%
\expandafter\expandafter\expandafter\FNH@check@c \expandafter\expandafter\expandafter\FNH@check@c
\expandafter\meaning\expandafter\fn@prefntext \expandafter\meaning\expandafter\FNH@prefntext
\meaning\fn@postfntext1.2!3?4,\FNH@check@c\relax \meaning\FNH@postfntext1.2!3?4,\FNH@check@c\relax
}% }%
\def\FNH@check@c #11.2!3?4,#2#3\relax \def\FNH@check@c #11.2!3?4,#2#3\relax{%
{\ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@footnote@env}% \ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@makefntext@alert
\def\FNH@bad@footnote@env }%
{\PackageWarningNoLine{footnotehyper-sphinx}% % slight reformulation for Sphinx
{Footnotes will be sub-optimal, sorry. This is due to the class or^^J \def\FNH@bad@makefntext@alert{%
\PackageWarningNoLine{footnotehyper-sphinx}%
{Footnotes will be sub-optimal, sorry. This is due to the document class or^^J
some package modifying macro \string\@makefntext.^^J some package modifying macro \string\@makefntext.^^J
You can try to report this incompatibility at^^J You can try to report this incompatibility at^^J
https://github.com/sphinx-doc/sphinx with this info:}% https://github.com/sphinx-doc/sphinx with this info:}%
\typeout{\meaning\@makefntext}% \typeout{\meaning\@makefntext}%
\let\fn@prefntext\@empty\let\fn@postfntext\@empty \let\FNH@prefntext\@empty\let\FNH@postfntext\@empty
}% }%
%% \sphinxfootnotemark: usable in section titles and silently removed from % this macro from original footnote.sty is not used anymore by Sphinx
%% TOCs. % but for simplicity sake let's just keep it as is
\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 of footnotehyper 2017/02/16 v0.99
% some extras for Sphinx :
% \sphinxfootnotemark: usable in section titles and silently removed from TOCs.
\def\sphinxfootnotemark [#1]% \def\sphinxfootnotemark [#1]%
{\ifx\thepage\relax\else \protect\spx@opt@BeforeFootnote {\ifx\thepage\relax\else\protect\spx@opt@BeforeFootnote
\protect\footnotemark[#1]\fi}% \protect\footnotemark[#1]\fi}%
\AtBeginDocument % let hyperref less complain \AtBeginDocument{%
{\pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}}% % let hyperref less complain
% to obtain hyperlinked footnotes in longtable environment we must replace \pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}%
% hyperref's patch of longtable's patch of \@footnotetext by our own % to obtain hyperlinked footnotes in longtable environment we must replace
\def\sphinxlongtablepatch {% only for longtable wrapped in "savenotes" % hyperref's patch of longtable's patch of \@footnotetext by our own
\let\LT@p@ftntext\FNH@hyper@fntext \let\LT@p@ftntext\FNH@hyper@fntext
}% % this *requires* longtable to be used always wrapped in savenotes environment
%% deprecate \makesavenoteenv
\def\makesavenoteenv{%
\AtEndDocument{\PackageWarning{footnotehyper-sphinx}
{^^J^^J^^J!\@spaces**** SPHINX DEPRECATION WARNING ****^^J!^^J%
!\@spaces\string\makesavenoteenv\space from footnote.sty is deprecated^^J%
!\@spaces and will be removed at Sphinx 1.7 !^^J^^J^^J}}%
\@ifnextchar[\fn@msne@ii\fn@msne@i%]
}% }%
\endinput \endinput
%% %%

View File

@ -74,7 +74,6 @@
% For hyperlinked footnotes in tables; also for gathering footnotes from % For hyperlinked footnotes in tables; also for gathering footnotes from
% topic and warning blocks. Also to allow code-blocks in footnotes. % topic and warning blocks. Also to allow code-blocks in footnotes.
\RequirePackage{footnotehyper-sphinx} \RequirePackage{footnotehyper-sphinx}
\AtBeginDocument{\@ifpackageloaded{longtable}{\sphinxlongtablepatch}{}}%
% For the H specifier. Do not \restylefloat{figure}, it breaks Sphinx code % For the H specifier. Do not \restylefloat{figure}, it breaks Sphinx code
% for allowing figures in tables. % for allowing figures in tables.
\RequirePackage{float} \RequirePackage{float}