Document structure and headlines/Collections of tips and tricks

Unofficial ConTeXt Wiki mirror

Last modified: 2025-01-18

Define your own sectioning commands

Of course you can define your own sectioning commands and probably want to adapt the default settings.

A new header \myheader is defined and it inherits the properties of \section (title, subject, whatever). You can define or setup several headers at once!

Section variable

You can set custom variables per section, and retrieve them with the \structureuservariable command:

Beware, if you want to reference these in your ToC setup, you need \structurelistuservariable.

Access to head number

To access the last head number in a document one can use:

\someheadnumber[][]

The following example from the mailing list demonstrates how to use it.

For using inside a Metapost-environment you can use the expandable version:

\somenamedheadnumber{}{}

Willi's comment on 15-06-2011: Sinds Context 13 june 2011 the name \somestructureheadnumber is replaced by \someheadnumber. This is in line with Hans' plans to get rid of the 'structure' part inside interface-names dealing with internal counters.

Generate a sorted of authors from headline content

An example on how to generate a sorted list of all authors contributed to a conference proceeding.


TODO: does no compile as of 2025.01.18 (See: To-Do List)
\setuphead
  [title]
  [page=no,command=,]

\setuphead
  [chapter]
  [command=\MyChapCMD]

\setuplist
  [chapter]
  [criterium=all,alternative=command,command=\MyChapListCMD]

\definesorting[author][authors]
\setupsorting [author][criterium=all,expansion=yes]

\define[2]\MyChapCMD
 {#1\enspace #2
   {\doifsomething
      {\structureuservariable{author}}
      \expanded{\author
        [\structureuservariable{name}] % -> sorted by "name"-variable
        {\bTABLE[width=broad]
           \bTR
             \bTD \structureuservariable{author} \eTD
             \bTD \structureuservariable{city}   \eTD
             \bTD \structureuservariable{date}   \eTD
             \bTD \structureuservariable{email}  \eTD
             \bTD \structureuservariable{note}   \eTD
           \eTR
         \eTABLE\nointerlineskip}%
         \tfxx (\structureuservariable{author}, \structureuservariable{city})}}}

\define[3]\MyChapListCMD
  {#1 #2 (\structurelistuservariable{author})\hfill  #3\blank}


\starttext  \showframe[text]

\starttitle[title=Contents]
  \placelist[chapter]
\stoptitle

\starttitle[title=List of Authors in Alphabetical Order]
  \placelistofauthors
\stoptitle

\startchapter
  [title=Text by Ward]
  [name=ward,
   author=Peter D. Ward,
   city=Washington,
   email=ward@sample.com]

  \input ward
\stopchapter

\startchapter
  [title=Text by Zapf]
  [name=zapf,
   author=Hermann Zapf,
   city=Nürnberg,
   date=8. November 1918,
   email=zapf@sample.de]

  \input zapf
\stopchapter

\startchapter
  [title=Text by Bryson]
  [name=bryson,
   author=Bill Bryson,
   city=Norfolk,
   date={December 8, 1951},
   note=best-selling American author]

  \input Bryson
\stopchapter

\startchapter
  [title=Text by Tufte]
  [name=tufte,
   author=Edward R. Tufte,
   city=Kansas City,
   date=1942,
   note=has criticized the way Microsoft PowerPoint is typically used]

  \input tufte
\stopchapter

\stoptext