Define `\internalreference` macro to redefine the style of references

This commit is contained in:
Takeshi KOMIYA 2016-02-25 22:07:18 +09:00
parent cea81e7a70
commit a682ab2e57
4 changed files with 21 additions and 15 deletions

View File

@ -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
----------

View File

@ -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.

View File

@ -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

View File

@ -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