summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--doc/extdev/deprecated.rst25
-rw-r--r--sphinx/builders/latex/__init__.py51
-rw-r--r--sphinx/writers/latex.py8
4 files changed, 80 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 112277742..5f962d2d7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,11 @@ Deprecated
* ``sphinx.pycode.ModuleAnalyzer.encoding``
* ``sphinx.util.detect_encoding()``
* ``sphinx.util.get_module_source()``
+* ``sphinx.writers.latex.LaTeXTranslator.settings.author``
+* ``sphinx.writers.latex.LaTeXTranslator.settings.contentsname``
+* ``sphinx.writers.latex.LaTeXTranslator.settings.docclass``
+* ``sphinx.writers.latex.LaTeXTranslator.settings.docname``
+* ``sphinx.writers.latex.LaTeXTranslator.settings.title``
Features added
--------------
diff --git a/doc/extdev/deprecated.rst b/doc/extdev/deprecated.rst
index 58638f999..e2f8b68c6 100644
--- a/doc/extdev/deprecated.rst
+++ b/doc/extdev/deprecated.rst
@@ -66,6 +66,31 @@ The following is a list of deprecated interfaces.
- 4.0
- ``tokenize.detect_encoding()``
+ * - ``sphinx.writers.latex.LaTeXTranslator.settings.author``
+ - 2.4
+ - 4.0
+ - N/A
+
+ * - ``sphinx.writers.latex.LaTeXTranslator.settings.contentsname``
+ - 2.4
+ - 4.0
+ - ``document['contentsname']``
+
+ * - ``sphinx.writers.latex.LaTeXTranslator.settings.docclass``
+ - 2.4
+ - 4.0
+ - ``document['docclass']``
+
+ * - ``sphinx.writers.latex.LaTeXTranslator.settings.docname``
+ - 2.4
+ - 4.0
+ - N/A
+
+ * - ``sphinx.writers.latex.LaTeXTranslator.settings.title``
+ - 2.4
+ - 4.0
+ - N/A
+
* - ``sphinx.builders.gettext.POHEADER``
- 2.3
- 4.0
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index 77f703ffe..5fe3cb9af 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -221,6 +221,7 @@ class LaTeXBuilder(Builder):
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values() # type: Any
+ patch_settings(docsettings)
self.init_document_data()
self.write_stylesheet()
@@ -243,16 +244,18 @@ class LaTeXBuilder(Builder):
doctree = self.assemble_doctree(
docname, toctree_only,
appendices=(self.config.latex_appendices if docclass != 'howto' else []))
+ doctree['docclass'] = docclass
+ doctree['contentsname'] = self.get_contentsname(docname)
doctree['tocdepth'] = tocdepth
self.post_process_images(doctree)
self.update_doc_context(title, author)
with progress_message(__("writing")):
- docsettings.author = author
- docsettings.title = title
- docsettings.contentsname = self.get_contentsname(docname)
- docsettings.docname = docname
- docsettings.docclass = docclass
+ docsettings._author = author
+ docsettings._title = title
+ docsettings._contentsname = doctree['contentsname']
+ docsettings._docname = docname
+ docsettings._docclass = docclass
doctree.settings = docsettings
docwriter.write(doctree, destination)
@@ -400,6 +403,44 @@ class LaTeXBuilder(Builder):
copy_asset_file(filename, self.outdir, context=context, renderer=LaTeXRenderer())
+def patch_settings(settings: Any):
+ """Make settings object to show deprecation messages."""
+
+ class Values(type(settings)): # type: ignore
+ @property
+ def author(self):
+ warnings.warn('settings.author is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
+ return self._author
+
+ @property
+ def title(self):
+ warnings.warn('settings.title is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
+ return self._title
+
+ @property
+ def contentsname(self):
+ warnings.warn('settings.contentsname is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
+ return self._contentsname
+
+ @property
+ def docname(self):
+ warnings.warn('settings.docname is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
+ return self._docname
+
+ @property
+ def docclass(self):
+ warnings.warn('settings.docclass is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
+ return self._docclass
+
+ # dynamic subclassing
+ settings.__class__ = Values
+
+
def validate_config_values(app: Sphinx, config: Config) -> None:
for key in list(config.latex_elements):
if key not in DEFAULT_SETTINGS:
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 3eee3eb02..89ee63e8f 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -322,12 +322,12 @@ class LaTeXTranslator(SphinxTranslator):
self.elements = self.builder.context.copy()
# but some have other interface in config file
- self.elements['wrapperclass'] = self.format_docclass(self.settings.docclass)
+ self.elements['wrapperclass'] = self.format_docclass(document.get('docclass'))
# we assume LaTeX class provides \chapter command except in case
# of non-Japanese 'howto' case
self.sectionnames = LATEXSECTIONNAMES[:]
- if self.settings.docclass == 'howto':
+ if document.get('docclass') == 'howto':
docclass = self.config.latex_docclass.get('howto', 'article')
if docclass[0] == 'j': # Japanese class...
pass
@@ -429,7 +429,7 @@ class LaTeXTranslator(SphinxTranslator):
# tocdepth = 1: show parts, chapters and sections
# tocdepth = 2: show parts, chapters, sections and subsections
# ...
- tocdepth = self.document['tocdepth'] + self.top_sectionlevel - 2
+ tocdepth = self.document.get('tocdepth', 999) + self.top_sectionlevel - 2
if len(self.sectionnames) < len(LATEXSECTIONNAMES) and \
self.top_sectionlevel > 0:
tocdepth += 1 # because top_sectionlevel is shifted by -1
@@ -447,7 +447,7 @@ class LaTeXTranslator(SphinxTranslator):
self.elements['secnumdepth'] = '\\setcounter{secnumdepth}{%d}' %\
minsecnumdepth
- contentsname = self.settings.contentsname
+ contentsname = document.get('contentsname')
if contentsname:
self.elements['contentsname'] = self.babel_renewcommand('\\contentsname',
contentsname)