Skip to content

Commit

Permalink
Merge pull request #3096 from jfbu/latex_fixtoodeeplynested
Browse files Browse the repository at this point in the history
Fix #777: (part II) LaTeX output "too deeply nested"
  • Loading branch information
jfbu committed Oct 27, 2016
2 parents 183a2ca + 4e2bdf6 commit 5fa47df
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 13 deletions.
16 changes: 16 additions & 0 deletions doc/config.rst
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sphinx/templates/latex/content.tex_t
@@ -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
Expand Down
89 changes: 83 additions & 6 deletions sphinx/texinputs/sphinx.sty
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
}
15 changes: 9 additions & 6 deletions sphinx/writers/latex.py
Expand Up @@ -51,6 +51,7 @@
'pxunit': '49336sp',
'classoptions': '',
'extraclassoptions': '',
'maxlistdepth': '',
'passoptionstopackages': '',
'geometry': '\\usepackage[margin=1in,marginparwidth=0.5in]'
'{geometry}',
Expand Down Expand Up @@ -374,12 +375,9 @@ def __init__(self, document, builder):
'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:
Expand Down Expand Up @@ -453,6 +451,11 @@ def declare_package(packagename, options=None):
# 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']
Expand Down

0 comments on commit 5fa47df

Please sign in to comment.