Fix #2134 figure caption with reference causes latex build error

This commit is contained in:
Takeshi KOMIYA 2015-12-03 10:33:15 +09:00
parent 7cbd1254a9
commit 32b483d5bc
6 changed files with 27 additions and 1 deletions

View File

@ -4,6 +4,8 @@ Release 1.3.4 (in development)
Bugs fixed
----------
* #2134 Fix figure caption with reference causes latex build error
Release 1.3.3 (released Dec 2, 2015)
====================================

View File

@ -1382,7 +1382,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_reference(self, node):
for id in node.get('ids'):
self.body += self.hypertarget(id, anchor=True)
anchor = not self.in_caption
self.body += self.hypertarget(id, anchor=anchor)
uri = node.get('refuri', '')
if not uri and node.get('refid'):
uri = '%' + self.curfilestack[-1] + '#' + node['refid']

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
html_theme = 'classic'

View File

@ -0,0 +1,8 @@
test-reference
==============
.. figure:: rimg.png
This is the figure caption with a reference to [AuthorYear]_.
.. [AuthorYear] Author, Title, Year

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

View File

@ -318,3 +318,14 @@ def test_footnote(app, status, warning):
assert ('\\end{threeparttable}\n\n'
'\\footnotetext[4]{\nfootnotes in table caption\n}'
'\\footnotetext[5]{\nfootnotes in table\n}' in result)
@with_app(buildername='latex', testroot='references-in-caption')
def test_reference_in_caption(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
print(result)
print(status.getvalue())
print(warning.getvalue())
assert ('\\caption{This is the figure caption with a reference to \\label{index:id1}'
'{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}.}' in result)