Commits

dan mackinlay committed 4458d7d

kludgey but working manual citation system

  • Participants
  • Parent commits c74a1ce

Comments (0)

Files changed (3)

_ext/manualxetex.py

+"""Disable as moch of ReST's truly overblown citation intervention as possible.
+I just want to pump unadorned citaions out and let BibTeX field this one.
+"""
+
+import docutils.writers.xetex
+from docutils import nodes
+
+class Writer(docutils.writers.xetex.Writer):
+    def __init__(self):
+        docutils.writers.xetex.Writer.__init__(self)
+        self.translator_class = ManualXeLaTeXTranslator
+
+class ManualXeLaTeXTranslator(docutils.writers.xetex.XeLaTeXTranslator):
+    def visit_manualcite(self, node):
+        if not self.inside_citation_reference_label:
+            self.out.append(r'\cite{')
+            self.inside_citation_reference_label = 1
+        else:
+            assert self.body[-1] in (' ', '\n'),\
+                    'unexpected non-whitespace while in reference label'
+            del self.body[-1]
+
+    def depart_manualcite(self, node):
+        followup_citation = False
+        # check for a following citation separated by a space or newline
+        next_siblings = node.traverse(descend=False, siblings=True,
+                                      include_self=False)
+        if len(next_siblings) > 1:
+            next = next_siblings[0]
+            if (isinstance(next, nodes.Text) and
+                next.astext() in (' ', '\n')):
+                if next_siblings[1].__class__ == node.__class__:
+                    followup_citation = True
+        if followup_citation:
+            self.out.append(',')
+        else:
+            self.out.append('}')
+            self.inside_citation_reference_label = False
+

_ext/pp_docutils_helper.py

 import docutils.nodes
 from docutils.parsers.rst import roles
 
-class ManualCite(docutils.nodes.citation_reference):
+class manualcite(docutils.nodes.citation_reference):
     "Just a citation ref, really but subclassed so we can treat it differently"
     pass
 
     :param content: The directive content for customization.
     """
 
-    app = inliner.document.settings.env.app
-    node = ManualCite(rawtext)
+    node = manualcite(rawsource=rawtext,text=text)
     return [node], []
 
 def register_roles():
                '<http://docutils.sourceforge.net/docs/user/latex.html> for '
                'the full reference.')
 
-publish_cmdline(writer_name='xetex', description=description)
+publish_cmdline(writer_name='manualxetex', description=description)