At 12:31 AM 7/7/2005, Frank Grieshaber wrote:
Hello all (esp. the ConTeXt-Developers),

some time ago I sent the following email to this list and got no reply so I'm resending it.
Dear all,
I have a manuscript with long nested numbered enumerations and I want the numbers of all levels to be printed automatically like:
1. one
1.1 one-one
1.2 one-two
2. two
2.1 two-one
2.2.1 two-two-one
...
Using the following prints only the current level's number, not all levels:
\startitemize[n,packed]
\item
\item
  \startitemize[m,packed]
  \item
  \item
  \stopitemize
\item
\item
\stopitemize

For Latex there is the package paralist.sty for doing the desired numbering, how can this be done with ConTeXt?

(I wrote this before I noticed that Hans had already replied, but I'm sending this anyway in case someone finds it useful.)

I just accidentally solved this problem, in some of the LaTeX-compatibility stuff that I've been working on. Have a look at t-ltenum.tex for the kernel code that does it, and latextest.tex for an example of how to use it for something akin to that effect. It's fairly self-contained; you should be able to use t-ltenum.tex, t-ltcnts (which does counters) and t-ltbase.tex to get the "LaTeX-style enumerations" working, without needing any of the other bits. All my current files are in this repository:
      http://dpdx.net/context/latex-compat/

That's sort of the long way around to doing what you're looking for, though, and you can get the same effect without the LaTeX-compatibility overhead. Here's the trick....

First, you create a set of "conversions" for each level of the list -- see the Wiki page linked off "Enumerations" for how to do that. The conversion for level one will look something like this:

  \def\listconversioni{%
     \edef\listheadi{\numbers{#1}.}%
     \numbers{#1}}

  \defineconversion[listconvi][\listconversioni]

That returns the list-counter in number form, but it also stores it (with a "." after it) in a "header". (I don't know whether that should be \edef or just \def, but I _think_ \edef is right.)

Then, the conversion for level two looks something like this:

  \def\listconversionii{%
     \edef\listheadii{\listheadi\numbers{#1}.}%
     \listheadi\numbers{#1}}

  \defineconversion[listconvii][\listconversionii]

That does the same thing, but now it's prefixing it with \listheadi. This then continues down the list as deep as you want to go. You then do a \defineitemgroup and some \setupitemgroup commands (again, see the Wiki's "Enumerations" page) to set it so that each one of those is associated with the appropriate level, and off you go; it's all automatic from there.


Depending on whether \startitemize / \stopitemize includes grouping or not (and on exactly where that grouping is placed), it may be possible to do this in a more general form -- have \startitemize execute some code to set \parentlisthead to the current \listhead (which comes from the next level up), and then have one conversion for all levels which uses \parentlisthead and defines a new \listhead to be used on any child itemizations. The trick here is that \stopitemize will (hopefully) contain a \endgroup or \egroup, so that after it the \listhead value will revert to what it was before the corresponding \startitemize. This has the advantage of being able to go arbitrarily deep, but you can't do things like "1.a" where the levels are enumerated differently.


There are, of course, variations on all of these, but that general idea should be enough to get you going.

And I'll second the recommendation that something like this ought go in the kernel; I'm actually rather surprised that it's not already in there!

Actually, what I would specifically suggest is that the \item code should place the converted item counter -- the result of calling \doconversion -- into something like \currentitemlabel, and then \startitemize should move that to \parentitemlabel, all automatically, so one can simply define conversions with \parentitemlabel in them without having to implement the machinery oneself.

Or ... ah, wait; I see that Hans already replied to this shortly after you posted, and I missed it. Oh, well; I'll send this anyway. :)

- Brooks

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to