From e03dc8d27e7eeecea6801cf18d4360c37e877376 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 6 Jan 2016 11:13:30 +0900 Subject: [PATCH] Fix #2072: Footnotes in chapter-titles do not appear in PDF output --- CHANGES | 1 + sphinx/writers/latex.py | 2 ++ tests/roots/test-footnotes/index.rst | 4 +++- tests/test_build_latex.py | 34 +++++++++++++++------------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index de0e01bfa..a3b950e64 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,7 @@ Bugs fixed * #771: Fix latex output doesn't set tocdepth * #1820: On Windows, console coloring is broken with colorama version 0.3.3. Now sphinx use colorama>=0.3.5 to avoid this problem. +* #2072: Fix footnotes in chapter-titles do not appear in PDF output Release 1.3.3 (released Dec 2, 2015) ==================================== diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 478d50318..784c58c21 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -724,6 +724,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append(r'\%s{' % self.sectionnames[-1]) self.context.append('}\n') + self.restrict_footnote(node) if self.next_section_ids: for id in self.next_section_ids: self.context[-1] += self.hypertarget(id, anchor=False) @@ -753,6 +754,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.table.caption = self.popbody() else: self.body.append(self.context.pop()) + self.unrestrict_footnote(node) def visit_subtitle(self, node): if isinstance(node.parent, nodes.sidebar): diff --git a/tests/roots/test-footnotes/index.rst b/tests/roots/test-footnotes/index.rst index 0c0e29b39..a20052037 100644 --- a/tests/roots/test-footnotes/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -33,9 +33,11 @@ The section with a reference to [AuthorYear]_ .. [1] Second .. [#] Third -The section with a reference to [1]_ +The section with a reference to [#]_ ===================================== +.. [#] Footnote in section + `URL in term `_ Description Description Description ... diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 9b58a6746..e86a794fa 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -332,15 +332,17 @@ def test_reference_in_caption(app, status, warning): assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result - assert '\\chapter{The section with a reference to \\protect\\footnotemark[1]}' in result + assert ('\\chapter{The section with a reference to \\protect\\footnotemark[4]}\n' + '\\label{index:the-section-with-a-reference-to}' + '\\footnotetext[4]{\nFootnote in section\n}' in result) assert ('\\caption{This is the figure caption with a footnote to ' - '\\protect\\footnotemark[5].}\end{figure}\n' - '\\footnotetext[5]{\nFootnote in caption\n}')in result - assert ('\\caption{footnote \\protect\\footnotemark[6] ' + '\\protect\\footnotemark[6].}\end{figure}\n' + '\\footnotetext[6]{\nFootnote in caption\n}')in result + assert ('\\caption{footnote \\protect\\footnotemark[7] ' 'in caption of normal table}') in result - assert '\\end{threeparttable}\n\n\\footnotetext[6]{\nFoot note in table\n}' in result - assert '\\caption{footnote \\protect\\footnotemark[7] in caption of longtable}' in result - assert '\end{longtable}\n\n\\footnotetext[7]{\nFoot note in longtable\n}' in result + assert '\\end{threeparttable}\n\n\\footnotetext[7]{\nFoot note in table\n}' in result + assert '\\caption{footnote \\protect\\footnotemark[8] in caption of longtable}' in result + assert '\end{longtable}\n\n\\footnotetext[8]{\nFoot note in longtable\n}' in result @with_app(buildername='latex', testroot='footnotes', @@ -359,8 +361,8 @@ def test_latex_show_urls_is_inline(app, status, warning): '(http://sphinx-doc.org/\\textasciitilde{}test/)' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term} (http://sphinx-doc.org/)}] ' '\\leavevmode\nDescription' in result) - assert ('\\item[{Footnote in term \\protect\\footnotemark[4]}] ' - '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) + assert ('\\item[{Footnote in term \\protect\\footnotemark[5]}] ' + '\\leavevmode\\footnotetext[5]{\nFootnote in term\n}\nDescription' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} ' '(http://sphinx-doc.org/)}] \\leavevmode\nDescription' in result) assert ('\\href{https://github.com/sphinx-doc/sphinx}' @@ -384,12 +386,12 @@ def test_latex_show_urls_is_footnote(app, status, warning): assert 'Third footnote: \\footnote[5]{\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[6]}] ' - '\\leavevmode\\footnotetext[6]{\nhttp://sphinx-doc.org/\n}\nDescription' in result) - assert ('\\item[{Footnote in term \\protect\\footnotemark[8]}] ' - '\\leavevmode\\footnotetext[8]{\nFootnote in term\n}\nDescription' in result) - assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\protect\\footnotemark[7]}] ' + 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]}] ' + '\\leavevmode\\footnotetext[8]{\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}' @@ -411,8 +413,8 @@ def test_latex_show_urls_is_no(app, status, warning): assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}}] ' '\\leavevmode\nDescription' in result) - assert ('\\item[{Footnote in term \\protect\\footnotemark[4]}] ' - '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) + assert ('\\item[{Footnote in term \\protect\\footnotemark[5]}] ' + '\\leavevmode\\footnotetext[5]{\nFootnote in term\n}\nDescription' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] ' '\\leavevmode\nDescription' in result) assert ('\\href{https://github.com/sphinx-doc/sphinx}'