latex: Move \pageautorefname to sphinxmessages.sty

This commit is contained in:
Takeshi KOMIYA 2018-08-10 22:19:55 +09:00
parent 8b687ac304
commit dcc4ac55bb
6 changed files with 65 additions and 26 deletions

View File

@ -26,7 +26,11 @@ Deprecated
* ``sphinx.testing.util.remove_unicode_literal()``
* ``sphinx.util.get_matching_docs()`` is deprecated
* ``sphinx.util.osutil.walk()``
* ``translatablestrings`` variable for LaTeX template
* ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
* template variables for LaTeX template
- ``pageautorefname``
- ``translatablestrings``
For more details, see `deprecation APIs list
<http://www.sphinx-doc.org/en/master/extdev/index.html#deprecated-apis>`_

View File

@ -158,6 +158,11 @@ The following is a list of deprecated interfaces.
- 3.0
- N/A
* - ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
- 2.0
- 4.0
- N/A
* - :rst:dir:`highlightlang`
- 1.8
- 4.0

View File

@ -37,7 +37,6 @@
<%= contentsname %>
<%= numfig_format %>
\input{sphinxmessages.sty}
<%= pageautorefname %>
<%= tocdepth %>
<%= secnumdepth %>
<%= preamble %>

View File

@ -8,3 +8,4 @@
\renewcommand{\sphinxnonalphabeticalgroupname}{<%= _('Non-alphabetical') | e %>}
\renewcommand{\sphinxsymbolsname}{<%= _('Symbols') | e %>}
\renewcommand{\sphinxnumbersname}{<%= _('Numbers') | e %>}
\def\pageautorefname{<%= _('page') | e %>}

View File

@ -24,7 +24,7 @@ from six import text_type
from sphinx import addnodes
from sphinx import highlighting
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
from sphinx.errors import SphinxError
from sphinx.locale import admonitionlabels, _, __
from sphinx.util import split_into, logging
@ -114,7 +114,6 @@ DEFAULT_SETTINGS = {
'figure_align': 'htbp',
'tocdepth': '',
'secnumdepth': '',
'pageautorefname': '',
} # type: Dict[unicode, unicode]
ADDITIONAL_SETTINGS = {
@ -627,8 +626,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
if self.elements['extraclassoptions']:
self.elements['classoptions'] += ',' + \
self.elements['extraclassoptions']
self.elements['pageautorefname'] = \
self.babel_defmacro('\\pageautorefname', self.encode(_('page')))
self.elements['numfig_format'] = self.generate_numfig_format(builder)
self.highlighter = highlighting.PygmentsBridge('latex', builder.config.pygments_style)
@ -730,17 +727,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
return ('%s\\renewcommand{%s}{%s}%s\n' % (prefix, command, definition, suffix))
def babel_defmacro(self, name, definition):
# type: (unicode, unicode) -> unicode
if self.elements['babel']:
prefix = '\\addto\\extras%s{' % self.babel.get_language()
suffix = '}'
else: # babel is disabled (mainly for Japanese environment)
prefix = ''
suffix = ''
return ('%s\\def%s{%s}%s\n' % (prefix, name, definition, suffix))
def generate_numfig_format(self, builder):
# type: (Builder) -> unicode
ret = [] # type: List[unicode]
@ -2564,6 +2550,19 @@ class LaTeXTranslator(nodes.NodeVisitor):
msg = __("Unknown configure key: latex_elements[%r] is ignored.")
logger.warning(msg % key)
def babel_defmacro(self, name, definition):
# type: (unicode, unicode) -> unicode
warnings.warn('babel_defmacro() is deprecated.',
RemovedInSphinx40Warning)
if self.elements['babel']:
prefix = '\\addto\\extras%s{' % self.babel.get_language()
suffix = '}'
else: # babel is disabled (mainly for Japanese environment)
prefix = ''
suffix = ''
return ('%s\\def%s{%s}%s\n' % (prefix, name, definition, suffix))
# Import old modules here for compatibility
# They should be imported after `LaTeXTranslator` to avoid recursive import.

View File

@ -420,9 +420,13 @@ def test_babel_with_no_language_settings(app, status, warning):
in result)
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -441,9 +445,13 @@ def test_babel_with_language_de(app, status, warning):
in result)
assert '\\addto\\captionsngerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsngerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\extrasngerman{\\def\\pageautorefname{Seite}}\n' in result
assert '\\shorthandoff{"}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -462,10 +470,13 @@ def test_babel_with_language_ru(app, status, warning):
in result)
assert '\\addto\\captionsrussian{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsrussian{\\renewcommand{\\tablename}{Table.}}\n' in result
assert (u'\\addto\\extrasrussian{\\def\\pageautorefname'
u'{\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430}}\n' in result)
assert '\\shorthandoff{"}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{страница}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -484,9 +495,13 @@ def test_babel_with_language_tr(app, status, warning):
in result)
assert '\\addto\\captionsturkish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsturkish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\extrasturkish{\\def\\pageautorefname{sayfa}}\n' in result
assert '\\shorthandoff{=}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{sayfa}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -504,9 +519,13 @@ def test_babel_with_language_ja(app, status, warning):
assert '\\renewcommand{\\contentsname}{Table of content}\n' in result
assert '\\renewcommand{\\figurename}{Fig.}\n' in result
assert '\\renewcommand{\\tablename}{Table.}\n' in result
assert u'\\def\\pageautorefname{ページ}\n' in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{ページ}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -525,11 +544,15 @@ def test_babel_with_unknown_language(app, status, warning):
in result)
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result
assert '\\shorthandoff' in result
assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue()
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -549,9 +572,13 @@ def test_polyglossia_with_language_de(app, status, warning):
in result)
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\def\\pageautorefname{Seite}\n' in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-babel',
@ -571,9 +598,13 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
in result)
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\def\\pageautorefname{page}\n' in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
@pytest.mark.sphinx('latex')
def test_footnote(app, status, warning):