From a682ab2e5782001181435b28eba040292e7e98f0 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 25 Feb 2016 22:07:18 +0900 Subject: [PATCH] Define ``\internalreference`` macro to redefine the style of references --- CHANGES | 1 + sphinx/texinputs/sphinx.sty | 1 + sphinx/writers/latex.py | 2 +- tests/test_build_latex.py | 32 ++++++++++++++++++-------------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 85330d988..3fb85433a 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Features added * PR #2340: Math extension: support alignment of multiple equations for MathJAX. * #2338: Define ``\titlereference`` macro to redefine the style of `title-reference` roles. * Define ``\menuselection`` and ``\accelerator`` macros to redefine the style of `menuselection` roles. +* Define ``\internalreference`` macro to redefine the style of references Bugs fixed ---------- diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 48e90bf0c..30c48c6ca 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -149,6 +149,7 @@ \newcommand{\titlereference}[1]{\emph{#1}} \newcommand{\menuselection}[1]{\emph{#1}} \newcommand{\accelerator}[1]{\underline{#1}} +\newcommand{\internalreference}[1]{\emph{#1}} % Redefine the Verbatim environment to allow border and background colors. % The original environment is still used for verbatims within tables. diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 49d29dc76..2baf245af 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1606,7 +1606,7 @@ class LaTeXTranslator(nodes.NodeVisitor): # reference to a label id = uri[1:].replace('#', ':') self.body.append(self.hyperlink(id)) - self.body.append(r'\emph{') + self.body.append(r'\internalreference{') if len(node) and hasattr(node[0], 'attributes') and \ 'std-term' in node[0].get('classes', []): # don't add a pageref for glossary terms diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index b71751266..ea1468c2e 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -397,7 +397,7 @@ def test_footnote(app, status, warning): assert '\\footnote[1]{\nnumbered\n}' in result assert '\\footnote[2]{\nauto numbered\n}' in result assert '\\footnote[3]{\nnamed\n}' in result - assert '{\\hyperref[footnote:bar]{\\emph{{[}bar{]}}}}' in result + assert '{\\hyperref[footnote:bar]{\\internalreference{{[}bar{]}}}}' in result assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} ' in result assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} \ncite' in result assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} \ncite\n}' in result @@ -416,7 +416,8 @@ def test_reference_in_caption(app, status, warning): print(status.getvalue()) print(warning.getvalue()) assert ('\\caption{This is the figure caption with a reference to \\label{index:id2}' - '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}.}' in result) + '{\\hyperref[index:authoryear]{\\internalreference{{[}AuthorYear{]}}}}.}' + in result) assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result @@ -445,11 +446,12 @@ def test_latex_show_urls_is_inline(app, status, warning): assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section' '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]' - '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}' - '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result) + '{\\internalreference{The section with a reference to \\phantomsection' + '\\label{index:id1}{\\hyperref[index:authoryear]{\\internalreference' + '{{[}AuthorYear{]}}}}}}}' in result) assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section' - '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section ' - 'with a reference to }}}' in result) + '\\string-with\\string-a\\string-reference\\string-to]' + '{\\internalreference{The section with a reference to }}}' in result) assert 'First footnote: \\footnote[2]{\nFirst\n}' in result assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result @@ -480,11 +482,12 @@ def test_latex_show_urls_is_footnote(app, status, warning): assert 'Auto footnote number \\footnote[2]{\nfootnote in baz\n} in baz.rst' in result assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section' '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]' - '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}' - '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result) + '{\\internalreference{The section with a reference to \\phantomsection' + '\\label{index:id1}{\\hyperref[index:authoryear]{\\internalreference' + '{{[}AuthorYear{]}}}}}}}' in result) assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section' - '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section ' - 'with a reference to }}}' in result) + '\\string-with\\string-a\\string-reference\\string-to]{\\internalreference' + '{The section with a reference to }}}' in result) assert 'First footnote: \\footnote[3]{\nFirst\n}' in result assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert ('\\href{http://sphinx-doc.org/}{Sphinx}' @@ -517,11 +520,12 @@ def test_latex_show_urls_is_no(app, status, warning): assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section' '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]' - '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}' - '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result) + '{\\internalreference{The section with a reference to \\phantomsection' + '\\label{index:id1}{\\hyperref[index:authoryear]{\\internalreference' + '{{[}AuthorYear{]}}}}}}}' in result) assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section' - '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section ' - 'with a reference to }}}' in result) + '\\string-with\\string-a\\string-reference\\string-to]{\\internalreference' + '{The section with a reference to }}}' in result) assert 'First footnote: \\footnote[2]{\nFirst\n}' in result assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result