Pandoc: ! LaTeX Error: Too deeply nested (lists more than 6 levels deep)

Created on 16 May 2016  路  13Comments  路  Source: jgm/pandoc

This is already a long-living issue (there has been discussions [1] [2] quite a while ago about this), but because it's still not solved (the hack mentioned in [1] obviously doesn't work when not working with markdown or when just converting random documents to PDF) and because I could not find any existing issue here on GitHub, I'm creating one.

I fully understand and even more agree with the rule to make _pandoc_ PDF export work even with the _texlive-latex-base_聽debian package and therefore I would recommend trying to use the solution outlined on SO.

LaTeX writer

Most helpful comment

Create a file deeplists.tex with the following contents:
`````
usepackage{enumitem}
setlistdepth{9}

setlist[itemize,1]{label=$bullet$}
setlist[itemize,2]{label=$bullet$}
setlist[itemize,3]{label=$bullet$}
setlist[itemize,4]{label=$bullet$}
setlist[itemize,5]{label=$bullet$}
setlist[itemize,6]{label=$bullet$}
setlist[itemize,7]{label=$bullet$}
setlist[itemize,8]{label=$bullet$}
setlist[itemize,9]{label=$bullet$}
renewlist{itemize}{itemize}{9}

setlist[enumerate,1]{label=$arabic.$}
setlist[enumerate,2]{label=$alph
.$}
setlist[enumerate,3]{label=$roman.$}
setlist[enumerate,4]{label=$arabic
.$}
setlist[enumerate,5]{label=$alpha$}
setlist[enumerate,6]{label=$roman
.$}
setlist[enumerate,7]{label=$arabic.$}
setlist[enumerate,8]{label=$alph
.$}
setlist[enumerate,9]{label=$roman*.$}
renewlist{enumerate}{enumerate}{9}
`````

Then use -H deeplists.tex on your pandoc command line. That should be all it takes to get deeply nested lists to work. You need to make sure the enumitem latex package is available.

All 13 comments

You mean the solution of adding a bunch of low-level latex definitions to the default latex template? I'd rather not do that; it adds a lot of length and complexity to the template.

Perhaps we could include a conditional in the template to use enumitem if a certain variable (enumitem) is set, and the LaTeX writer could be told to set that variable if the document contains any lists nested more than six levels deep? The writer would have to keep track of nesting levels as it rendered lists, but this could be done.

This solution would mean that in most cases the enumitem package wouldn't be needed.

You mean the solution of adding a bunch of low-level latex definitions to the default latex template?

Right, that's what I meant.

Perhaps we could include a conditional in the template to use enumitem if a certain variable (enumitem) is set, and the LaTeX writer could be told to set that variable if the document contains any lists nested more than six levels deep?

How about making it completely unattended using IfFileExists or @ifpackageloaded?

+++ dumblob [May 17 16 10:53 ]:

Perhaps we could include a conditional in the template to use
enumitem if a certain variable (enumitem) is set, and the LaTeX
writer could be told to set that variable if the document contains
any lists nested more than six levels deep?

How about making it completely unattended using [1]IfFileExists or
[2]@ifpackageloaded?

If we do that, then people who don't have enumitem installed
will still get the LaTeX error, and won't know how to fix
it. With the solution I suggested, they'd get a different
LaTeX error, but one that points towards a solution (package
enumitem missing).

If we do that, then people who don't have enumitem installed will still get the LaTeX error, and won't know how to fix it. With the solution I suggested, they'd get a different LaTeX error, but one that points towards a solution (package enumitem missing).

That depends on whether the enumitem variable will be set by default or unset. Probably unset (because deeper nesting than 5 shouldn't be more common than nesting up to 5th level) and then you're right.

Any news on this?

No, it's not a high priority for me, but maybe someone else wants to code up the solution mentioned?

Well, the part

The writer would have to keep track of nesting levels as it rendered lists, but this could be done.

seems to be the most difficult one of the whole solution you proposed above. Could you help at least with this keeping track of nesting levels?

+++ dumblob [Nov 06 17 17:08 ]:

Well, the part

The writer would have to keep track of nesting levels as it rendered
lists, but this could be done.

seems to be the most difficult one of the whole solution you proposed
[1]above. Could you help at least with this keeping track of nesting
levels?

You'd need to add a counter for the nesting level to
LaTeXState. Then you'd use 'modify' to increment this
before parsing the contents of a list, and decrement
it after. And you'd use 'gets' to get the current nesting
level. I suppose you'd need something else in state that
would be set to True if the nesting level ever gets above 5.

As a follow up here, while it sounds like fixing this sustainably may not be possible at this time is there a workaround (however hacky)? I noticed an old post on Gmane about this topic where @jgm you seemed to have a temporary solution involving replacing the enumerate package with enumitem. That post is back from 2012 and the template default.latex no longer appears to use the enumerate package. Is a similar workaround still viable and if so what would be the lines now to remove and add? Thanks in advance!

Create a file deeplists.tex with the following contents:
`````
usepackage{enumitem}
setlistdepth{9}

setlist[itemize,1]{label=$bullet$}
setlist[itemize,2]{label=$bullet$}
setlist[itemize,3]{label=$bullet$}
setlist[itemize,4]{label=$bullet$}
setlist[itemize,5]{label=$bullet$}
setlist[itemize,6]{label=$bullet$}
setlist[itemize,7]{label=$bullet$}
setlist[itemize,8]{label=$bullet$}
setlist[itemize,9]{label=$bullet$}
renewlist{itemize}{itemize}{9}

setlist[enumerate,1]{label=$arabic.$}
setlist[enumerate,2]{label=$alph
.$}
setlist[enumerate,3]{label=$roman.$}
setlist[enumerate,4]{label=$arabic
.$}
setlist[enumerate,5]{label=$alpha$}
setlist[enumerate,6]{label=$roman
.$}
setlist[enumerate,7]{label=$arabic.$}
setlist[enumerate,8]{label=$alph
.$}
setlist[enumerate,9]{label=$roman*.$}
renewlist{enumerate}{enumerate}{9}
`````

Then use -H deeplists.tex on your pandoc command line. That should be all it takes to get deeply nested lists to work. You need to make sure the enumitem latex package is available.

Exactly what I was looking for, thank you so much for the quick reply!

Is this still valid? I'm continuing to get Too deeply nested errors.

This is how I fixed it (December 2018). I went nine deep and figured I'd be good to go:
usepackage{enumitem}
setlistdepth{9}

setlist[itemize,1]{label=textbullet}
setlist[itemize,2]{label=textbullet}
setlist[itemize,3]{label=textbullet}
setlist[itemize,4]{label=textbullet}
setlist[itemize,5]{label=textbullet}
setlist[itemize,6]{label=textbullet}
setlist[itemize,7]{label=textbullet}
setlist[itemize,8]{label=textbullet}
setlist[itemize,9]{label=textbullet}

renewlist{itemize}{itemize}{9}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timtroendle picture timtroendle  路  3Comments

tolot27 picture tolot27  路  5Comments

johnridesabike picture johnridesabike  路  4Comments

transientsolutions picture transientsolutions  路  3Comments

RyanGreenup picture RyanGreenup  路  4Comments