Fix section and table titles with reference cause latex build error

This commit is contained in:
Takeshi KOMIYA
2015-12-03 11:39:25 +09:00
parent 32b483d5bc
commit c8837338d3
3 changed files with 19 additions and 4 deletions

View File

@@ -1381,9 +1381,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
raise nodes.SkipNode
def visit_reference(self, node):
for id in node.get('ids'):
anchor = not self.in_caption
self.body += self.hypertarget(id, anchor=anchor)
if not self.in_title:
for id in node.get('ids'):
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

@@ -1,8 +1,20 @@
==============
test-reference
==============
The section with a reference to [AuthorYear]_
=============================================
.. figure:: rimg.png
This is the figure caption with a reference to [AuthorYear]_.
.. list-table:: The table title with a reference to [AuthorYear]_
:header-rows: 1
* - Header1
- Header2
* - Content
- Content
.. [AuthorYear] Author, Title, Year

View File

@@ -327,5 +327,7 @@ def test_reference_in_caption(app, status, warning):
print(result)
print(status.getvalue())
print(warning.getvalue())
assert ('\\caption{This is the figure caption with a reference to \\label{index:id1}'
assert ('\\caption{This is the figure caption with a reference to \\label{index:id2}'
'{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}.}' in result)
assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result
assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result