ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Bruce Horrocks via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Bruce Horrocks <ntg@scorecrow.com>
Subject: Re: Setting table of contents depth by number rather than by list
Date: Fri, 24 Dec 2021 23:35:46 +0000	[thread overview]
Message-ID: <4878D762-E665-4096-82C1-3C9308EB5028@scorecrow.com> (raw)
In-Reply-To: <585d8aea-8e50-e4c7-cb62-e9f62506fba0@gmail.com>



> On 24 Dec 2021, at 16:45, Jason Ross via ntg-context <ntg-context@ntg.nl> wrote:
> 
> Dear list,
> 
> Is it possible to set the maximum table of contents depth to a number rather than providing an explicit list of section names?
> 
> 
> Background:
> 
> I am developing an exporter for Org mode. In Org, users can specify the number of levels they want in the table of contents with a number. I currently do this by having the sectioning commands be known to the exporter so I can generate a command like
>    \setupcombinedlist
>      [content]
>      [list={section,subsection}]
> for n=2.
> 
> I'm considering using  \start/stopsectionlevel for sectioning commands instead. That way, users could add \definesectionlevels to the document preamble to use whatever sectioning scheme they wanted. However, this would mean that the exporter wouldn't know what sectioning commands to use the TOC setup.

Can you not specify a full list of sections in your exporter code and then truncate that list to the appropriate value of n before generating the ConTeXt source from the truncated list?

Assuming you are using an Emacs macro to do the export then the following code will return the first 2 from the list of section types:

(let ((list '("part" "chapter" "section" "subsection" "subsubsection" "subsubsubsection" "subsubsubsubsection")))
  (butlast list (- (length list) 2)))

I stole that from StackOverflow so I'll leave it to you work out how to get your depth variable substituted for the 2. :-)

Note that you probably don't want "part" but I include it for completeness. Best to start with "chapter".
—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2021-12-24 23:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24 16:45 Jason Ross via ntg-context
2021-12-24 17:42 ` Denis Maier via ntg-context
2021-12-24 17:49   ` Denis Maier via ntg-context
2021-12-24 17:53     ` Jason Ross via ntg-context
2021-12-24 21:13       ` Denis Maier via ntg-context
2021-12-24 21:20         ` Denis Maier via ntg-context
2021-12-24 21:22           ` Jason Ross via ntg-context
2021-12-24 21:29             ` Denis Maier via ntg-context
2021-12-24 21:37               ` Jason Ross via ntg-context
2021-12-24 21:43                 ` Denis Maier via ntg-context
2021-12-24 21:48                   ` Denis Maier via ntg-context
2021-12-24 21:55                     ` Jason Ross via ntg-context
2021-12-24 23:35 ` Bruce Horrocks via ntg-context [this message]
2021-12-25  0:00 ` Hans Hagen via ntg-context

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=4878D762-E665-4096-82C1-3C9308EB5028@scorecrow.com \
    --to=ntg-context@ntg.nl \
    --cc=ntg@scorecrow.com \
    /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).