This commit is contained in:
Georg Brandl 2009-02-07 20:21:02 +01:00
commit 0b34fa7ef3
2 changed files with 21 additions and 9 deletions

View File

@ -120,6 +120,8 @@ New features added
Release 0.5.2 (in development) Release 0.5.2 (in development)
============================== ==============================
* Fix problems with footnotes in the LaTeX output.
* Prevent double hyphens becoming en-dashes in literal code in * Prevent double hyphens becoming en-dashes in literal code in
the LaTeX output. the LaTeX output.

View File

@ -62,6 +62,9 @@ FOOTER = r'''
\end{document} \end{document}
''' '''
class collected_footnote(nodes.footnote):
"""Footnotes that are collected are assigned this class."""
class LaTeXWriter(writers.Writer): class LaTeXWriter(writers.Writer):
@ -279,8 +282,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
yield k yield k
for fn in footnotes_under(node): for fn in footnotes_under(node):
num = fn.children[0].astext().strip() num = fn.children[0].astext().strip()
fnotes[num] = fn fnotes[num] = [collected_footnote(*fn.children), False]
fn.parent.remove(fn)
return fnotes return fnotes
def depart_start_of_file(self, node): def depart_start_of_file(self, node):
@ -550,9 +552,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append(self.context.pop()) self.body.append(self.context.pop())
def visit_footnote(self, node): def visit_footnote(self, node):
pass raise nodes.SkipNode
def depart_footnote(self, node):
pass def visit_collected_footnote(self, node):
self.body.append('\\footnote{')
def depart_collected_footnote(self, node):
self.body.append('}')
def visit_label(self, node): def visit_label(self, node):
if isinstance(node.parent, nodes.citation): if isinstance(node.parent, nodes.citation):
@ -1034,14 +1039,19 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_footnote_reference(self, node): def visit_footnote_reference(self, node):
num = node.astext().strip() num = node.astext().strip()
try: try:
fn = self.footnotestack[-1][num] footnode, used = self.footnotestack[-1][num]
except (KeyError, IndexError): except (KeyError, IndexError):
raise nodes.SkipNode raise nodes.SkipNode
self.body.append('\\footnote{') # if a footnote has been inserted once, it shouldn't be repeated
fn.walkabout(self) # by the next reference
if used:
self.body.append('\\footnotemark[%s]' % num)
else:
footnode.walkabout(self)
self.footnotestack[-1][num][1] = True
raise nodes.SkipChildren raise nodes.SkipChildren
def depart_footnote_reference(self, node): def depart_footnote_reference(self, node):
self.body.append('}') pass
def visit_literal_block(self, node): def visit_literal_block(self, node):
self.verbatim = '' self.verbatim = ''