SF.net SVN: docutils:[10316 ] trunk/docutils

milde--- via Docutils-checkins <[email protected]> Thu, 30 Apr 2026 19:17:03 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10316
          http://sourceforge.net/p/docutils/code/10316
Author:   milde
Date:     2026-04-30 19:17:00 +0000 (Thu, 30 Apr 2026)
Log Message:
-----------
Fixup for latex-footnotes.

Only deactivate "hyperfootnotes" if ``docutils_footnotes`` is True.

Simplify code:
  After the `Footnotes` transform, all footnote references contain
  a "refid" attribute.

  Use `document.ids` (a mapping of ids to nodes populated by the
  parser and transforms) to get the footnote text.

Add comments.

The functional test fails with a RecursionError.
This will be solved in the next commits.

Modified Paths:
--------------
    trunk/docutils/docutils/writers/latex2e/__init__.py
    trunk/docutils/test/functional/expected/latex_footnotes.tex

Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py	2026-04-30 19:16:50 UTC (rev 10315)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py	2026-04-30 19:17:00 UTC (rev 10316)
@@ -1382,8 +1382,10 @@
                            for path in stylesheet_list]
 
         # PDF setup
+        self.hyperref_options = []
         # avoid warnings about empty anchors with \DUfootnotetext:
-        self.hyperref_options = ['hyperfootnotes=false']
+        if self.docutils_footnotes:
+            self.hyperref_options = ['hyperfootnotes=false']
         # link color (default is "blue"):
         if self.hyperlink_color.lower() not in ('0', 'off', 'no', 'false', ''):
             self.hyperref_options.append('colorlinks=true,'
@@ -2379,6 +2381,8 @@
             if len(node) > 1 and isinstance(node[1], nodes.paragraph):
                 self.out.append('%')
         elif not self.footnote_queues:
+            # latex-footnotes: set only scheduled footnotes
+            # (see `visit_footnote_reference()`)
             raise nodes.SkipNode
 
     def depart_footnote(self, node) -> None:
@@ -2386,11 +2390,7 @@
             self.out.append('}\n')
 
     def visit_footnote_reference(self, node) -> None:
-        href = ''
-        if 'refid' in node:
-            href = node['refid']
-        elif 'refname' in node:
-            href = self.document.nameids[node['refname']]
+        href = node['refid']
         if self.docutils_footnotes:
             format = self.settings.footnote_references
             if format == 'brackets':
@@ -2403,22 +2403,13 @@
                 self.out.append(r'\DUfootnotemark{%s}{%s}{' %
                                 (node['ids'][0], href))
                 self.context.append('}')
-        else:
-            footnotes = (self.document.footnotes
-                         + self.document.autofootnotes
-                         + self.document.symbol_footnotes)
-            for footnote in footnotes:
-                if href in footnote['ids']:
-                    self.footnote_queues.append([])
-                    self.push_output_collector([])
-                    footnote.walkabout(self)
-                    text = ''.join(self.out)
-                    self.pop_output_collector()
-                    break
-            else:
-                self.document.reporter.error(
-                    "Footnote %s referenced but not found" % href)
-                raise nodes.SkipNode
+        else:  # latex-footnotes
+            footnote = self.document.ids[href]
+            # write footnote content into string `text`
+            self.footnote_queues.append([])
+            self.push_output_collector([])
+            footnote.walkabout(self)
+            text = ''.join(self.pop_output_collector())
             queued = self.footnote_queues.pop()
             if not self.footnote_queues:
                 self.out.append("\\footnote{%")
@@ -2433,6 +2424,10 @@
                 self.footnote_queues[-1].append(text)
                 self.footnote_queues[-1].extend(queued)
             raise nodes.SkipNode
+            # TODO:
+            # * Prepend a label if the footnote is an explicit target.
+            # * use \footref (part of LaTeX since 2021-05-01)
+            #   for multiple refs to the same footnote.
 
     def depart_footnote_reference(self, node) -> None:
         self.out.append(self.context.pop())

Modified: trunk/docutils/test/functional/expected/latex_footnotes.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_footnotes.tex	2026-04-30 19:16:50 UTC (rev 10315)
+++ trunk/docutils/test/functional/expected/latex_footnotes.tex	2026-04-30 19:17:00 UTC (rev 10316)
@@ -17,8 +17,7 @@
 % hyperlinks:
 \ifdefined\hypersetup
 \else
-  \usepackage[hyperfootnotes=false,
-              colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
+  \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
   \usepackage{bookmark}
   \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
 \fi

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.