ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Brooks Moses <bmoses@stanford.edu>
Subject: Re: enumerated lists
Date: Thu, 04 Aug 2005 11:14:22 -0700	[thread overview]
Message-ID: <4.3.1.2.20050804011251.01c63008@cits1.stanford.edu> (raw)
In-Reply-To: <42CCDA63.8000204@online-resourcen.de>

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

      parent reply	other threads:[~2005-08-04 18:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-01 19:40 Frank Grieshaber
2005-07-07  7:31 ` Frank Grieshaber
2005-07-07  8:15   ` Taco Hoekwater
2005-07-07 20:32   ` Mojca Miklavec
2005-07-08  8:05     ` Hans Hagen
2005-07-08 12:13   ` Radhelorn
2005-08-04 18:14   ` Brooks Moses [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4.3.1.2.20050804011251.01c63008@cits1.stanford.edu \
    --to=bmoses@stanford.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).