From 5b2b0ecfd3dda77ad3a110286eea24fd484b42dc Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 Aug 2010 15:17:12 +0200 Subject: [PATCH] Better references to tables, as well. --- sphinx/writers/latex.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 03c90fe27..1bb534a0b 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -225,6 +225,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.top_sectionlevel = 1 self.next_section_ids = set() self.next_figure_ids = set() + self.next_table_ids = set() # flags self.verbatim = None self.in_title = 0 @@ -634,7 +635,10 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append('{|' + ('L|' * self.table.colcount) + '}\n') if self.table.longtable and self.table.caption is not None: self.body.append(u'\\caption{%s} \\\\\n' % self.table.caption) - + if self.table.caption is not None: + for id in self.next_table_ids: + self.body.append(self.hypertarget(id, anchor=False)) + self.next_table_ids.clear() if self.table.longtable: self.body.append('\\hline\n') self.body.append('\\endfirsthead\n\n') @@ -989,10 +993,19 @@ class LaTeXTranslator(nodes.NodeVisitor): self.next_section_ids.update(node['ids']) return elif isinstance(next, nodes.figure): + # labels for figures go in the figure body, not before if node.get('refid'): self.next_figure_ids.add(node['refid']) self.next_figure_ids.update(node['ids']) return + elif isinstance(next, nodes.table): + # same for tables, but only if they have a caption + for n in node: + if isinstance(n, nodes.title): + if node.get('refid'): + self.next_table_ids.add(node['refid']) + self.next_table_ids.update(node['ids']) + return except IndexError: pass if 'refuri' in node: