Georg Brandl avatar Georg Brandl committed 813aacd

Fix problems with footnotes in the LaTeX output.

Comments (0)

Files changed (2)

 Release 0.5.2 (in development)
+* Fix problems with footnotes in the LaTeX output.
 * Prevent double hyphens becoming en-dashes in literal code in
   the LaTeX output.


+class collected_footnote(nodes.footnote):
+    """Footnotes that are collected are assigned this class."""
 class LaTeXWriter(writers.Writer):
                         yield k
         for fn in footnotes_under(node):
             num = fn.children[0].astext().strip()
-            fnotes[num] = fn
-            fn.parent.remove(fn)
+            fnotes[num] = [collected_footnote(*fn.children), False]
         return fnotes
     def depart_start_of_file(self, node):
     def visit_footnote(self, node):
-        pass
-    def depart_footnote(self, node):
-        pass
+        raise nodes.SkipNode
+    def visit_collected_footnote(self, node):
+        self.body.append('\\footnote{')
+    def depart_collected_footnote(self, node):
+        self.body.append('}')
     def visit_label(self, node):
         if isinstance(node.parent, nodes.citation):
     def visit_footnote_reference(self, node):
         num = node.astext().strip()
-            fn = self.footnotestack[-1][num]
+            footnode, used = self.footnotestack[-1][num]
         except (KeyError, IndexError):
             raise nodes.SkipNode
-        self.body.append('\\footnote{')
-        fn.walkabout(self)
+        # if a footnote has been inserted once, it shouldn't be repeated
+        # 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
     def depart_footnote_reference(self, node):
-        self.body.append('}')
+        pass
     def visit_literal_block(self, node):
         self.verbatim = ''
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
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.