diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 52d8e268c..04b6f1564 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -2117,7 +2117,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append(r'\sphinxaccelerator{') self.context.append('}') elif classes and not self.in_title: - self.body.append(r'\DUrole{%s}{' % ','.join(classes)) + self.body.append(r'\DUrole{\detokenize{%s}}{' % ','.join(classes)) self.context.append('}') else: self.context.append('') diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 6a13ea60a..8e05fae70 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -461,8 +461,8 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning): '\sphinxAtStartFootnote\n' 'Foot note in longtable\n%\n\\end{footnotetext}' in result) assert ('This is a reference to the code-block in the footnote:\n' - '{\hyperref[index:codeblockinfootnote]{\\sphinxcrossref{\\DUrole' - '{std,std-ref}{I am in a footnote}}}}') in result + '{\\hyperref[index:codeblockinfootnote]{\\sphinxcrossref{\\DUrole' + '{\\detokenize{std,std-ref}}{I am in a footnote}}}}') in result assert ('&\nThis is one more footnote with some code in it ' '\\sphinxfootnotemark[10].\n\\\\') in result assert '\\begin{sphinxVerbatim}[commandchars=\\\\\\{\\}]' in result diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index a29db6b90..d6e8d52ca 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -80,10 +80,10 @@ def test_code_block_namedlink_latex(app, status, warning): latex = (app.outdir / 'Python.tex').text(encoding='utf-8') label1 = '\def\sphinxLiteralBlockLabel{\label{caption:name-test-rb}}' link1 = '\\hyperref[caption:name\\string-test\\string-rb]'\ - '{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}' + '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{Ruby}}' label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}' link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\ - '{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}' + '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{the ruby code}}}' assert label1 in latex assert link1 in latex assert label2 in latex @@ -275,10 +275,10 @@ def test_literalinclude_namedlink_latex(app, status, warning): latex = (app.outdir / 'Python.tex').text(encoding='utf-8') label1 = '\def\sphinxLiteralBlockLabel{\label{caption:name-test-py}}' link1 = '\\hyperref[caption:name\\string-test\\string-py]'\ - '{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}' + '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{Python}}' label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}' link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\ - '{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}' + '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{the python code}}}' assert label1 in latex assert link1 in latex assert label2 in latex