Deprecate sphinx.writers.latex.ExtBabel.get_shorthandoff()

This partially reverts d17f3955a5
This commit is contained in:
jfbu 2018-06-06 18:55:49 +02:00
parent a32c358342
commit b41b1dac5c
4 changed files with 30 additions and 14 deletions

View File

@ -216,6 +216,11 @@ The following is a list of deprecated interface.
- 3.0
- N/A
* - ``sphinx.writers.latex.ExtBabel.get_shorthandoff()``
- 1.8
- 2.0
- N/A
* - ``sphinx.application.CONFIG_FILENAME``
- 1.8
- 3.0

View File

@ -2114,6 +2114,7 @@ information.
``'author'``
``'logo'``
``'makeindex'``
``'shorthandoff'``
.. confval:: latex_docclass

View File

@ -44,14 +44,17 @@ logger = logging.getLogger(__name__)
BEGIN_DOC = r'''
\begin{document}
\ifdefined\shorthandoff
\ifnum\catcode`\=\string=\active\shorthandoff{=}\fi
\ifnum\catcode`\"=\active\shorthandoff{"}\fi
\fi
%(shorthandoff)s
%(maketitle)s
%(tableofcontents)s
'''
SHORTHANDOFF = r'''
\ifdefined\shorthandoff
\ifnum\catcode`\=\string=\active\shorthandoff{=}\fi
\ifnum\catcode`\"=\active\shorthandoff{"}\fi
\fi
'''
MAX_CITATION_LABEL_LENGTH = 8
LATEXSECTIONNAMES = ["part", "chapter", "section", "subsection",
@ -104,6 +107,7 @@ DEFAULT_SETTINGS = {
'logo': '\\vbox{}',
'releasename': '',
'makeindex': '\\makeindex',
'shorthandoff': '',
'maketitle': '\\maketitle',
'tableofcontents': '\\sphinxtableofcontents',
'atendofbody': '',
@ -201,16 +205,6 @@ class LaTeXWriter(writers.Writer):
class ExtBabel(Babel):
cyrillic_languages = ('bulgarian', 'kazakh', 'mongolian', 'russian', 'ukrainian')
shorthands = {
'ngerman': '"',
'slovene': '"',
'portuges': '"',
'brazil': '"',
'spanish': '"',
'dutch': '"',
'polish': '"',
'italian': '"',
}
def __init__(self, language_code, use_polyglossia=False):
# type: (unicode, bool) -> None
@ -219,6 +213,12 @@ class ExtBabel(Babel):
self.supported = True
super(ExtBabel, self).__init__(language_code or '')
def get_shorthandoff(self):
# type: () -> unicode
warnings.warn('ExtBabel.get_shorthandoff() is deprecated.',
RemovedInSphinx20Warning)
return SHORTHANDOFF
def uses_cyrillic(self):
# type: () -> bool
return self.language in self.cyrillic_languages
@ -574,6 +574,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
# this branch is not taken for xelatex/lualatex if default settings
self.elements['multilingual'] = self.elements['babel']
if builder.config.language:
self.elements['shorthandoff'] = SHORTHANDOFF
# Times fonts don't work with Cyrillic languages
if self.babel.uses_cyrillic() \
@ -586,6 +587,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.elements['classoptions'] = ',dvipdfmx'
# disable babel which has not publishing quality in Japanese
self.elements['babel'] = ''
self.elements['shorthandoff'] = ''
self.elements['multilingual'] = ''
# disable fncychap in Japanese documents
self.elements['fncychap'] = ''

View File

@ -424,6 +424,7 @@ def test_babel_with_no_language_settings(app, status, warning):
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
@pytest.mark.sphinx(
@ -444,6 +445,7 @@ def test_babel_with_language_de(app, status, warning):
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
@pytest.mark.sphinx(
@ -465,6 +467,7 @@ def test_babel_with_language_ru(app, status, warning):
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
@pytest.mark.sphinx(
@ -485,6 +488,7 @@ def test_babel_with_language_tr(app, status, warning):
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
@pytest.mark.sphinx(
@ -504,6 +508,7 @@ def test_babel_with_language_ja(app, status, warning):
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
@pytest.mark.sphinx(
@ -524,6 +529,7 @@ def test_babel_with_unknown_language(app, status, warning):
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()
@ -547,6 +553,7 @@ def test_polyglossia_with_language_de(app, status, warning):
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
@pytest.mark.sphinx(
@ -568,6 +575,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
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
@pytest.mark.sphinx('latex')