diff --git a/CHANGES b/CHANGES index 03e8ebe62..1be7c2c43 100644 --- a/CHANGES +++ b/CHANGES @@ -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) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 434d8a699..31189c7da 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -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) diff --git a/tests/roots/test-footnotes/bar.rst b/tests/roots/test-footnotes/bar.rst new file mode 100644 index 000000000..660c66306 --- /dev/null +++ b/tests/roots/test-footnotes/bar.rst @@ -0,0 +1,6 @@ +bar +=== + +Same footnote number [1]_ in bar.rst + +.. [1] footnote in bar diff --git a/tests/roots/test-footnotes/baz.rst b/tests/roots/test-footnotes/baz.rst new file mode 100644 index 000000000..af496c5f6 --- /dev/null +++ b/tests/roots/test-footnotes/baz.rst @@ -0,0 +1,6 @@ +baz +=== + +Auto footnote number [#]_ in baz.rst + +.. [#] footnote in baz diff --git a/tests/roots/test-footnotes/index.rst b/tests/roots/test-footnotes/index.rst index 228fccf8d..3a8bc25c5 100644 --- a/tests/roots/test-footnotes/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -2,6 +2,11 @@ test-footenotes =============== +.. toctree:: + + bar + baz + .. contents:: :local: diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4533ee4c0..c4a887d44 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -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}'