Added the `latex_docclass` config value and made the "twoside"

documentclass option overridable by "oneside".
This commit is contained in:
Georg Brandl 2009-06-04 17:50:37 +02:00
parent 55bbb72bd0
commit ebcf18d9c3
7 changed files with 56 additions and 14 deletions

View File

@ -1,6 +1,9 @@
Release 1.0 (in development)
============================
* Added the ``latex_docclass`` config value and made the "twoside"
documentclass option overridable by "oneside".
* Added the ``extlinks`` extension.
* Allow searching for object names including the module name, like

View File

@ -74,7 +74,7 @@ latex_logo = '_static/sphinx.png'
# Additional stuff for the LaTeX preamble.
latex_elements = {
'fontpkg': '\\usepackage{palatino}'
'fontpkg': '\\usepackage{palatino}',
}
# Put TODOs into the output.

View File

@ -660,6 +660,14 @@ These options influence LaTeX output.
``'shorthandoff'``
``'printmodindex'``
.. confval:: latex_docclass
A dictionary mapping ``'howto'`` and ``'manual'`` to names of real document
classes that will be used as the base for the two Sphinx classes. Default
is to use ``'article'`` for ``'howto'`` and ``'report'`` for ``'manual'``.
.. versionadded:: 1.0
.. confval:: latex_additional_files
A list of file names, relative to the configuration directory, to copy to the

View File

@ -104,6 +104,7 @@ class Config(object):
latex_font_size = ('10pt', None),
latex_elements = ({}, None),
latex_additional_files = ([], None),
latex_docclass = ({}, None),
# now deprecated - use latex_elements
latex_preamble = ('', None),
)

View File

@ -1,14 +1,25 @@
%
% howto.cls for Sphinx
% sphinxhowto.cls for Sphinx (http://sphinx.pocoo.org/)
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{howto}[2008/10/18 Document class (Sphinx HOWTO)]
\ProvidesClass{sphinxhowto}[2009/06/02 Document class (Sphinx HOWTO)]
% Pass all given class options to the parent class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
% 'oneside' option overriding the 'twoside' default
\newif\if@oneside
\DeclareOption{oneside}{\@onesidetrue}
% Pass remaining document options to the parent class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\sphinxdocclass}}
\ProcessOptions\relax
\LoadClass[twoside]{article}
% Default to two-side document
\if@oneside
% nothing to do (oneside is the default)
\else
\PassOptionsToClass{twoside}{\sphinxdocclass}
\fi
\LoadClass{\sphinxdocclass}
% Set some sane defaults for section numbering depth and TOC depth. You can
% reset these counters in your preamble.

View File

@ -1,14 +1,28 @@
%
% manual.cls for Sphinx
% sphinxmanual.cls for Sphinx (http://sphinx.pocoo.org/)
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{manual}[2008/10/18 Document class (Sphinx manual)]
\ProvidesClass{sphinxmanual}[2009/06/02 Document class (Sphinx manual)]
% Pass all given class options to the parent class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
% chapters starting at odd pages (overridden by 'openany' document option)
\PassOptionsToClass{openright}{\sphinxdocclass}
% 'oneside' option overriding the 'twoside' default
\newif\if@oneside
\DeclareOption{oneside}{\@onesidetrue}
% Pass remaining document options to the parent class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\sphinxdocclass}}
\ProcessOptions\relax
\LoadClass[twoside,openright]{report}
% Defaults two-side document
\if@oneside
% nothing to do (oneside is the default)
\else
\PassOptionsToClass{twoside}{\sphinxdocclass}
\fi
\LoadClass{\sphinxdocclass}
% Set some sane defaults for section numbering depth and TOC depth. You can
% reset these counters in your preamble.

View File

@ -28,7 +28,8 @@ from sphinx.util.texescape import tex_escape_map
from sphinx.util.smartypants import educateQuotesLatex
HEADER = r'''%% Generated by Sphinx.
\documentclass[%(papersize)s,%(pointsize)s%(classoptions)s]{%(docclass)s}
\def\sphinxdocclass{%(docclass)s}
\documentclass[%(papersize)s,%(pointsize)s%(classoptions)s]{%(wrapperclass)s}
%(inputenc)s
%(utf8extra)s
%(fontenc)s
@ -135,7 +136,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
ignore_missing_images = False
default_elements = {
'docclass': 'manual',
'papersize': 'letterpaper',
'pointsize': '10pt',
'classoptions': '',
@ -175,7 +175,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.elements = self.default_elements.copy()
self.elements.update({
'docclass': document.settings.docclass,
'wrapperclass': 'sphinx' + document.settings.docclass,
'papersize': papersize,
'pointsize': builder.config.latex_font_size,
# if empty, the title is set to the first section title
@ -189,6 +189,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
'modindexname': _('Module Index'),
'indexname': _('Index'),
})
if document.settings.docclass == 'howto':
docclass = builder.config.latex_docclass.get('howto', 'article')
else:
docclass = builder.config.latex_docclass.get('manual', 'report')
self.elements['docclass'] = docclass
if builder.config.latex_logo:
self.elements['logo'] = '\\includegraphics{%s}\\par' % \
path.basename(builder.config.latex_logo)