Commits

Georg Brandl committed 5b1718f

Added the ``latex_docclass`` config value and made the "twoside"
documentclass option overridable by "oneside".

  • Participants
  • Parent commits 2fa8417

Comments (0)

Files changed (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
 
 # Additional stuff for the LaTeX preamble.
 latex_elements = {
-    'fontpkg': '\\usepackage{palatino}'
+    'fontpkg': '\\usepackage{palatino}',
 }
 
 # Put TODOs into the output.

File doc/config.rst

      ``'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

File sphinx/config.py

         latex_font_size = ('10pt', None),
         latex_elements = ({}, None),
         latex_additional_files = ([], None),
+        latex_docclass = ({}, None),
         # now deprecated - use latex_elements
         latex_preamble = ('', None),
     )

File sphinx/texinputs/howto.cls

-%
-% howto.cls for Sphinx
-%
-
-\NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesClass{howto}[2008/10/18 Document class (Sphinx HOWTO)]
-
-% Pass all given class options to the parent class.
-\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
-\ProcessOptions\relax
-\LoadClass[twoside]{article}
-
-% Set some sane defaults for section numbering depth and TOC depth.  You can
-% reset these counters in your preamble.
-%
-\setcounter{secnumdepth}{2}
-
-% Change the title page to look a bit better, and fit in with the fncychap
-% ``Bjarne'' style a bit better.
-%
-\renewcommand{\maketitle}{
-  \rule{\textwidth}{1pt}
-  \ifsphinxpdfoutput
-    \begingroup
-    % This \def is required to deal with multi-line authors; it
-    % changes \\ to ', ' (comma-space), making it pass muster for
-    % generating document info in the PDF file.
-    \def\\{, }
-    \pdfinfo{
-      /Author (\@author)
-      /Title (\@title)
-    }
-    \endgroup
-  \fi
-  \begin{flushright}
-    \sphinxlogo%
-    {\rm\Huge\py@HeaderFamily \@title} \par
-    {\em\large\py@HeaderFamily \py@release\releaseinfo} \par
-    \vspace{25pt}
-    {\Large\py@HeaderFamily \@author} \par
-    \vspace{25pt}
-    \@date \par
-    \py@authoraddress \par
-  \end{flushright}
-  \@thanks
-  \setcounter{footnote}{0}
-  \let\thanks\relax\let\maketitle\relax
-  %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
-}
-
-\let\py@OldTableofcontents=\tableofcontents
-\renewcommand{\tableofcontents}{
-  \begingroup
-    \parskip = 0mm
-    \py@OldTableofcontents
-  \endgroup
-  \rule{\textwidth}{1pt}
-  \vspace{12pt}
-}  
-
-\@ifundefined{fancyhf}{
-  \pagestyle{plain}}{
-  \pagestyle{normal}}		% start this way; change for
-\pagenumbering{arabic}		% ToC & chapters
-
-\thispagestyle{empty}

File sphinx/texinputs/manual.cls

-%
-% manual.cls for Sphinx
-%
-
-\NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesClass{manual}[2008/10/18 Document class (Sphinx manual)]
-
-% Pass all given class options to the parent class.
-\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
-\ProcessOptions\relax
-\LoadClass[twoside,openright]{report}
-
-% Set some sane defaults for section numbering depth and TOC depth.  You can
-% reset these counters in your preamble.
-%
-\setcounter{secnumdepth}{2}
-\setcounter{tocdepth}{1}
-
-% Change the title page to look a bit better, and fit in with the fncychap
-% ``Bjarne'' style a bit better.
-%
-\renewcommand{\maketitle}{%
-  \begin{titlepage}%
-    \let\footnotesize\small
-    \let\footnoterule\relax
-    \rule{\textwidth}{1pt}%
-    \ifsphinxpdfoutput
-      \begingroup
-      % This \def is required to deal with multi-line authors; it
-      % changes \\ to ', ' (comma-space), making it pass muster for
-      % generating document info in the PDF file.
-      \def\\{, }
-      \pdfinfo{
-        /Author (\@author)
-        /Title (\@title)
-      }
-      \endgroup
-    \fi
-    \begin{flushright}%
-      \sphinxlogo%
-      {\rm\Huge\py@HeaderFamily \@title \par}%
-      {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par}
-      \vfill
-      {\LARGE\py@HeaderFamily \@author \par}
-      \vfill\vfill
-      {\large
-       \@date \par
-       \vfill
-       \py@authoraddress \par
-      }%
-    \end{flushright}%\par
-    \@thanks
-  \end{titlepage}%
-  \cleardoublepage%
-  \setcounter{footnote}{0}%
-  \let\thanks\relax\let\maketitle\relax
-  %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
-}
-
-
-% Catch the end of the {abstract} environment, but here make sure the abstract
-% is followed by a blank page if the 'openright' option is used.
-%
-\let\py@OldEndAbstract=\endabstract
-\renewcommand{\endabstract}{
-  \if@openright
-    \ifodd\value{page}
-      \typeout{Adding blank page after the abstract.}
-      \vfil\pagebreak
-    \fi
-  \fi
-  \py@OldEndAbstract
-}
-
-% This wraps the \tableofcontents macro with all the magic to get the spacing
-% right and have the right number of pages if the 'openright' option has been
-% used.  This eliminates a fair amount of crud in the individual document files.
-%
-\let\py@OldTableofcontents=\tableofcontents
-\renewcommand{\tableofcontents}{%
-  \setcounter{page}{1}%
-  \pagebreak%
-  \pagestyle{plain}%
-  {%
-    \parskip = 0mm%
-    \py@OldTableofcontents%
-    \if@openright%
-      \ifodd\value{page}%
-        \typeout{Adding blank page after the table of contents.}%
-        \pagebreak\hspace{0pt}%
-      \fi%
-    \fi%
-    \cleardoublepage%
-  }%
-  \pagenumbering{arabic}%
-  \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
-}
-
-% This is needed to get the width of the section # area wide enough in the
-% library reference.  Doing it here keeps it the same for all the manuals.
-%
-\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}}
-\renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}

File sphinx/texinputs/sphinxhowto.cls

+%
+% sphinxhowto.cls for Sphinx (http://sphinx.pocoo.org/)
+%
+
+\NeedsTeXFormat{LaTeX2e}[1995/12/01]
+\ProvidesClass{sphinxhowto}[2009/06/02 Document class (Sphinx HOWTO)]
+
+% '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
+
+% 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.
+%
+\setcounter{secnumdepth}{2}
+
+% Change the title page to look a bit better, and fit in with the fncychap
+% ``Bjarne'' style a bit better.
+%
+\renewcommand{\maketitle}{
+  \rule{\textwidth}{1pt}
+  \ifsphinxpdfoutput
+    \begingroup
+    % This \def is required to deal with multi-line authors; it
+    % changes \\ to ', ' (comma-space), making it pass muster for
+    % generating document info in the PDF file.
+    \def\\{, }
+    \pdfinfo{
+      /Author (\@author)
+      /Title (\@title)
+    }
+    \endgroup
+  \fi
+  \begin{flushright}
+    \sphinxlogo%
+    {\rm\Huge\py@HeaderFamily \@title} \par
+    {\em\large\py@HeaderFamily \py@release\releaseinfo} \par
+    \vspace{25pt}
+    {\Large\py@HeaderFamily \@author} \par
+    \vspace{25pt}
+    \@date \par
+    \py@authoraddress \par
+  \end{flushright}
+  \@thanks
+  \setcounter{footnote}{0}
+  \let\thanks\relax\let\maketitle\relax
+  %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
+}
+
+\let\py@OldTableofcontents=\tableofcontents
+\renewcommand{\tableofcontents}{
+  \begingroup
+    \parskip = 0mm
+    \py@OldTableofcontents
+  \endgroup
+  \rule{\textwidth}{1pt}
+  \vspace{12pt}
+}  
+
+\@ifundefined{fancyhf}{
+  \pagestyle{plain}}{
+  \pagestyle{normal}}		% start this way; change for
+\pagenumbering{arabic}		% ToC & chapters
+
+\thispagestyle{empty}

File sphinx/texinputs/sphinxmanual.cls

+%
+% sphinxmanual.cls for Sphinx (http://sphinx.pocoo.org/)
+%
+
+\NeedsTeXFormat{LaTeX2e}[1995/12/01]
+\ProvidesClass{sphinxmanual}[2009/06/02 Document class (Sphinx manual)]
+
+% 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
+
+% 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.
+%
+\setcounter{secnumdepth}{2}
+\setcounter{tocdepth}{1}
+
+% Change the title page to look a bit better, and fit in with the fncychap
+% ``Bjarne'' style a bit better.
+%
+\renewcommand{\maketitle}{%
+  \begin{titlepage}%
+    \let\footnotesize\small
+    \let\footnoterule\relax
+    \rule{\textwidth}{1pt}%
+    \ifsphinxpdfoutput
+      \begingroup
+      % This \def is required to deal with multi-line authors; it
+      % changes \\ to ', ' (comma-space), making it pass muster for
+      % generating document info in the PDF file.
+      \def\\{, }
+      \pdfinfo{
+        /Author (\@author)
+        /Title (\@title)
+      }
+      \endgroup
+    \fi
+    \begin{flushright}%
+      \sphinxlogo%
+      {\rm\Huge\py@HeaderFamily \@title \par}%
+      {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par}
+      \vfill
+      {\LARGE\py@HeaderFamily \@author \par}
+      \vfill\vfill
+      {\large
+       \@date \par
+       \vfill
+       \py@authoraddress \par
+      }%
+    \end{flushright}%\par
+    \@thanks
+  \end{titlepage}%
+  \cleardoublepage%
+  \setcounter{footnote}{0}%
+  \let\thanks\relax\let\maketitle\relax
+  %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
+}
+
+
+% Catch the end of the {abstract} environment, but here make sure the abstract
+% is followed by a blank page if the 'openright' option is used.
+%
+\let\py@OldEndAbstract=\endabstract
+\renewcommand{\endabstract}{
+  \if@openright
+    \ifodd\value{page}
+      \typeout{Adding blank page after the abstract.}
+      \vfil\pagebreak
+    \fi
+  \fi
+  \py@OldEndAbstract
+}
+
+% This wraps the \tableofcontents macro with all the magic to get the spacing
+% right and have the right number of pages if the 'openright' option has been
+% used.  This eliminates a fair amount of crud in the individual document files.
+%
+\let\py@OldTableofcontents=\tableofcontents
+\renewcommand{\tableofcontents}{%
+  \setcounter{page}{1}%
+  \pagebreak%
+  \pagestyle{plain}%
+  {%
+    \parskip = 0mm%
+    \py@OldTableofcontents%
+    \if@openright%
+      \ifodd\value{page}%
+        \typeout{Adding blank page after the table of contents.}%
+        \pagebreak\hspace{0pt}%
+      \fi%
+    \fi%
+    \cleardoublepage%
+  }%
+  \pagenumbering{arabic}%
+  \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
+}
+
+% This is needed to get the width of the section # area wide enough in the
+% library reference.  Doing it here keeps it the same for all the manuals.
+%
+\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}}
+\renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}

File sphinx/writers/latex.py

 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
     ignore_missing_images = False
 
     default_elements = {
-        'docclass':        'manual',
         'papersize':       'letterpaper',
         'pointsize':       '10pt',
         'classoptions':    '',
 
         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
             '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)