LaTeX writer tests fail with Docutils HEAD
type:bug
### Describe the bug
@jfbu
Recent changes in Docutils make the LaTeX writer tests fail
(Docutils commit r10284 from 2026-01-07).
From Docutils RELEASE NOTES:
> LaTeX writer:
> - Do not write ``\label`` commands for section titles and other
> implicit targets if there is no matching reference in the document.
You may either
* change the Sphinx LaTeX writer to write all labels, or
* adapt the tests (my preference):
FAILED tests/test_builders/test_build_latex.py::test_latex_labels
expected:
\caption{labeled figure}\label{\detokenize{index:id1}}\label{\detokenize{index:figure2}}\label{\detokenize{index:figure1}}\end{figure}
result:
\caption{labeled figure}\label{\detokenize{index:id2}}\label{\detokenize{index:figure2}}\label{\detokenize{index:figure1}}\end{figure}
Solutions:
a) use special ID numbers only for Docutils 0.22
- if docutils.__version_info__[:2] < (0, 22):
+ if docutils.__version_info__[:2] == (0, 22):
figure_id, table_id = 'id1', 'id2'
else:
figure_id, table_id = 'id2', 'id3'
b) set "auto-id-prefix" to "%" for more stable IDs
FAILED tests/test_builders/test_build_latex.py::test_latex_raw_directive
expected:
\label{\detokenize{index:id1}}
standalone raw directive (LaTeX)
result:
standalone raw directive (LaTeX)
Solution:
change the source to contain a reference to the label or
remove the label from the assertion statement.
FAILED tests/test_builders/test_build_latex.py::test_writer
expected
\begin{sphinxfigure-in-table}
\centering
\capstart
\noindent\sphinxincludegraphics{{img}.png}
\sphinxfigcaption{figure in table}\label{\detokenize{markup:id8}}\end{sphinxfigure-in-table}\relax
result
\begin{sphinxfigure-in-table}
\centering
\capstart
\noindent\sphinxincludegraphics{{img}.png}
\sphinxfigcaption{figure in table}\label{\detokenize{markup:id7}}\end{sphinxfigure-in-table}\relax
Solution:
change the source to contain a reference to the label or
adapt ID numbers.
### How to Reproduce
See e.g. https://github.com/sphinx-doc/sphinx/actions/runs/24500180813/job/71604629131?pr=14400#logs
and https://github.com/sphinx-doc/sphinx/pull/14399
### Environment Information
```text
Docutils repository version (0.23.b.dev)
```
### Sphinx extensions
```python
```
### Additional context
_No response_
关闭于 2026-04-17 2 条评论