Georg Brandl avatar Georg Brandl committed c3a4ec6 Merge

Merge with http://bitbucket.org/chrism/sphinx/, add latex_show_pagrefs/latex_show_urls config values.

Comments (0)

Files changed (6)

   - Added the ``trim_doctest_flags`` config value, which is true by
     default.
   - Added ``html_show_copyright`` config value.
+  - Added ``latex_show_pagerefs`` and ``latex_show_urls`` config values.
 
 * New builders:
 
    .. deprecated:: 1.0
       Use :confval:`latex_domain_indices`.
 
+.. confval:: latex_show_pagerefs
+
+   If true, add page references after internal references.  This is very useful
+   for printed copies of the manual.  Default is ``False``.
+
+   .. versionadded:: 1.0
+
+.. confval:: latex_show_urls
+
+   If true, add URL addresses after links.  This is very useful for printed
+   copies of the manual.  Default is ``False``.
+
+   .. versionadded:: 1.0
+
 .. confval:: latex_elements
 
    .. versionadded:: 0.5
         latex_use_parts = (False, None),
         latex_use_modindex = (True, None),  # deprecated
         latex_domain_indices = (True, None),
+        latex_show_urls = (False, None),
+        latex_show_pagerefs = (False, None),
         # paper_size and font_size are still separate values
         # so that you can give them easily on the command line
         latex_paper_size = ('letter', None),

sphinx/quickstart.py

 # not chapters.
 #latex_use_parts = False
 
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
 # Additional stuff for the LaTeX preamble.
 #latex_preamble = ''
 

sphinx/writers/latex.py

     def hyperlink(self, id):
         return '\\hyperref[%s]{' % (self.idescape(id))
 
+    def hyperpageref(self, id):
+        return '\\autopageref*{%s}' % (self.idescape(id))
+
     def idescape(self, id):
         return str(unicode(id).translate(tex_replace_map))
 
         if self.in_title or not uri:
             self.context.append('')
         elif uri.startswith('mailto:') or uri.startswith('http:') or \
-             uri.startswith('https:') or uri.startswith('ftp:'):
+                 uri.startswith('https:') or uri.startswith('ftp:'):
             self.body.append('\\href{%s}{' % self.encode_uri(uri))
-            self.context.append('}')
+            # if configured, put the URL after the link
+            if self.builder.config.latex_show_urls and \
+                   node.astext() != uri:
+                if uri.startswith('mailto:'):
+                    uri = uri[7:]
+                self.context.append('} (%s)' % self.encode_uri(uri))
+            else:
+                self.context.append('}')
         elif uri.startswith('#'):
             # references to labels in the same document
-            self.body.append(self.hyperlink(self.curfilestack[-1] +
-                                            ':' + uri[1:]))
-            self.context.append('}')
+            id = self.curfilestack[-1] + ':' + uri[1:]
+            self.body.append(self.hyperlink(id))
+            if self.builder.config.latex_show_pagerefs:
+                self.context.append('} (%s)' % self.hyperpageref(id))
+            else:
+                self.context.append('}')
         elif uri.startswith('%'):
             # references to documents or labels inside documents
             hashindex = uri.find('#')
                 # reference to a label
                 id = uri[1:].replace('#', ':')
             self.body.append(self.hyperlink(id))
-            self.context.append('}')
+            if len(node) and 'std-term' in node[0].get('classes', []):
+                # don't add a pageref for glossary terms
+                self.context.append('}')
+            else:
+                if self.builder.config.latex_show_pagerefs:
+                    self.context.append('} (%s)' % self.hyperpageref(id))
+                else:
+                    self.context.append('}')
         elif uri.startswith('@token'):
             if self.in_production_list:
                 self.body.append('\\token{')

File contents unchanged.

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.