From e9c472c8513e6edce83b0ec9d36c9fb1f9260dc3 Mon Sep 17 00:00:00 2001 From: jfbu Date: Fri, 9 Dec 2016 09:45:44 +0100 Subject: [PATCH] Fix #3207: latex issue with references from inside parsed-literal This reverts commit e25cce1a64f0a314272431debeb7d0c89908a4c5 in order to move ``\detokenize`` insertion away from latex writer to inside the ``\DUrole`` definition in sphinx.sty. --- sphinx/texinputs/sphinx.sty | 8 ++++---- sphinx/writers/latex.py | 2 +- tests/test_build_latex.py | 4 ++-- tests/test_directive_code.py | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 5037fbd92..c250f536f 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -946,11 +946,11 @@ % inline markup (custom roles) % \DUrole{#1}{#2} tries \DUrole#1{#2} \providecommand*{\DUrole}[2]{% - \ifcsname DUrole#1\endcsname - \csname DUrole#1\endcsname{#2}% + \ifcsname DUrole\detokenize{#1}\endcsname + \csname DUrole\detokenize{#1}\endcsname{#2}% \else% backwards compatibility: try \docutilsrole#1{#2} - \ifcsname docutilsrole#1\endcsname - \csname docutilsrole#1\endcsname{#2}% + \ifcsname docutilsrole\detokenize{#1}\endcsname + \csname docutilsrole\detokenize{#1}\endcsname{#2}% \else #2% \fi diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 04b6f1564..52d8e268c 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{\detokenize{%s}}{' % ','.join(classes)) + self.body.append(r'\DUrole{%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 8e05fae70..6a13ea60a 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' - '{\\detokenize{std,std-ref}}{I am in a footnote}}}}') in result + '{\hyperref[index:codeblockinfootnote]{\\sphinxcrossref{\\DUrole' + '{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 d6e8d52ca..a29db6b90 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{\\detokenize{std,std-ref}}{Ruby}}' + '{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}' label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}' link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\ - '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{the ruby code}}}' + '{\\sphinxcrossref{\\DUrole{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{\\detokenize{std,std-ref}}{Python}}' + '{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}' label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}' link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\ - '{\\sphinxcrossref{\\DUrole{\\detokenize{std,std-ref}}{the python code}}}' + '{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}' assert label1 in latex assert link1 in latex assert label2 in latex