Skip to content

Commit

Permalink
Attempt using footnote.sty to re-enable footnotes in "topic" contexts
Browse files Browse the repository at this point in the history
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 sphinx-doc#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
  • Loading branch information
jfbu committed Apr 17, 2016
1 parent fae8db9 commit ebb6ab5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
34 changes: 18 additions & 16 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
}


Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 5 additions & 9 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ebb6ab5

Please sign in to comment.