ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Custom Table of Contents
@ 2022-01-20 14:45 andrei--- via ntg-context
  2022-01-20 16:39 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: andrei--- via ntg-context @ 2022-01-20 14:45 UTC (permalink / raw)
  To: ntg-context; +Cc: andrei


[-- Attachment #1.1: Type: text/plain, Size: 1763 bytes --]

Hi! I’m new to ConTeXt.

I need to make a custom table of contents that looks like this:

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 an xtable (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 \completecontent doesn'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>.


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.



Any help will be appreciated! Thank you in advance!

Stay safe,
Andrei Borisov.

[-- Attachment #1.2: Type: text/html, Size: 15417 bytes --]

[-- Attachment #2: 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Custom Table of Contents
  2022-01-20 14:45 Custom Table of Contents andrei--- via ntg-context
@ 2022-01-20 16:39 ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen via ntg-context @ 2022-01-20 16:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-20 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 14:45 Custom Table of Contents andrei--- via ntg-context
2022-01-20 16:39 ` Hans Hagen via ntg-context

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).