Georg Brandl avatar Georg Brandl committed 70f2984

Make token references work as hyperlinks again in LaTeX output.

Comments (0)

Files changed (4)

 Release 1.0.7 (in development)
 ==============================
 
+* Make token references work as hyperlinks again in LaTeX output.
+
 * #572: Show warnings by default when reference labels cannot be
   found.
 

sphinx/builders/latex.py

         return 'all documents' # for now
 
     def get_target_uri(self, docname, typ=None):
-        if typ == 'token':
-            # token references are always inside production lists and must be
-            # replaced by \token{} in LaTeX
-            return '@token'
         if docname not in self.docnames:
             raise NoUri
         else:

sphinx/texinputs/sphinx.sty

   \addtolength{\py@argswidth}{\linewidth}%
   \item[#1\code{(}\py@sigparams{#2}{#3}]}
 
-% This version is being checked in for the historical record; it shows
-% how I've managed to get some aspects of this to work.  It will not
-% be used in practice, so a subsequent revision will change things
-% again.  This version has problems, but shows how to do something
-% that proved more tedious than I'd expected, so I don't want to lose
-% the example completely.
+% Production lists
 %
-\newcommand{\grammartoken}[1]{\texttt{#1}}
-\newenvironment{productionlist}[1][\@undefined]{
-  \def\optional##1{{\Large[}##1{\Large]}}
-  \def\production##1##2{\hypertarget{grammar-token-##1}{}%
-    \code{##1}&::=&\code{##2}\\}
-  \def\productioncont##1{& &\code{##1}\\}
-  \def\token##1{##1}
-  \let\grammartoken=\token
+\newenvironment{productionlist}{
+%  \def\optional##1{{\Large[}##1{\Large]}}
+  \def\production##1##2{\\\code{##1}&::=&\code{##2}}
+  \def\productioncont##1{\\& &\code{##1}}
   \parindent=2em
   \indent
   \begin{tabular}{lcl}

sphinx/writers/latex.py

                '\\label{%s}' % self.idescape(id)
 
     def hyperlink(self, id):
-        return '{\\hyperref[%s]{' % (self.idescape(id))
+        return '{\\hyperref[%s]{' % self.idescape(id)
 
     def hyperpageref(self, id):
-        return '\\autopageref*{%s}' % (self.idescape(id))
+        return '\\autopageref*{%s}' % self.idescape(id)
 
     def idescape(self, id):
         return str(unicode(id).translate(tex_replace_map))
 
     def visit_production(self, node):
         if node['tokenname']:
-            self.body.append('\\production{%s}{' %
-                             self.encode(node['tokenname']))
+            tn = node['tokenname']
+            self.body.append(self.hypertarget('grammar-token-' + tn))
+            self.body.append('\\production{%s}{' % self.encode(tn))
         else:
             self.body.append('\\productioncont{')
     def depart_production(self, node):
                     self.context.append('}} (%s)' % self.hyperpageref(id))
                 else:
                     self.context.append('}}')
-        elif uri.startswith('@token'):
-            if self.in_production_list:
-                self.body.append('\\token{')
-            else:
-                self.body.append('\\grammartoken{')
-            self.context.append('}')
         else:
             self.builder.warn('unusable reference target found: %s' % uri,
                               (self.curfilestack[-1], node.line))
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.