Fix #1237 footnotes not working in definition list in LaTeX

This commit is contained in:
Takeshi KOMIYA 2015-12-08 12:16:15 +09:00
parent 5fc4536040
commit 5983d02787
4 changed files with 46 additions and 3 deletions

View File

@ -10,6 +10,7 @@ Bugs fixed
* #1833: Fix email addresses is showed again if latex_show_urls is not None * #1833: Fix email addresses is showed again if latex_show_urls is not None
* #2176: sphinx.ext.graphviz: use <object> instead of <img> to embed svg * #2176: sphinx.ext.graphviz: use <object> instead of <img> to embed svg
* #967: Fix SVG inheritance diagram is not hyperlinked (clickable) * #967: Fix SVG inheritance diagram is not hyperlinked (clickable)
* #1237: Fix footnotes not working in definition list in LaTeX
Release 1.3.3 (released Dec 2, 2015) Release 1.3.3 (released Dec 2, 2015)

View File

@ -373,6 +373,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
sys.maxsize]] sys.maxsize]]
self.bodystack = [] self.bodystack = []
self.footnotestack = [] self.footnotestack = []
self.termfootnotestack = []
self.curfilestack = [] self.curfilestack = []
self.handled_abbrs = set() self.handled_abbrs = set()
if document.settings.docclass == 'howto': if document.settings.docclass == 'howto':
@ -392,6 +393,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.in_footnote = 0 self.in_footnote = 0
self.in_caption = 0 self.in_caption = 0
self.in_container_literal_block = 0 self.in_container_literal_block = 0
self.in_term = 0
self.first_document = 1 self.first_document = 1
self.this_is_the_title = 1 self.this_is_the_title = 1
self.literal_whitespace = 0 self.literal_whitespace = 0
@ -856,7 +858,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_collected_footnote(self, node): def visit_collected_footnote(self, node):
self.in_footnote += 1 self.in_footnote += 1
if 'in_table' in node: if 'footnotetext' in node:
self.body.append('\\footnotetext[%s]{' % node['number']) self.body.append('\\footnotetext[%s]{' % node['number'])
else: else:
self.body.append('\\footnote[%s]{' % node['number']) self.body.append('\\footnote[%s]{' % node['number'])
@ -959,7 +961,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append('\\end{threeparttable}\n\n') self.body.append('\\end{threeparttable}\n\n')
if self.table.footnotes: if self.table.footnotes:
for footnode in self.table.footnotes: for footnode in self.table.footnotes:
footnode['in_table'] = True footnode['footnotetext'] = True
footnode.walkabout(self) footnode.walkabout(self)
self.table = None self.table = None
self.tablebody = None self.tablebody = None
@ -1126,14 +1128,22 @@ class LaTeXTranslator(nodes.NodeVisitor):
pass pass
def visit_term(self, node): def visit_term(self, node):
self.in_term += 1
ctx = '}] \\leavevmode' ctx = '}] \\leavevmode'
if node.get('ids'): if node.get('ids'):
ctx += self.hypertarget(node['ids'][0]) ctx += self.hypertarget(node['ids'][0])
self.body.append('\\item[{') self.body.append('\\item[{')
self.termfootnotestack.append([])
self.context.append(ctx) self.context.append(ctx)
def depart_term(self, node): def depart_term(self, node):
self.body.append(self.context.pop()) self.body.append(self.context.pop())
footnotes = self.termfootnotestack.pop()
for footnode in footnotes:
footnode['footnotetext'] = True
footnode.walkabout(self)
self.in_term -= 1
def visit_termsep(self, node): def visit_termsep(self, node):
self.body.append(', ') self.body.append(', ')
@ -1647,7 +1657,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
# if a footnote has been inserted once, it shouldn't be repeated # if a footnote has been inserted once, it shouldn't be repeated
# by the next reference # by the next reference
if used: if used:
if self.table: if self.table or self.in_term:
self.body.append('\\protect\\footnotemark[%s]' % num) self.body.append('\\protect\\footnotemark[%s]' % num)
else: else:
self.body.append('\\footnotemark[%s]' % num) self.body.append('\\footnotemark[%s]' % num)
@ -1655,6 +1665,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.footnotestack[-1][num][1] = True self.footnotestack[-1][num][1] = True
self.body.append('\\protect\\footnotemark[%s]' % num) self.body.append('\\protect\\footnotemark[%s]' % num)
self.table.footnotes.append(footnode) self.table.footnotes.append(footnode)
elif self.in_term:
self.body.append('\\footnotemark[%s]' % num)
self.termfootnotestack[-1].append(footnode)
else: else:
if self.in_caption: if self.in_caption:
raise UnsupportedError('%s:%s: footnotes in float captions ' raise UnsupportedError('%s:%s: footnotes in float captions '

View File

@ -30,3 +30,14 @@ The section with a reference to [AuthorYear]_
.. [AuthorYear] Author, Title, Year .. [AuthorYear] Author, Title, Year
.. [1] Second .. [1] Second
.. [#] Third .. [#] Third
`URL in term <http://sphinx-doc.org/>`_
Description Description Description ...
Footnote in term [#]_
Description Description Description ...
`Term in deflist <http://sphinx-doc.org/>`_
Description2
.. [#] Footnote in term

View File

@ -351,6 +351,12 @@ def test_latex_show_urls_is_inline(app, status, warning):
assert 'Third footnote: \\footnote[3]{\nThird\n}' in result assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} ' assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} '
'(http://sphinx-doc.org/\\textasciitilde{}test/)' in result) '(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 \\footnotemark[4]}] '
'\\leavevmode\\footnotetext[4]{\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)
@with_app(buildername='latex', testroot='footnotes', @with_app(buildername='latex', testroot='footnotes',
@ -368,6 +374,12 @@ def test_latex_show_urls_is_footnote(app, status, warning):
assert 'Third footnote: \\footnote[5]{\nThird\n}' in result assert 'Third footnote: \\footnote[5]{\nThird\n}' in result
assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}' assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}'
'\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result) '\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\footnotemark[6]}] '
'\\leavevmode\\footnotetext[6]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
assert ('\\item[{Footnote in term \\footnotemark[8]}] '
'\\leavevmode\\footnotetext[8]{\nFootnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\footnotemark[7]}] '
'\\leavevmode\\footnotetext[7]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
@with_app(buildername='latex', testroot='footnotes', @with_app(buildername='latex', testroot='footnotes',
@ -383,3 +395,9 @@ def test_latex_show_urls_is_no(app, status, warning):
assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result
assert 'Third footnote: \\footnote[3]{\nThird\n}' in result assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result 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 \\footnotemark[4]}] '
'\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] '
'\\leavevmode\nDescription' in result)