mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Fix #2629. Add new config option `latex_keep_old_macro_names`
The cause of the issue was a clash about ``\titleref`` macro being already
defined in memoir class context. To avoid similar problems, this makes
the text styling macros
``\strong``, ``\code``, ``\bfcode``, ``\email``, ``\tablecontinued``,
``\titleref``, ``\menuselection``, ``\accelerator``, ``\crossref``,
``\termref``, ``\optional``,
also available with ``\sphinx`` prefix, with a conf.py boolean option to
let sphinx.sty only define ``\sphinx``-prefixed macros. As default value
is False, backwards compatibility is maintained.
On this occasion, some internal non-public macros have been renamed with
prefix ``\spx@``. The command
find . -name '*.sty' -exec grep -l \\\\spx@ {} \;
has been executed in TeXLive 2015 and 2016 installations to check no
package defines macros starting with ``\spx@``.
Some internal macros having public names (because they are written by
latex.py into the body of the latex document) have been renamed to have
``\sphinx`` prefix. The macros in sphinx.sty starting with \py@, or \DU,
or \PYG have not been modified. Similarly ``\release``, ``\version``,
``\releasename``, etc... have not been renamed.
This commit is contained in:
+17
-14
@@ -112,9 +112,9 @@ def test_writer(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||
|
||||
assert ('\\begin{figure-in-table}\n\\centering\n\\capstart\n'
|
||||
'\\includegraphics{{img}.png}\n'
|
||||
'\\figcaption{figure in table}\\label{markup:id7}\\end{figure-in-table}' in result)
|
||||
assert ('\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n'
|
||||
'\\includegraphics{{img}.png}\n\\sphinxfigcaption'
|
||||
'{figure in table}\\label{markup:id7}\\end{sphinxfigure-in-table}' in result)
|
||||
|
||||
assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
|
||||
'\\includegraphics{{rimg}.png}\n\\caption{figure with align option}'
|
||||
@@ -409,7 +409,7 @@ def test_footnote(app, status, warning):
|
||||
assert '\\footnote[1]{\sphinxAtStartFootnote%\nnumbered\n}' in result
|
||||
assert '\\footnote[2]{\sphinxAtStartFootnote%\nauto numbered\n}' in result
|
||||
assert '\\footnote[3]{\sphinxAtStartFootnote%\nnamed\n}' in result
|
||||
assert '{\\hyperref[footnote:bar]{\\crossref{{[}bar{]}}}}' in result
|
||||
assert '{\\hyperref[footnote:bar]{\\sphinxcrossref{{[}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
|
||||
@@ -428,7 +428,7 @@ 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]{\\crossref{{[}AuthorYear{]}}}}.}' in result)
|
||||
'{\\hyperref[index:authoryear]{\\sphinxcrossref{{[}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
|
||||
@@ -462,11 +462,12 @@ def test_latex_show_urls_is_inline(app, status, warning):
|
||||
'footnote 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]'
|
||||
'{\\crossref{The section with a reference to \\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\crossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference to '
|
||||
'\\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\sphinxcrossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
|
||||
'\\string-with\\string-a\\string-reference\\string-to]'
|
||||
'{\\crossref{The section with a reference to }}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference to }}}' in result)
|
||||
assert 'First footnote: \\footnote[2]{\sphinxAtStartFootnote%\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\sphinxAtStartFootnote%\nSecond\n}' in result
|
||||
assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result
|
||||
@@ -499,11 +500,12 @@ def test_latex_show_urls_is_footnote(app, status, warning):
|
||||
'footnote 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]'
|
||||
'{\\crossref{The section with a reference to \\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\crossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference '
|
||||
'to \\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\sphinxcrossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
|
||||
'\\string-with\\string-a\\string-reference\\string-to]'
|
||||
'{\\crossref{The section with a reference to }}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference to }}}' in result)
|
||||
assert 'First footnote: \\footnote[3]{\sphinxAtStartFootnote%\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\sphinxAtStartFootnote%\nSecond\n}' in result
|
||||
assert ('\\href{http://sphinx-doc.org/}{Sphinx}'
|
||||
@@ -542,11 +544,12 @@ def test_latex_show_urls_is_no(app, status, warning):
|
||||
'footnote 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]'
|
||||
'{\\crossref{The section with a reference to \\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\crossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference '
|
||||
'to \\phantomsection\\label{index:id1}'
|
||||
'{\\hyperref[index:authoryear]{\\sphinxcrossref{{[}AuthorYear{]}}}}}}}' in result)
|
||||
assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
|
||||
'\\string-with\\string-a\\string-reference\\string-to]'
|
||||
'{\\crossref{The section with a reference to }}}' in result)
|
||||
'{\\sphinxcrossref{The section with a reference to }}}' in result)
|
||||
assert 'First footnote: \\footnote[2]{\sphinxAtStartFootnote%\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\sphinxAtStartFootnote%\nSecond\n}' in result
|
||||
assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result
|
||||
|
||||
@@ -65,8 +65,8 @@ def test_code_block_caption_html(app, status, warning):
|
||||
def test_code_block_caption_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}'
|
||||
label = '\\def\\SphinxLiteralBlockLabel{\\label{caption:caption-test-rb}}'
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-rb}}'
|
||||
link = '\hyperref[caption:caption-test-rb]' \
|
||||
'{Listing \\ref{caption:caption-test-rb}}'
|
||||
assert caption in latex
|
||||
@@ -78,12 +78,12 @@ def test_code_block_caption_latex(app, status, warning):
|
||||
def test_code_block_namedlink_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-rb}}'
|
||||
label1 = '\def\sphinxLiteralBlockLabel{\label{caption:name-test-rb}}'
|
||||
link1 = '\\hyperref[caption:name\\string-test\\string-rb]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{Ruby}}'
|
||||
label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}'
|
||||
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
|
||||
label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}'
|
||||
link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\
|
||||
'{\\crossref{\\DUrole{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
|
||||
@@ -252,8 +252,8 @@ def test_literalinclude_caption_html(app, status, warning):
|
||||
def test_literalinclude_caption_latex(app, status, warning):
|
||||
app.builder.build('index')
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}'
|
||||
label = '\\def\\SphinxLiteralBlockLabel{\\label{caption:caption-test-py}}'
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-py}}'
|
||||
link = '\hyperref[caption:caption-test-py]' \
|
||||
'{Listing \\ref{caption:caption-test-py}}'
|
||||
assert caption in latex
|
||||
@@ -265,12 +265,12 @@ def test_literalinclude_caption_latex(app, status, warning):
|
||||
def test_literalinclude_namedlink_latex(app, status, warning):
|
||||
app.builder.build('index')
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-py}}'
|
||||
label1 = '\def\sphinxLiteralBlockLabel{\label{caption:name-test-py}}'
|
||||
link1 = '\\hyperref[caption:name\\string-test\\string-py]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{Python}}'
|
||||
label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}'
|
||||
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
|
||||
label2 = '\def\sphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}'
|
||||
link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\
|
||||
'{\\crossref{\\DUrole{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
|
||||
|
||||
@@ -93,32 +93,32 @@ def test_inline():
|
||||
# correct interpretation of code with whitespace
|
||||
_html = ('<p><code class="(samp )?docutils literal"><span class="pre">'
|
||||
'code</span> <span class="pre">sample</span></code></p>')
|
||||
yield verify_re, '``code sample``', _html, r'\\code{code sample}'
|
||||
yield verify_re, ':samp:`code sample`', _html, r'\\code{code sample}'
|
||||
yield verify_re, '``code sample``', _html, r'\\sphinxcode{code sample}'
|
||||
yield verify_re, ':samp:`code sample`', _html, r'\\sphinxcode{code sample}'
|
||||
|
||||
# interpolation of braces in samp and file roles (HTML only)
|
||||
yield (verify, ':samp:`a{b}c`',
|
||||
'<p><code class="samp docutils literal"><span class="pre">a</span>'
|
||||
'<em><span class="pre">b</span></em>'
|
||||
'<span class="pre">c</span></code></p>',
|
||||
'\\code{a\\emph{b}c}')
|
||||
'\\sphinxcode{a\\emph{b}c}')
|
||||
|
||||
# interpolation of arrows in menuselection
|
||||
yield (verify, ':menuselection:`a --> b`',
|
||||
u'<p><span class="menuselection">a \N{TRIANGULAR BULLET} b</span></p>',
|
||||
'\\menuselection{a \\(\\rightarrow\\) b}')
|
||||
'\\sphinxmenuselection{a \\(\\rightarrow\\) b}')
|
||||
|
||||
# interpolation of ampersands in guilabel/menuselection
|
||||
yield (verify, ':guilabel:`&Foo -&&- &Bar`',
|
||||
u'<p><span class="guilabel"><span class="accelerator">F</span>oo '
|
||||
'-&- <span class="accelerator">B</span>ar</span></p>',
|
||||
r'\menuselection{\accelerator{F}oo -\&- \accelerator{B}ar}')
|
||||
r'\sphinxmenuselection{\sphinxaccelerator{F}oo -\&- \sphinxaccelerator{B}ar}')
|
||||
|
||||
# non-interpolation of dashes in option role
|
||||
yield (verify_re, ':option:`--with-option`',
|
||||
'<p><code( class="xref std std-option docutils literal")?>'
|
||||
'<span class="pre">--with-option</span></code></p>$',
|
||||
r'\\code{-{-}with-option}$')
|
||||
r'\\sphinxcode{-{-}with-option}$')
|
||||
|
||||
# verify smarty-pants quotes
|
||||
yield verify, '"John"', '<p>“John”</p>', "``John''"
|
||||
@@ -126,7 +126,7 @@ def test_inline():
|
||||
yield (verify, '``"John"``',
|
||||
'<p><code class="docutils literal"><span class="pre">'
|
||||
'"John"</span></code></p>',
|
||||
'\\code{"John"}')
|
||||
'\\sphinxcode{"John"}')
|
||||
|
||||
# verify classes for inline roles
|
||||
yield (verify, ':manpage:`mp(1)`',
|
||||
|
||||
Reference in New Issue
Block a user