LaTeX: fix mark-up when \DUrole is used with multiple classes (#12745)

This commit is contained in:
Jean-François B. 2024-08-17 20:33:15 +02:00 committed by GitHub
parent 334e69fbb4
commit 4c7fe10a4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 9 deletions

View File

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

View File

@ -1865,6 +1865,19 @@ Miscellany
Formerly, use of *fncychap* with other styles than ``Bjarne`` was Formerly, use of *fncychap* with other styles than ``Bjarne`` was
dysfunctional. dysfunctional.
- The :dudir:`role` directive allows to mark inline text with class arguments.
This is handled in LaTeX output via the ``\DUrole`` dispatcher command `as
in Docutils <classarguments_>`_. Object signatures also use ``\DUrole`` for
some components, with one or two-letters class names as in HTML output.
.. versionchanged:: 8.1.0
When multiple classes are injected via a a custom role, the LaTeX output
uses nested ``\DUrole``'s as in the `Docutils documentation
<classarguments_>`_. Formerly it used a single ``\DUrole`` with comma
separated classes, making the LaTeX customization more arduous.
.. _classarguments: https://docutils.sourceforge.io/docs/user/latex.html#custom-interpreted-text-roles
.. _latexcontainer: .. _latexcontainer:
- Docutils :dudir:`container` directives are supported in LaTeX output: to - Docutils :dudir:`container` directives are supported in LaTeX output: to

View File

@ -2173,8 +2173,8 @@ class LaTeXTranslator(SphinxTranslator):
self.body.append(r'\sphinxaccelerator{') self.body.append(r'\sphinxaccelerator{')
self.context.append('}') self.context.append('}')
elif classes and not self.in_title: elif classes and not self.in_title:
self.body.append(r'\DUrole{%s}{' % ','.join(classes)) self.body.append(r'\DUrole{' + r'}{\DUrole{'.join(classes) + '}{')
self.context.append('}') self.context.append('}' * len(classes))
else: else:
self.context.append('') self.context.append('')

View File

@ -70,4 +70,4 @@ cell3\sphinxhyphen{}2
\end{savenotes} \end{savenotes}
\sphinxAtStartPar \sphinxAtStartPar
See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std,std-ref}{this one}}}}. See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std}{\DUrole{std-ref}{this one}}}}}.

View File

@ -43,4 +43,4 @@ cell3\sphinxhyphen{}2
\sphinxattableend\end{savenotes} \sphinxattableend\end{savenotes}
\sphinxAtStartPar \sphinxAtStartPar
See {\hyperref[\detokenize{tabular:mytabular}]{\sphinxcrossref{\DUrole{std,std-ref}{this}}}}, same as {\hyperref[\detokenize{tabular:namedtabular}]{\sphinxcrossref{namedtabular}}}. See {\hyperref[\detokenize{tabular:mytabular}]{\sphinxcrossref{\DUrole{std}{\DUrole{std-ref}{this}}}}}, same as {\hyperref[\detokenize{tabular:namedtabular}]{\sphinxcrossref{namedtabular}}}.

View File

@ -1016,7 +1016,8 @@ def test_reference_in_caption_and_codeblock_in_footnote(app):
assert ( assert (
'This is a reference to the code\\sphinxhyphen{}block in the footnote:\n' 'This is a reference to the code\\sphinxhyphen{}block in the footnote:\n'
'{\\hyperref[\\detokenize{index:codeblockinfootnote}]' '{\\hyperref[\\detokenize{index:codeblockinfootnote}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{I am in a footnote}}}}' '{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}'
'{I am in a footnote}}}}}'
) in result ) in result
assert ( assert (
'&\n\\sphinxAtStartPar\nThis is one more footnote with some code in it %\n' '&\n\\sphinxAtStartPar\nThis is one more footnote with some code in it %\n'

View File

@ -333,7 +333,7 @@ def test_code_block_namedlink_latex(app):
) )
link1 = ( link1 = (
'\\hyperref[\\detokenize{caption:name-test-rb}]' '\\hyperref[\\detokenize{caption:name-test-rb}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}' '{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{Ruby}}}}'
) )
label2 = ( label2 = (
'\\def\\sphinxLiteralBlockLabel' '\\def\\sphinxLiteralBlockLabel'
@ -341,7 +341,7 @@ def test_code_block_namedlink_latex(app):
) )
link2 = ( link2 = (
'\\hyperref[\\detokenize{namedblocks:some-ruby-code}]' '\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}' '{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{the ruby code}}}}'
) )
assert label1 in latex assert label1 in latex
assert link1 in latex assert link1 in latex
@ -472,7 +472,7 @@ def test_literalinclude_namedlink_latex(app):
) )
link1 = ( link1 = (
'\\hyperref[\\detokenize{caption:name-test-py}]' '\\hyperref[\\detokenize{caption:name-test-py}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}' '{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{Python}}}}'
) )
label2 = ( label2 = (
'\\def\\sphinxLiteralBlockLabel' '\\def\\sphinxLiteralBlockLabel'
@ -480,7 +480,7 @@ def test_literalinclude_namedlink_latex(app):
) )
link2 = ( link2 = (
'\\hyperref[\\detokenize{namedblocks:some-python-code}]' '\\hyperref[\\detokenize{namedblocks:some-python-code}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}' '{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}{the python code}}}}'
) )
assert label1 in latex assert label1 in latex
assert link1 in latex assert link1 in latex