mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
LaTeX: Add :confval:latex_theme_options
to override theme options
This commit is contained in:
parent
66744c656e
commit
05aff200b1
1
CHANGES
1
CHANGES
@ -20,6 +20,7 @@ Features added
|
|||||||
|
|
||||||
* LaTeX: Make the ``toplevel_sectioning`` setting optional in LaTeX theme
|
* LaTeX: Make the ``toplevel_sectioning`` setting optional in LaTeX theme
|
||||||
* LaTeX: Allow to override papersize and pointsize from LaTeX themes
|
* LaTeX: Allow to override papersize and pointsize from LaTeX themes
|
||||||
|
* LaTeX: Add :confval:`latex_theme_options` to override theme options
|
||||||
* #7410: Allow to suppress "circular toctree references detected" warnings using
|
* #7410: Allow to suppress "circular toctree references detected" warnings using
|
||||||
:confval:`suppress_warnings`
|
:confval:`suppress_warnings`
|
||||||
* C, added scope control directives, :rst:dir:`c:namespace`,
|
* C, added scope control directives, :rst:dir:`c:namespace`,
|
||||||
|
@ -2119,6 +2119,13 @@ These options influence LaTeX output.
|
|||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
|
|
||||||
|
.. confval:: latex_theme_options
|
||||||
|
|
||||||
|
A dictionary of options that influence the look and feel of the selected
|
||||||
|
theme.
|
||||||
|
|
||||||
|
.. versionadded:: 3.1
|
||||||
|
|
||||||
.. confval:: latex_theme_path
|
.. confval:: latex_theme_path
|
||||||
|
|
||||||
A list of paths that contain custom LaTeX themes as subdirectories. Relative
|
A list of paths that contain custom LaTeX themes as subdirectories. Relative
|
||||||
|
@ -493,6 +493,14 @@ def validate_config_values(app: Sphinx, config: Config) -> None:
|
|||||||
config.latex_elements.pop(key)
|
config.latex_elements.pop(key)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_latex_theme_options(app: Sphinx, config: Config) -> None:
|
||||||
|
for key in list(config.latex_theme_options):
|
||||||
|
if key not in Theme.UPDATABLE_KEYS:
|
||||||
|
msg = __("Unknown theme option: latex_theme_options[%r], ignored.")
|
||||||
|
logger.warning(msg % (key,))
|
||||||
|
config.latex_theme_options.pop(key)
|
||||||
|
|
||||||
|
|
||||||
def default_latex_engine(config: Config) -> str:
|
def default_latex_engine(config: Config) -> str:
|
||||||
""" Better default latex_engine settings for specific languages. """
|
""" Better default latex_engine settings for specific languages. """
|
||||||
if config.language == 'ja':
|
if config.language == 'ja':
|
||||||
@ -539,6 +547,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
|
|
||||||
app.add_builder(LaTeXBuilder)
|
app.add_builder(LaTeXBuilder)
|
||||||
app.connect('config-inited', validate_config_values, priority=800)
|
app.connect('config-inited', validate_config_values, priority=800)
|
||||||
|
app.connect('config-inited', validate_latex_theme_options, priority=800)
|
||||||
|
|
||||||
app.add_config_value('latex_engine', default_latex_engine, None,
|
app.add_config_value('latex_engine', default_latex_engine, None,
|
||||||
ENUM('pdflatex', 'xelatex', 'lualatex', 'platex', 'uplatex'))
|
ENUM('pdflatex', 'xelatex', 'lualatex', 'platex', 'uplatex'))
|
||||||
@ -555,6 +564,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
app.add_config_value('latex_elements', {}, None)
|
app.add_config_value('latex_elements', {}, None)
|
||||||
app.add_config_value('latex_additional_files', [], None)
|
app.add_config_value('latex_additional_files', [], None)
|
||||||
app.add_config_value('latex_theme', 'manual', None, [str])
|
app.add_config_value('latex_theme', 'manual', None, [str])
|
||||||
|
app.add_config_value('latex_theme_options', {}, None)
|
||||||
app.add_config_value('latex_theme_path', [], None, [list])
|
app.add_config_value('latex_theme_path', [], None, [list])
|
||||||
|
|
||||||
app.add_config_value('latex_docclass', default_latex_docclass, None)
|
app.add_config_value('latex_docclass', default_latex_docclass, None)
|
||||||
|
@ -25,6 +25,7 @@ class Theme:
|
|||||||
"""A set of LaTeX configurations."""
|
"""A set of LaTeX configurations."""
|
||||||
|
|
||||||
LATEX_ELEMENTS_KEYS = ['papersize', 'pointsize']
|
LATEX_ELEMENTS_KEYS = ['papersize', 'pointsize']
|
||||||
|
UPDATABLE_KEYS = ['papersize', 'pointsize']
|
||||||
|
|
||||||
def __init__(self, name: str) -> None:
|
def __init__(self, name: str) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -41,6 +42,11 @@ class Theme:
|
|||||||
value = config.latex_elements[key]
|
value = config.latex_elements[key]
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
for key in self.UPDATABLE_KEYS:
|
||||||
|
if key in config.latex_theme_options:
|
||||||
|
value = config.latex_theme_options[key]
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
|
||||||
class BuiltInTheme(Theme):
|
class BuiltInTheme(Theme):
|
||||||
"""A built-in LaTeX theme."""
|
"""A built-in LaTeX theme."""
|
||||||
|
@ -235,6 +235,17 @@ def test_latex_theme_papersize(app, status, warning):
|
|||||||
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result
|
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('latex', testroot='latex-theme',
|
||||||
|
confoverrides={'latex_theme_options': {'papersize': 'b5paper',
|
||||||
|
'pointsize': '9pt'}})
|
||||||
|
def test_latex_theme_options(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||||
|
print(result)
|
||||||
|
assert r'\def\sphinxdocclass{book}' in result
|
||||||
|
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'zh'})
|
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'zh'})
|
||||||
def test_latex_additional_settings_for_language_code(app, status, warning):
|
def test_latex_additional_settings_for_language_code(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
Loading…
Reference in New Issue
Block a user