Fix #2292: Some footnotes disappear from LaTeX output

This commit is contained in:
Takeshi KOMIYA 2016-02-07 22:58:14 +09:00
parent 9b958b6dcc
commit 9ba7cc815c
6 changed files with 42 additions and 13 deletions

View File

@ -8,6 +8,7 @@ Bugs fixed
* #2295: Avoid mutating dictionary errors while enumerating members in autodoc
with Python 3
* #2291: Fix pdflatex "Counter too large" error from footnotes inside tables of contents
* #2292: Fix some footnotes disappear from LaTeX output
Release 1.3.5 (released Jan 24, 2016)

View File

@ -199,9 +199,14 @@ class ShowUrlsTransform(object):
def is_auto_footnote(node):
return isinstance(node, nodes.footnote) and node.get('auto')
def footnote_ref_by(ids):
def footnote_ref_by(node):
ids = node['ids']
parent = list(traverse_parent(node, (nodes.document, addnodes.start_of_file)))[0]
def is_footnote_ref(node):
return isinstance(node, nodes.footnote_reference) and ids[0] == node['refid']
return (isinstance(node, nodes.footnote_reference) and
ids[0] == node['refid'] and
parent in list(traverse_parent(node)))
return is_footnote_ref
@ -220,7 +225,7 @@ class ShowUrlsTransform(object):
footnote['names'].remove(old_label)
footnote['names'].append(label)
for footnote_ref in self.document.traverse(footnote_ref_by(footnote['ids'])):
for footnote_ref in self.document.traverse(footnote_ref_by(footnote)):
footnote_ref.remove(footnote_ref[0])
footnote_ref += nodes.Text(label)

View File

@ -0,0 +1,6 @@
bar
===
Same footnote number [1]_ in bar.rst
.. [1] footnote in bar

View File

@ -0,0 +1,6 @@
baz
===
Auto footnote number [#]_ in baz.rst
.. [#] footnote in baz

View File

@ -2,6 +2,11 @@
test-footenotes
===============
.. toctree::
bar
baz
.. contents::
:local:

View File

@ -372,6 +372,8 @@ def test_latex_show_urls_is_inline(app, status, warning):
print(result)
print(status.getvalue())
print(warning.getvalue())
assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result
assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
'\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
'{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'
@ -405,6 +407,8 @@ def test_latex_show_urls_is_footnote(app, status, warning):
print(result)
print(status.getvalue())
print(warning.getvalue())
assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
assert 'Auto footnote number \\footnote[2]{\nfootnote in baz\n} in baz.rst' in result
assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
'\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
'{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'
@ -412,20 +416,20 @@ def test_latex_show_urls_is_footnote(app, status, warning):
assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
'\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section '
'with a reference to }}}' in result)
assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
assert 'First footnote: \\footnote[3]{\nFirst\n}' in result
assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
assert ('\\href{http://sphinx-doc.org/}{Sphinx}'
'\\footnote[3]{\nhttp://sphinx-doc.org/\n}' in result)
assert 'Third footnote: \\footnote[5]{\nThird\n}' in result
'\\footnote[4]{\nhttp://sphinx-doc.org/\n}' in result)
assert 'Third footnote: \\footnote[6]{\nThird\n}' in result
assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}'
'\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\protect\\footnotemark[7]}] '
'\\leavevmode\\footnotetext[7]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
assert ('\\item[{Footnote in term \\protect\\footnotemark[9]}] '
'\\leavevmode\\footnotetext[9]{\nFootnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\protect'
'\\footnotemark[8]}] '
'\\footnote[5]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\protect\\footnotemark[8]}] '
'\\leavevmode\\footnotetext[8]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
assert ('\\item[{Footnote in term \\protect\\footnotemark[10]}] '
'\\leavevmode\\footnotetext[10]{\nFootnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\protect'
'\\footnotemark[9]}] '
'\\leavevmode\\footnotetext[9]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
'{https://github.com/sphinx-doc/sphinx}\n' in result)
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
@ -440,6 +444,8 @@ def test_latex_show_urls_is_no(app, status, warning):
print(result)
print(status.getvalue())
print(warning.getvalue())
assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result
assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
'\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
'{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'