Skip to content

Commit 4c7fe10

Browse files
authored
LaTeX: fix mark-up when \DUrole is used with multiple classes (#12745)
1 parent 334e69f commit 4c7fe10

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Bugs fixed
6262
get passed to :program:`latexmk`. Let :option:`-Q <sphinx-build -Q>`
6363
(silent) apply as well to the PDF build phase.
6464
Patch by Jean-François B.
65+
* #12744: LaTeX: Classes injected by a custom interpreted text role now give
66+
rise to nested ``\DUrole``'s, rather than a single one with comma separated
67+
classes.
68+
Patch by Jean-François B.
6569
* #11970, #12551: singlehtml builder: make target URIs to be same-document
6670
references in the sense of :rfc:`RFC 3986, §4.4 <3986#section-4.4>`,
6771
e.g., ``index.html#foo`` becomes ``#foo``.

doc/latex.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,19 @@ Miscellany
18651865
Formerly, use of *fncychap* with other styles than ``Bjarne`` was
18661866
dysfunctional.
18671867

1868+
- The :dudir:`role` directive allows to mark inline text with class arguments.
1869+
This is handled in LaTeX output via the ``\DUrole`` dispatcher command `as
1870+
in Docutils <classarguments_>`_. Object signatures also use ``\DUrole`` for
1871+
some components, with one or two-letters class names as in HTML output.
1872+
1873+
.. versionchanged:: 8.1.0
1874+
When multiple classes are injected via a a custom role, the LaTeX output
1875+
uses nested ``\DUrole``'s as in the `Docutils documentation
1876+
<classarguments_>`_. Formerly it used a single ``\DUrole`` with comma
1877+
separated classes, making the LaTeX customization more arduous.
1878+
1879+
.. _classarguments: https://docutils.sourceforge.io/docs/user/latex.html#custom-interpreted-text-roles
1880+
18681881
.. _latexcontainer:
18691882

18701883
- Docutils :dudir:`container` directives are supported in LaTeX output: to

sphinx/writers/latex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,8 +2173,8 @@ def visit_inline(self, node: Element) -> None:
21732173
self.body.append(r'\sphinxaccelerator{')
21742174
self.context.append('}')
21752175
elif classes and not self.in_title:
2176-
self.body.append(r'\DUrole{%s}{' % ','.join(classes))
2177-
self.context.append('}')
2176+
self.body.append(r'\DUrole{' + r'}{\DUrole{'.join(classes) + '}{')
2177+
self.context.append('}' * len(classes))
21782178
else:
21792179
self.context.append('')
21802180

tests/roots/test-latex-table/expects/longtable_having_widths.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@
7070
\end{savenotes}
7171

7272
\sphinxAtStartPar
73-
See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std,std-ref}{this one}}}}.
73+
See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std}{\DUrole{std-ref}{this one}}}}}.

tests/roots/test-latex-table/expects/table_having_widths.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
\sphinxattableend\end{savenotes}
4444

4545
\sphinxAtStartPar
46-
See {\hyperref[\detokenize{tabular:mytabular}]{\sphinxcrossref{\DUrole{std,std-ref}{this}}}}, same as {\hyperref[\detokenize{tabular:namedtabular}]{\sphinxcrossref{namedtabular}}}.
46+
See {\hyperref[\detokenize{tabular:mytabular}]{\sphinxcrossref{\DUrole{std}{\DUrole{std-ref}{this}}}}}, same as {\hyperref[\detokenize{tabular:namedtabular}]{\sphinxcrossref{namedtabular}}}.

tests/test_builders/test_build_latex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ def test_reference_in_caption_and_codeblock_in_footnote(app):
10161016
assert (
10171017
'This is a reference to the code\\sphinxhyphen{}block in the footnote:\n'
10181018
'{\\hyperref[\\detokenize{index:codeblockinfootnote}]'
1019-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{I am in a footnote}}}}'
1019+
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}'
1020+
'{I am in a footnote}}}}}'
10201021
) in result
10211022
assert (
10221023
'&\n\\sphinxAtStartPar\nThis is one more footnote with some code in it %\n'

tests/test_directives/test_directive_code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,15 @@ def test_code_block_namedlink_latex(app):
333333
)
334334
link1 = (
335335
'\\hyperref[\\detokenize{caption:name-test-rb}]'
336-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
336+
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{Ruby}}}}'
337337
)
338338
label2 = (
339339
'\\def\\sphinxLiteralBlockLabel'
340340
'{\\label{\\detokenize{namedblocks:some-ruby-code}}}'
341341
)
342342
link2 = (
343343
'\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'
344-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}'
344+
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{the ruby code}}}}'
345345
)
346346
assert label1 in latex
347347
assert link1 in latex
@@ -472,15 +472,15 @@ def test_literalinclude_namedlink_latex(app):
472472
)
473473
link1 = (
474474
'\\hyperref[\\detokenize{caption:name-test-py}]'
475-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
475+
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{Python}}}}'
476476
)
477477
label2 = (
478478
'\\def\\sphinxLiteralBlockLabel'
479479
'{\\label{\\detokenize{namedblocks:some-python-code}}}'
480480
)
481481
link2 = (
482482
'\\hyperref[\\detokenize{namedblocks:some-python-code}]'
483-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}'
483+
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{the python code}}}}'
484484
)
485485
assert label1 in latex
486486
assert link1 in latex

0 commit comments

Comments
 (0)