summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2023-04-17 12:13:29 +0200
committerBénédikt Tran <10796600+picnixz@users.noreply.github.com>2023-04-18 12:13:20 +0200
commite2f66cea4997b6d8c588d3509adb68d4e9108ee6 (patch)
tree63b1440755e5455631396478dff69346e8e00f9b
parent61576516d4ed6c4e10d38f959e8625201abcc7d3 (diff)
downloadsphinx-git-e2f66cea4997b6d8c588d3509adb68d4e9108ee6.tar.gz
Update CHANGES for PR #11333
-rw-r--r--CHANGES3
-rw-r--r--sphinx/writers/latex.py6
-rw-r--r--tests/test_build_latex.py17
3 files changed, 16 insertions, 10 deletions
diff --git a/CHANGES b/CHANGES
index e70998055..da414f1e2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -75,6 +75,9 @@ Bugs fixed
* #11079: LaTeX: figures with align attribute may disappear and strangely impact
following lists
+* #11093: LaTeX: fix "multiply-defined references" PDF build warnings when one or
+ more reST labels directly precede an :rst:dir:`py:module` or :rst:dir:`automodule`
+ directive. Patch by Bénédikt Tran (picnixz)
* #11110: LaTeX: Figures go missing from latex pdf if their files have the same
base name and they use a post transform. Patch by aaron-cooper
* LaTeX: fix potential color leak from shadow to border of rounded boxes, if
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 684164a1f..efb847353 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -1504,14 +1504,14 @@ class LaTeXTranslator(SphinxTranslator):
if node.get('ismod', False):
# Detect if the previous nodes are label targets. If so, remove
# the refid thereof from node['ids'] to avoid duplicated ids.
- def has_dup_label(sib: Element | None) -> bool:
+ def has_dup_label(sib: Node | None) -> bool:
return isinstance(sib, nodes.target) and sib.get('refid') in node['ids']
- prev: Element | None = get_prev_node(node)
+ prev = get_prev_node(node)
if has_dup_label(prev):
ids = node['ids'][:] # copy to avoid side-effects
while has_dup_label(prev):
- ids.remove(prev['refid'])
+ ids.remove(prev['refid']) # type: ignore
prev = get_prev_node(prev)
else:
ids = iter(node['ids']) # read-only iterator
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index de45f5f0c..faf1a47b7 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -1720,18 +1720,21 @@ def test_duplicated_labels_before_module(app, status, warning):
return content.count(text)
pattern = r'\\phantomsection\\label\{\\detokenize\{index:label-(?:auto-)?\d+[a-z]*}}'
- expect_labels = {match.group() for match in re.finditer(pattern, content)}
- result_labels = set()
+ # labels found in the TeX output
+ output_labels = frozenset(match.group() for match in re.finditer(pattern, content))
+ # labels that have been tested and occurring exactly once in the output
+ tested_labels = set()
# iterate over the (explicit) labels in the corresponding index.rst
- for rst_label_name in {
+ for rst_label_name in [
'label_1a', 'label_1b', 'label_2', 'label_3',
'label_auto_1a', 'label_auto_1b', 'label_auto_2', 'label_auto_3',
- }:
+ ]:
tex_label_name = 'index:' + rst_label_name.replace('_', '-')
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name
assert content.count(tex_label_code) == 1, f'duplicated label: {tex_label_name!r}'
- result_labels.add(tex_label_code)
+ tested_labels.add(tex_label_code)
- # sort the labels for a better visual diff, if any
- assert sorted(result_labels) == sorted(expect_labels)
+ # ensure that we did not forget any label to check
+ # and if so, report them nicely in case of failure
+ assert sorted(tested_labels) == sorted(output_labels)