Skip to content

Latex output "too deeply nested" #777

Closed

Description

@shimizukawa

If Sphinx's LaTeX output gets too deeply-nested, I get the following error:

[13] [14]
Chapter 4.
[15]

! LaTeX Error: Too deeply nested.

I've found an item on the Docutils to-do list:
http://docutils.sourceforge.net/docs/dev/todo.html
indicating that this is something they're aware of, but have not yet fixed, but I'm wondering if this is something Sphinx can work around in the mean time.

In particular, the LaTeX "enumitem" package:
http://www.tex.ac.uk/CTAN/macros/latex/contrib/enumitem/
has recently added support for list environments of any depth. I was wondering if Sphinx could make use of this package to allow nesting of chapters and code blocks to a higher number of levels, because when you start using code blocks with several levels of indentation, the nesting gets deep quickly, and standard LaTeX maxes out somewhere around 5-6 levels.

Could something like this work?


Activity

  1. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From kaiwa on 2012-07-18 12:31:15+00:00

    +1 for using enumitem package

  2. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From Martin Ortbauer on 2012-09-05 12:36:10+00:00

    I encountered the same problem. did you or somebody already implement that? or did you find some workaround?
    thanks

  3. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From tonycpsu on 2012-09-05 14:49:20+00:00

    I don't know of any workarounds other than lowering the number of nesting levels in my documents. I would love it if Sphinx could switch to using enumitem to get rid of this limit.

  4. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From Nicolas M. Thiéry on 2013-08-29 15:12:46+00:00

    +1 to using enumitem as well. We stumbled on this problem in Sage [1]:

    Probably a bit more work will actually be needed, for there seems to be a bug in the @listdepth incrementation/decrementation with Sphinx+enumitem: for a file which is not soo deeply nested (10 maybe?) but quite long, we actually need to use \setlistdepth{264} !

    Cheers,
    Nicolas

    [1] http://trac.sagemath.org/ticket/9107#comment:42

  5. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From Nicolas M. Thiéry on 2014-06-13 08:36:59+00:00

    I got annoyed because we now need to use \setlistdepth{2000}, so the problem was just going to become worst and worst with time. So I investigated a bit further, and found out that if we replace list by trivlist in the customized Verbatim defined by sphinx.sty, then our documenation compiles smoothly, without even using enumitem.

    To everyone here: does this fix your own compilation errors?

    To the sphinx devs: does this seem like a sensible change to do to sphinx.sty?

  6. shimizukawa commented on Jan 2, 2015

    @shimizukawa
    MemberAuthor

    From Nicolas M. Thiéry on 2014-06-13 09:16:52+00:00

    I proposed a pull request for this on: https://bitbucket.org/birkenfeld/sphinx/pull-request/250/

  7. nthiery commented on Mar 8, 2015

    @nthiery

    Ping? Does using trivlist sound reasonable?

  8. kiwifb commented on Jun 5, 2016

    @kiwifb

    Resurrecting the discussion. Using trivlist sounds ok to me. Looking at the doc that would also means that some of the lengths are set to 0 automatically so a few (but not all) \setlength statements could be removed.

  9. jfbu commented on Jun 5, 2016

    @jfbu
    Contributor

    yes using trivlist is definitely feasible, avoids the check for nesting depth done by list and if needed (I have not looked closerly) we can always add some of the things done by list and not by trivlist either at begin or end. I can work on this tomorrow.

  10. added this to the 1.4.4 milestone on Jun 5, 2016
  11. self-assigned this
    on Jun 5, 2016
  12. 47 remaining items

  13. modified the milestones: 1.4.6, 1.4.5 on Jul 8, 2016
  14. modified the milestones: 1.5, 1.4.6 on Aug 17, 2016
  15. mindw commented on Oct 24, 2016

    @mindw
    Contributor

    got hit by this issue while building sqlalchemy PDF doc. The following worked for me:

    \usepackage{enumitem}
    \setlistdepth{20}
    \renewlist{itemize}{itemize}{20}
    
    % initially, use dots for all levels
    \setlist[itemize]{label=$\cdot$}
    \setlist[itemize]{labelsep=.5em}
    
    % customize the first 3 levels
    \setlist[itemize,1]{label=\textbullet}
    \setlist[itemize,2]{label=--}
    \setlist[itemize,3]{label=*}
  16. added a commit that references this issue on Oct 25, 2016
    15b4573
  17. jfbu commented on Oct 25, 2016

    @jfbu
    Contributor

    @mindw

    Thanks for the tip. Loading enumitem and using \setlistdepth allows to ease up the cap on maximal depths, but one must also, as you do in your code, \renewlist explicitely the itemize, enumerate and description to reset the cap on listdepth for them.

    I wanted to test this and I have an issue, I can't get it to work:

    \documentclass{article}
    
    \usepackage{enumitem}
    \setlistdepth{10}
    \renewlist{itemize}{itemize}{10}
    \setlist[itemize]{label=$\cdot$}
    \setlist[itemize]{labelsep=.5em}
    
    \setlist[itemize,1]{label=\textbullet}
    \setlist[itemize,2]{label=--}
    \setlist[itemize,3]{label=*}
    \setlist[itemize,4]{label=*}
    
    \begin{document}
    
    %does NOT work! Package enumitem Error: Undefined label. (at level of \item e)
    
    \begin{itemize}
    \item a
      \begin{itemize}
      \item b
        \begin{itemize}
        \item c
          \begin{itemize}
          \item d
            \begin{itemize}
            \item e
              \begin{itemize}
              \item f
              \end{itemize}
            \end{itemize}
          \end{itemize}
        \end{itemize}
      \end{itemize}
    \end{itemize}
    \end{document}

    Does your document really have 5 or more nested itemize ? or is it simply the maximal nesting depth which goes beyond 6 and is fixed by your set-up ?

    This is with enumitem 2011/09/28 v3.5.2. Could you also check in your latex log the version you use (in case my code snippet above does work with your version of enumitem).

  18. jfbu commented on Oct 25, 2016

    @jfbu
    Contributor

    @mindw

    I see your code snippet also here. However notice that the accepted answer explicitely sets the label at each level (in the case of enumerate). I checked the enumitem manual and the fact that my code snippet is not working does seem to contradict the manual. This is possibly a bug in package enumitem, or in its documentation. This problem complicates incorporating use of enumitem into Sphinx (additionally to the fact that we should not break people's setup which already use it). Besides enumitem has had some updates after TL2009 which Sphinx currently supports. It appears some of these updates precisely refers to issues with \setlist.

    Memo:

  19. jfbu commented on Oct 25, 2016

    @jfbu
    Contributor

    @mindw

    I got it just before posting a bug report to enumitem's author !

    Your code should be with

    \setlist[itemize]{label=$\cdot$, labelsep=.5em}
    

    and not with

    \setlist[itemize]{label=$\cdot$}
    \setlist[itemize]{labelsep=.5em}
    

    It appears that the second use of \setlist upsets the first one. I have no idea if this is clear from the enumitem doc. But this does complicate matters for incorporating use of enumuitem in Sphinx.

  20. added a commit that references this issue on Oct 25, 2016
    3e1a7e0
  21. jfbu commented on Oct 25, 2016

    @jfbu
    Contributor

    PR #3096 addresses this without resorting to package enumitem. Of course enumitem has much to recommend it, but its version in TeXLive 2009 which Sphinx supports was at 2.x, and later it reached 3.5.2, with some important changes. Once Sphinx will support only TeXLive 2013 or later, we can more easily consider using enumitem which had no changes since.

  22. added a commit that references this issue on Oct 26, 2016
    3af9353
  23. added a commit that references this issue on Oct 27, 2016
    5fa47df
  24. locked as resolved and limited conversation to collaborators on Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions