From ebb6ab51492a7468e25e3f18c95650edfc4bf345 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 17 Apr 2016 11:37:28 +0200 Subject: [PATCH] Attempt using footnote.sty to re-enable footnotes in "topic" contexts This works from the LaTeX point of view, the footnotes are gathered and put at bottom of page like any other footnote. Applies to local tables of contents and more generally topic directives which use the same SphinxShadowBox, and applies also to the warning type boxes. (in case of box contents on two or more pages, the footnotes appear on last one) The problem is that footnote.sty is not compatible with hyperref. What happens is that in case of multiple footnotes in a topic box, only the last one has a correct hyperlink to footnote text at bottom of page. The others point to document start. This is unrecoverable apart from re-writing footnote package (which dates back to 1997) and make it hyperref compatible. Hyperref package simply says to disable hyperfootnotes in case of use of package footnote... http://tex.stackexchange.com/questions/194255/is-there-a-way-to-make-the-footnote-package-work-correctly-with-hyperref This partially reverted 9b958b6 Fix #2291: pdflatex "Counter too large" error from footnotes inside tables of contents. Test files not updated. modified: sphinx/texinputs/sphinx.sty modified: sphinx/writers/latex.py --- sphinx/texinputs/sphinx.sty | 34 ++++++++++++++++++---------------- sphinx/writers/latex.py | 14 +++++--------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 222ba3f6298..65bc8c21d80 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -31,7 +31,7 @@ \RequirePackage{fancyvrb} % For table captions. \RequirePackage{threeparttable} -% Handle footnotes in tables. +% Handle footnotes in tables; also for topic and warning blocks. \RequirePackage{footnote} \makesavenoteenv{tabulary} % For floating figures in the text. @@ -289,6 +289,8 @@ % vertical space which we try to imitate as much as possible via "trivlist" \OuterFrameSep \z@skip \def\FrameHeightAdjust {\baselineskip}% + % use package footnote to handle footnotes + \savenotes % the \noindent is needed to get proper vertical spacing at the % \endtrivlist location after \MakeFramed. Together with \FrameHeightAdjust % setting, about same vertical spacing as with Sphinx 1.4.1 is obtained. @@ -302,22 +304,21 @@ % the "\width" here means width from the frame added by \Sphinx@ShadowFBox \hsize\dimexpr\linewidth-\width\relax \textwidth\hsize \columnwidth\hsize \@parboxrestore - % for footnotes, but Sphinx inactivates footnotes in topics - \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@ - \let\@footnotetext\@mpfootnotetext + % no need for that since \savenotes + % \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@ + % \let\@footnotetext\@mpfootnotetext \let\@listdepth\@mplistdepth \@mplistdepth\z@ \@minipagerestore \@setminipage }% }% {\par\unskip - % handles footnotes - \ifvoid\@mpfootins\else - \vskip\skip\@mpfootins\normalcolor\footnoterule\unvbox\@mpfootins - \fi \@minipagefalse \endMakeFramed \endtrivlist + % output the stored footnotes, if any, at bottom of last page occupied + % by shadowed box. + \spewnotes } @@ -399,25 +400,26 @@ \def\FrameCommand##1{\fboxsep\FrameSep \fboxrule\FrameRule \hskip\@totalleftmargin\hskip-\FrameSep\fbox{##1}\hskip-\FrameSep \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth }% + % use package footnote to store footnotes + \savenotes \MakeFramed {\advance\hsize-\width\@totalleftmargin\z@\linewidth\hsize % same technique as in SphinxShadowBox environment. % minipage initialization copied from LaTeX source code. \@pboxswfalse \@parboxrestore - % for footnotes - \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@ - \let\@footnotetext\@mpfootnotetext + % no need for that since \savenotes + % \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@ + % \let\@footnotetext\@mpfootnotetext \let\@listdepth\@mplistdepth \@mplistdepth\z@ \@minipagerestore \@setminipage }% } \newcommand{\py@endheavybox}{% \par\unskip - % handles footnotes - \ifvoid\@mpfootins\else - \vskip\skip\@mpfootins\normalcolor\footnoterule\unvbox\@mpfootins - \fi - \@minipagefalse\endMakeFramed + \@minipagefalse + \endMakeFramed + % set footnotes at bottom of page + \spewnotes % arrange for similar spacing below frame as for "light" boxes. \vskip .4\baselineskip } diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 7ce35b80fbb..625955c42a5 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -179,15 +179,11 @@ def expand_show_urls(self): if node.astext() != uri: index = node.parent.index(node) if show_urls == 'footnote': - if list(traverse_parent(node, nodes.topic)): - # should not expand references in topics - pass - else: - footnote_nodes = self.create_footnote(uri) - for i, fn in enumerate(footnote_nodes): - node.parent.insert(index + i + 1, fn) - - self.expanded = True + footnote_nodes = self.create_footnote(uri) + for i, fn in enumerate(footnote_nodes): + node.parent.insert(index + i + 1, fn) + + self.expanded = True else: # all other true values (b/w compat) textnode = nodes.Text(" (%s)" % uri) node.parent.insert(index + 1, textnode)