Georg Brandl avatar Georg Brandl committed 27c1dd6

#295: Fix escaping of hyperref targets in LaTeX output.

Comments (0)

Files changed (2)

 Release 0.6.4 (in development)
 ==============================
 
+* #295: Fix escaping of hyperref targets in LaTeX output.
+
 * #302: Fix links generated by the ``:doc:`` role for LaTeX output.
 
 * #286: collect todo nodes after the whole document has been read;

sphinx/writers/latex.py

         return (HEADER % self.elements + self.highlighter.get_stylesheet() +
                 u''.join(self.body) + FOOTER % self.elements)
 
+    def idescape(self, id):
+        return str(unicode(id).translate(tex_escape_map))
+
     def visit_document(self, node):
         self.footnotestack.append(self.collect_footnotes(node))
         self.curfilestack.append(node.get('docname', ''))
         d = self.descstack[-1]
         d.cls = d.cls.rstrip('.')
         if node.parent['desctype'] != 'describe' and node['ids']:
-            hyper = '\\hypertarget{%s}{}' % node['ids'][0]
+            hyper = '\\hypertarget{%s}{}' % self.idescape(node['ids'][0])
         else:
             hyper = ''
         if d.count == 0:
     def visit_term(self, node):
         ctx = '] \\leavevmode'
         if node.has_key('ids') and node['ids']:
-            ctx += '\\hypertarget{%s}{}' % node['ids'][0]
+            ctx += '\\hypertarget{%s}{}' % self.idescape(node['ids'][0])
         self.body.append('\\item[')
         self.context.append(ctx)
     def depart_term(self, node):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.