[Python-checkins] r63584 - in doctools/trunk: CHANGES sphinx/latexwriter.py
georg.brandl
python-checkins at python.org
Sat May 24 18:45:52 CEST 2008
Author: georg.brandl
Date: Sat May 24 18:45:52 2008
New Revision: 63584
Log:
Support citation nodes in latex writer.
Modified:
doctools/trunk/CHANGES
doctools/trunk/sphinx/latexwriter.py
Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES (original)
+++ doctools/trunk/CHANGES Sat May 24 18:45:52 2008
@@ -40,6 +40,8 @@
* Fix behavior of references to functions/methods with an explicit title.
+* Support citation nodes in LaTeX writer.
+
Release 0.3 (May 6, 2008)
=========================
Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py (original)
+++ doctools/trunk/sphinx/latexwriter.py Sat May 24 18:45:52 2008
@@ -123,6 +123,7 @@
'latex', builder.config.pygments_style)
self.context = []
self.descstack = []
+ self.bibitems = []
self.table = None
self.next_table_colspec = None
self.highlightlang = 'python'
@@ -170,7 +171,18 @@
# "- 1" because the level is increased before the title is visited
self.sectionlevel = self.top_sectionlevel - 1
def depart_document(self, node):
- pass
+ if self.bibitems:
+ widest_label = ""
+ for bi in self.bibitems:
+ if len(widest_label) < len(bi[0]):
+ widest_label = bi[0]
+ self.body.append('\n\\begin{thebibliography}{%s}\n' % widest_label)
+ for bi in self.bibitems:
+ # cite_key: underscores must not be escaped
+ cite_key = bi[0].replace(r"\_", "_")
+ self.body.append('\\bibitem[%s]{%s}{%s}\n' % (bi[0], cite_key, bi[1]))
+ self.body.append('\\end{thebibliography}\n')
+ self.bibitems = []
def visit_start_of_file(self, node):
# This marks the begin of a new file; therefore the current module and
@@ -779,6 +791,21 @@
def depart_title_reference(self, node):
self.body.append('}')
+ def visit_citation(self, node):
+ # TODO maybe use cite bibitems
+ self.context.append(len(self.body))
+ def depart_citation(self, node):
+ size = self.context.pop()
+ label = self.body[size]
+ text = ''.join(self.body[size+1:])
+ del self.body[size:]
+ self.bibitems.append([label, text])
+
+ def visit_citation_reference(self, node):
+ self.body.append('\\cite{')
+ def depart_citation_reference(self, node):
+ self.body.append('}')
+
def visit_literal(self, node):
content = self.encode(node.astext().strip())
if self.in_title:
More information about the Python-checkins
mailing list