ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: Custom Table of Contents
Date: Thu, 20 Jan 2022 17:39:16 +0100	[thread overview]
Message-ID: <874f4b12-b7ea-0928-417a-f03ffdcc978d@xs4all.nl> (raw)
In-Reply-To: <36EDA4FC-F41E-43A6-8379-9AE4D53FDDA6@borisov.dev>

[-- Attachment #1: Type: text/plain, Size: 2693 bytes --]

On 1/20/2022 3:45 PM, andrei--- via ntg-context wrote:
> Hi! I’m new to ConTeXt.
> 
> I need to make a custom table of contents that looks like this:
> 
> https://imgur.com/a/Ca3By6X <https://imgur.com/a/Ca3By6X>
> 
> Each row in the table corresponds to an item that has following data to 
> print in the table of contents: page, total number of pages which the 
> item spans, name of the item and a custom text metadata field which is 
> defined by the item. Each item will have its own regular table of 
> content and own structure. So we can think of this TOC as kind of a mega 
> table of content one level above.
> 
> It needs to be fully automatic.
> 
> The actual table is going to be anxtable(which I was blown away by after 
> using LaTeX godawful tables for years, it’s soo good).
> 
> After digging into the documentation (again, wow, it’s soo detailed and 
> approachable after LaTeX😂), I found out that\completecontentdoesn't 
> provide such extreme level of customization. Therefore I need 
> reimplement at least some parts of the default content forming 
> mechanism. After digging in the source a bit, I found something 
> relevant: 
> https://source.contextgarden.net/tex/context/base/mkxl/strc-lst.mklx 
> <https://source.contextgarden.net/tex/context/base/mkxl/strc-lst.mklx>.

there are some examples in the test suite ... if you look into the 
stc-lst files you'll see that one has access to fields and can use setups

> What I need is some guidance on what would be the best course of action, 
> in particular, which API should I use and roughly how should I approach it🙏
> 
> Should I create my own counters for each item and somehow reference 
> those manually in the TOC?
> 
> How would I save additional text metadata field and the item name to 
> show it in the TOC?
> 
> The source code mentions a concept of list renderers. This sounds like 
> the correct API to plug in, but it’s hard for me to grasp how exactly it 
> works.

The problem with tables is that they are multipass and store 
(unexpanded) data so it has not enough info. Attached is an example of 
how to circumvent this (the helpers can be found in the lua file).

(You can then try to add it to the wiki so that it gets documented. The 
lua-context interface wrt TABLE can do the same from the lua end as in 
tex. There are examples of that.)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: tabulated-002.tex --]
[-- Type: text/plain, Size: 1885 bytes --]

\definelistalternative
  [whatever]
  [renderingsetup=whatever]

\setuplist
  [chapter]
  [alternative=whatever]

\startsetups whatever
    \framed [offset=overlay,frame=off] {
        \framed [width=25mm,align=flushleft,frame=off,offset=0pt] {
            number: \currentlistentrynumber
        }
        \framed [width=4cm,align=normal,frame=off,offset=0pt] {
            title: \currentlistentrytitle
        }
        \framed [width=2cm,align=flushleft,frame=off,offset=0pt] {
            page: \currentlistentrypagenumber
        }
        \framed [width=4cm,align=normal,frame=off,offset=0pt] {
            author: \structurelistuservariable{more}
        }
    }
\stopsetups

\starttext

\starttitle[title={Tabulated Table of Contents}]
    \placelist[chapter]
    \blank[2*big]
    \determinelistcharacteristics[chapter]
    \startluacode
        local result = structures.lists.result
        context.bTABLE()
            for i=1,#result do
                local entry = result[i]
                inspect(entry)
                context.bTR()
                    context.bTD()
                        structures.lists.number(entry.metadata.name,i)
                    context.eTD()
                    context.bTD()
                     -- context(entry.titledata.title)
                        structures.lists.title(entry.metadata.name,i)
                    context.eTD()
                    context.bTD()
                        context(entry.userdata.more)
                    context.eTD()
                context.eTR()
            end
        context.eTABLE()
    \stopluacode
\stoptitle

\startchapter[title=One]  [more=ONE]   \samplefile{ward} \stopchapter
\startchapter[title=Two]  [more=TWO]   \samplefile{ward} \stopchapter
\startchapter[title=Three][more=THREE] \samplefile{ward} \stopchapter

\stoptext

[-- Attachment #3: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

      reply	other threads:[~2022-01-20 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 14:45 andrei--- via ntg-context
2022-01-20 16:39 ` Hans Hagen via ntg-context [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=874f4b12-b7ea-0928-417a-f03ffdcc978d@xs4all.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@xs4all.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).