diff options
| author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2023-04-17 12:07:32 +0200 |
|---|---|---|
| committer | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2023-04-17 12:07:32 +0200 |
| commit | 61576516d4ed6c4e10d38f959e8625201abcc7d3 (patch) | |
| tree | 024b9747d6d0d43ace873adc34f6f230427a0e32 /sphinx | |
| parent | 5a6b2b16b6b588cdd4dab1b43b7873153da10baa (diff) | |
| download | sphinx-git-61576516d4ed6c4e10d38f959e8625201abcc7d3.tar.gz | |
Fix duplicated labels in TeX output (#11093)
Diffstat (limited to 'sphinx')
| -rw-r--r-- | sphinx/writers/latex.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 215fd4c76..684164a1f 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1499,7 +1499,26 @@ class LaTeXTranslator(SphinxTranslator): pass else: add_target(node['refid']) - for id in node['ids']: + # Temporary fix for https://github.com/sphinx-doc/sphinx/issues/11093 + # TODO: investigate if a more elegant solution exists (see comments of #11093) + 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: + return isinstance(sib, nodes.target) and sib.get('refid') in node['ids'] + + prev: Element | None = 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']) + prev = get_prev_node(prev) + else: + ids = iter(node['ids']) # read-only iterator + else: + ids = iter(node['ids']) # read-only iterator + + for id in ids: add_target(id) def depart_target(self, node: Element) -> None: |
