Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a command set that allows me to do something like

\nestedlist{
  \listitem An item
  \sublist{
    \listitem A sub item
    \listitem Another sub item
  }
}

and get

  1. An item
    1.1 A sub item
    1.2 Another sub item

etc, but with infinite depth (that is, I want to be able to use \sublist recursively, without specifying on beforehand how many nesting levels are allowed, or having to write extra code to allow another level).

I tried an approach with one counter to keep track of the current depth, and one per nesting level to keep track of the numbers. However, when I try to create the number counters with

\newcounter{n\arabic{depth}}

I get an error the second time I reach a nesting level, since the counter is already defined. Is there any way to check if the counter is already defined, and if it is just set it to zero (or whatever number is appropriate)?

And as a side note: Is there already some package where this functionality is provided? My requirements are that there should be no limit on the nesting depth, and on each item, the entire "breadcrumb" should be shown as the bullet.

share|improve this question

1 Answer 1

up vote 16 down vote accepted

The paralist package provides the package option pointedenum (or pointlessenum depending on whether you want 1.1.1. or 1.1.1) that makes the enumerate environment behave in exactly this way. If you only want to use this on some enums, you can define (with paralist loaded)

\newenvironment{myenum}%
{\pointedenum\begin{enumerate}}%
{\end{enumerate}}

The same works with \pointlessenum.

share|improve this answer
    
Perfect - this does what I want, I don't have to code it myself, and it is common enough to already be installed on the IT system I have no control over! =) –  Tomas Lycken Aug 3 '10 at 20:31
    
But the depth is not unlimited. Any idea to have unlimited depth ? –  Ludovic Kuty Dec 30 '11 at 19:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.