SF.net SVN: docutils:[10218 ] trunk/docutils
milde--- via Docutils-checkins <[email protected]> Wed, 20 Aug 2025 12:04:55 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10218
http://sourceforge.net/p/docutils/code/10218
Author: milde
Date: 2025-08-20 12:04:54 +0000 (Wed, 20 Aug 2025)
Log Message:
-----------
LaTeX writer: dont add `\phantomsection` for subtitle labels.
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/test_writers/test_latex2e_parts.py
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2025-08-20 12:04:42 UTC (rev 10217)
+++ trunk/docutils/HISTORY.rst 2025-08-20 12:04:54 UTC (rev 10218)
@@ -45,7 +45,7 @@
- Prepend ``\phantomsection`` to labelled math-blocks.
- Fix cross-reference anchor placement in figures, images,
- literal-blocks, and tables.
+ literal-blocks, tables, and (sub)titles.
- Simplify code for nested image.
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2025-08-20 12:04:42 UTC (rev 10217)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2025-08-20 12:04:54 UTC (rev 10218)
@@ -1381,7 +1381,8 @@
# -----------------
def stylesheet_call(self, path):
- """Return code to reference or embed stylesheet file `path`"""
+ """Return code to reference or embed stylesheet file `path`."""
+
path = Path(path)
# is it a package (no extension or *.sty) or "normal" tex code:
is_package = path.suffix in ('.sty', '')
@@ -2518,8 +2519,9 @@
# Handle "ids" attribute:
# do we need a \phantomsection?
- set_anchor = not (isinstance(node.parent, (nodes.caption, nodes.title))
- or isinstance(node, nodes.caption))
+ anchor_nodes = (nodes.caption, nodes.subtitle, nodes.title)
+ set_anchor = not (isinstance(node.parent, anchor_nodes)
+ or isinstance(node, anchor_nodes))
add_newline = isinstance(node, nodes.paragraph)
self.out += self.ids_to_labels(node, set_anchor, newline=add_newline)
# Handle "classes" attribute:
Modified: trunk/docutils/test/test_writers/test_latex2e_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e_parts.py 2025-08-20 12:04:42 UTC (rev 10217)
+++ trunk/docutils/test/test_writers/test_latex2e_parts.py 2025-08-20 12:04:54 UTC (rev 10218)
@@ -464,6 +464,45 @@
\date{}
"""
}],
+# document title and subtitle with labels
+["""\
+.. _top:
+
+The Document Title
+==================
+
+.. _what-for:
+
+for test purposes
+-----------------
+
+Links to top_ and what-for_.
+""",
+ {'body': r"""
+Links to \hyperref[top]{top} and \hyperref[what-for]{what-for}.
+""",
+ 'body_pre_docinfo': '\\maketitle\n',
+ 'fallbacks': r"""
+% subtitle (in document title)
+\providecommand*{\DUdocumentsubtitle}[1]{{\large #1}}
+""",
+ 'pdfsetup': DEFAULT_PARTS['pdfsetup'] + r"""\hypersetup{
+ pdftitle={The Document Title},
+}
+""",
+ 'subtitle': 'for test purposes',
+ 'title': 'The Document Title',
+ 'titledata': r"""\title{The Document Title%
+ \label{the-document-title}%
+ \label{top}%
+ \\%
+ \DUdocumentsubtitle{for test purposes}%
+ \label{for-test-purposes}%
+ \label{what-for}}
+\author{}
+\date{}
+"""
+ }],
# template
["""\
""",
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.