mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3096 from jfbu/latex_fixtoodeeplynested
Fix #777: (part II) LaTeX output "too deeply nested"
This commit is contained in:
commit
5fa47df1e8
@ -1743,6 +1743,22 @@ These options influence LaTeX output. See further :doc:`latex`.
|
||||
|
||||
* Keys that don't need be overridden unless in special cases are:
|
||||
|
||||
``'maxlistdepth'``
|
||||
LaTeX allows by default at most 6 levels for nesting list and
|
||||
quote-like environments, with at most 4 enumerated lists, and 4 bullet
|
||||
lists. Setting this key for example to ``'10'`` (as a string) will
|
||||
allow up to 10 nested levels (of all sorts). Leaving it to the empty
|
||||
string means to obey the LaTeX default.
|
||||
|
||||
.. warning::
|
||||
|
||||
- Using this key may prove incompatible with some LaTeX packages
|
||||
or special document classes which do their own list customization.
|
||||
|
||||
- The key setting is silently *ignored* in presence of "enumitem".
|
||||
Use then rather the dedicated commands of this LaTeX package.
|
||||
|
||||
.. versionadded:: 1.5
|
||||
``'inputenc'``
|
||||
"inputenc" package inclusion, defaults to
|
||||
``'\\usepackage[utf8]{inputenc}'`` when using pdflatex.
|
||||
|
@ -1,6 +1,6 @@
|
||||
%% Generated by Sphinx.
|
||||
\def\sphinxdocclass{<%= docclass %>}
|
||||
<%= keepoldnames %>
|
||||
<%= passoptionstosphinx %>
|
||||
\documentclass[<%= papersize %>,<%= pointsize %><%= classoptions %>]{<%= wrapperclass %>}
|
||||
\ifdefined\pdfpxdimen
|
||||
\let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
|
||||
|
@ -6,11 +6,15 @@
|
||||
%
|
||||
|
||||
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
|
||||
\ProvidesPackage{sphinx}[2016/10/12 v1.5 LaTeX package (Sphinx markup)]
|
||||
\newif\ifsphinxKeepOldNames \sphinxKeepOldNamestrue
|
||||
\DeclareOption{dontkeepoldnames}{\sphinxKeepOldNamesfalse}
|
||||
\DeclareOption*{\PackageWarning{sphinx}{Unknown option `\CurrentOption'}}
|
||||
\ProcessOptions\relax
|
||||
\ProvidesPackage{sphinx}[2016/10/26 v1.5 LaTeX package (Sphinx markup)]
|
||||
|
||||
% Handle package options via "kvoptions" (later loaded by hyperref anyhow)
|
||||
\RequirePackage{kvoptions}
|
||||
\SetupKeyvalOptions{prefix=spx@opt@} % use \spx@opt@ prefix
|
||||
\DeclareBoolOption{dontkeepoldnames} % \ifspx@opt@dontkeepoldnames = \iffalse
|
||||
\DeclareStringOption[0]{maxlistdepth}% \newcommand*\spx@opt@maxlistdepth{0}
|
||||
\DeclareDefaultOption{\@unknownoptionerror}
|
||||
\ProcessKeyvalOptions*
|
||||
|
||||
% this is the \ltx@ifundefined of ltxcmds.sty, which is loaded by
|
||||
% hyperref.sty, but we need it before, and the first release of
|
||||
@ -962,7 +966,7 @@
|
||||
\spx@originalcaption }
|
||||
|
||||
% by default, also define macros with the no-prefix names
|
||||
\ifsphinxKeepOldNames
|
||||
\ifspx@opt@dontkeepoldnames\else
|
||||
\typeout{** (sphinx) defining (legacy) text style macros without \string\sphinx\space prefix}
|
||||
\typeout{** if clashes with packages, set latex_keep_old_macro_names=False
|
||||
in conf.py}
|
||||
@ -1005,3 +1009,76 @@
|
||||
\providecommand*{\sphinxtableofcontents}{\tableofcontents}
|
||||
\providecommand*{\sphinxthebibliography}{\thebibliography}
|
||||
\providecommand*{\sphinxtheindex}{\theindex}
|
||||
|
||||
% remove LaTeX's cap on nesting depth if 'maxlistdepth' key used.
|
||||
% This is a hack, which works with the standard classes: it assumes \@toodeep
|
||||
% is always used in "true" branches: "\if ... \@toodeep \else .. \fi."
|
||||
|
||||
% will force use the "false" branch (if there is one)
|
||||
\def\spx@toodeep@hack{\fi\iffalse}
|
||||
|
||||
% do nothing if 'maxlistdepth' key not used or if package enumitem loaded.
|
||||
\ifnum\spx@opt@maxlistdepth=\z@\expandafter\@gobbletwo\fi
|
||||
\AtBeginDocument{%
|
||||
\@ifpackageloaded{enumitem}{\remove@to@nnil}{}%
|
||||
\let\spx@toodeepORI\@toodeep
|
||||
\def\@toodeep{%
|
||||
\ifnum\@listdepth<\spx@opt@maxlistdepth\relax
|
||||
\expandafter\spx@toodeep@hack
|
||||
\else
|
||||
\expandafter\spx@toodeepORI
|
||||
\fi}%
|
||||
% define all missing \@list... macros
|
||||
\count@\@ne
|
||||
\loop
|
||||
\spx@ifundefined{@list\romannumeral\the\count@}
|
||||
{\iffalse}{\iftrue\advance\count@\@ne}%
|
||||
\repeat
|
||||
\loop
|
||||
\ifnum\count@>\spx@opt@maxlistdepth\relax\else
|
||||
\expandafter\let
|
||||
\csname @list\romannumeral\the\count@\expandafter\endcsname
|
||||
\csname @list\romannumeral\the\numexpr\count@-\@ne\endcsname
|
||||
% higher \leftmargin... needed to fix issue with babel-french (v2.6--...)
|
||||
\spx@ifundefined{leftmargin\romannumeral\the\count@}
|
||||
{\expandafter\let
|
||||
\csname leftmargin\romannumeral\the\count@\expandafter\endcsname
|
||||
\csname leftmargin\romannumeral\the\numexpr\count@-\@ne\endcsname}{}%
|
||||
\advance\count@\@ne
|
||||
\repeat
|
||||
% define all missing enum... counters and \labelenum... macros and \p@enum..
|
||||
\count@\@ne
|
||||
\loop
|
||||
\spx@ifundefined{c@enum\romannumeral\the\count@}
|
||||
{\iffalse}{\iftrue\advance\count@\@ne}%
|
||||
\repeat
|
||||
\loop
|
||||
\ifnum\count@>\spx@opt@maxlistdepth\relax\else
|
||||
\newcounter{enum\romannumeral\the\count@}%
|
||||
\expandafter\def
|
||||
\csname labelenum\romannumeral\the\count@\expandafter\endcsname
|
||||
\expandafter
|
||||
{\csname theenum\romannumeral\the\numexpr\count@\endcsname.}%
|
||||
\expandafter\def
|
||||
\csname p@enum\romannumeral\the\count@\expandafter\endcsname
|
||||
\expandafter
|
||||
{\csname p@enum\romannumeral\the\numexpr\count@-\@ne\expandafter
|
||||
\endcsname\csname theenum\romannumeral\the\numexpr\count@-\@ne\endcsname.}%
|
||||
\advance\count@\@ne
|
||||
\repeat
|
||||
% define all missing labelitem... macros
|
||||
\count@\@ne
|
||||
\loop
|
||||
\spx@ifundefined{labelitem\romannumeral\the\count@}
|
||||
{\iffalse}{\iftrue\advance\count@\@ne}%
|
||||
\repeat
|
||||
\loop
|
||||
\ifnum\count@>\spx@opt@maxlistdepth\relax\else
|
||||
\expandafter\let
|
||||
\csname labelitem\romannumeral\the\count@\expandafter\endcsname
|
||||
\csname labelitem\romannumeral\the\numexpr\count@-\@ne\endcsname
|
||||
\advance\count@\@ne
|
||||
\repeat
|
||||
\PackageInfo{sphinx}{maximal list depth extended to \spx@opt@maxlistdepth}%
|
||||
\@gobble\@nnil
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ DEFAULT_SETTINGS = {
|
||||
'pxunit': '49336sp',
|
||||
'classoptions': '',
|
||||
'extraclassoptions': '',
|
||||
'maxlistdepth': '',
|
||||
'passoptionstopackages': '',
|
||||
'geometry': '\\usepackage[margin=1in,marginparwidth=0.5in]'
|
||||
'{geometry}',
|
||||
@ -374,12 +375,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
'releasename': _('Release'),
|
||||
'indexname': _('Index'),
|
||||
})
|
||||
# set-up boolean for sphinx.sty
|
||||
if builder.config.latex_keep_old_macro_names:
|
||||
self.elements['keepoldnames'] = ''
|
||||
else:
|
||||
self.elements['keepoldnames'] = ('\\PassOptionsToPackage'
|
||||
'{dontkeepoldnames}{sphinx}')
|
||||
sphinxpkgoptions = ''
|
||||
if not builder.config.latex_keep_old_macro_names:
|
||||
sphinxpkgoptions = 'dontkeepoldnames'
|
||||
if document.settings.docclass == 'howto':
|
||||
docclass = builder.config.latex_docclass.get('howto', 'article')
|
||||
else:
|
||||
@ -453,6 +451,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
# allow the user to override them all
|
||||
self.check_latex_elements()
|
||||
self.elements.update(builder.config.latex_elements)
|
||||
if self.elements['maxlistdepth']:
|
||||
sphinxpkgoptions += ',maxlistdepth=%s' % self.elements['maxlistdepth']
|
||||
if sphinxpkgoptions:
|
||||
self.elements['passoptionstosphinx'] = \
|
||||
'\\PassOptionsToPackage{%s}{sphinx}' % sphinxpkgoptions
|
||||
if self.elements['extraclassoptions']:
|
||||
self.elements['classoptions'] += ',' + \
|
||||
self.elements['extraclassoptions']
|
||||
|
Loading…
Reference in New Issue
Block a user