LaTeX writer: dont add \phantomsection for subtitle labels.

git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@10218 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
This commit is contained in:
milde
2025-08-20 12:04:54 +00:00
parent 4430777211
commit 02cfab2b1e
3 changed files with 45 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ Release 0.23b0 (unpublished)
- 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.

View File

@@ -1381,7 +1381,8 @@ class LaTeXTranslator(writers.DoctreeTranslator):
# -----------------
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 @@ class LaTeXTranslator(writers.DoctreeTranslator):
# 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:

View File

@@ -462,6 +462,45 @@ This is the \emph{document}.
\label{this-is-the-subtitle}}
\author{}
\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