Skip to content

Commit e2f66ce

Browse files
committed
Update CHANGES for PR #11333
1 parent 6157651 commit e2f66ce

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Bugs fixed
7575

7676
* #11079: LaTeX: figures with align attribute may disappear and strangely impact
7777
following lists
78+
* #11093: LaTeX: fix "multiply-defined references" PDF build warnings when one or
79+
more reST labels directly precede an :rst:dir:`py:module` or :rst:dir:`automodule`
80+
directive. Patch by Bénédikt Tran (picnixz)
7881
* #11110: LaTeX: Figures go missing from latex pdf if their files have the same
7982
base name and they use a post transform. Patch by aaron-cooper
8083
* LaTeX: fix potential color leak from shadow to border of rounded boxes, if

sphinx/writers/latex.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1504,14 +1504,14 @@ def add_target(id: str) -> None:
15041504
if node.get('ismod', False):
15051505
# Detect if the previous nodes are label targets. If so, remove
15061506
# the refid thereof from node['ids'] to avoid duplicated ids.
1507-
def has_dup_label(sib: Element | None) -> bool:
1507+
def has_dup_label(sib: Node | None) -> bool:
15081508
return isinstance(sib, nodes.target) and sib.get('refid') in node['ids']
15091509

1510-
prev: Element | None = get_prev_node(node)
1510+
prev = get_prev_node(node)
15111511
if has_dup_label(prev):
15121512
ids = node['ids'][:] # copy to avoid side-effects
15131513
while has_dup_label(prev):
1514-
ids.remove(prev['refid'])
1514+
ids.remove(prev['refid']) # type: ignore
15151515
prev = get_prev_node(prev)
15161516
else:
15171517
ids = iter(node['ids']) # read-only iterator

tests/test_build_latex.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1720,18 +1720,21 @@ def count_label(name):
17201720
return content.count(text)
17211721

17221722
pattern = r'\\phantomsection\\label\{\\detokenize\{index:label-(?:auto-)?\d+[a-z]*}}'
1723-
expect_labels = {match.group() for match in re.finditer(pattern, content)}
1724-
result_labels = set()
1723+
# labels found in the TeX output
1724+
output_labels = frozenset(match.group() for match in re.finditer(pattern, content))
1725+
# labels that have been tested and occurring exactly once in the output
1726+
tested_labels = set()
17251727

17261728
# iterate over the (explicit) labels in the corresponding index.rst
1727-
for rst_label_name in {
1729+
for rst_label_name in [
17281730
'label_1a', 'label_1b', 'label_2', 'label_3',
17291731
'label_auto_1a', 'label_auto_1b', 'label_auto_2', 'label_auto_3',
1730-
}:
1732+
]:
17311733
tex_label_name = 'index:' + rst_label_name.replace('_', '-')
17321734
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name
17331735
assert content.count(tex_label_code) == 1, f'duplicated label: {tex_label_name!r}'
1734-
result_labels.add(tex_label_code)
1736+
tested_labels.add(tex_label_code)
17351737

1736-
# sort the labels for a better visual diff, if any
1737-
assert sorted(result_labels) == sorted(expect_labels)
1738+
# ensure that we did not forget any label to check
1739+
# and if so, report them nicely in case of failure
1740+
assert sorted(tested_labels) == sorted(output_labels)

0 commit comments

Comments
 (0)