8

Consider the following MWE:

\definehead[mysec][section]

\starttext
\startsection[title=Test]

\stopsection
\startmysec[title=Test]

\stopmysec
\stoptext

In this case I define a head mysec based on section (in my real use case because I want to copy its formatting, the toc entry etc.). Now this will output

context output

However, I want mysec to be numbered independently (i.e. start from 1). What I have tried:

  • Using several keys, among them resetnumber
  • Having a \resetnumber[mysec] just beforehand.

Question: How can I get an independent numbering for a derived section?

5
  • This is reproducible in beta and LMTX. – TeXnician Oct 23 '19 at 19:50
  • Have you checked the Wiki? – Henri Menke Oct 27 '19 at 20:24
  • @HenriMenke Yes, but unfortunately I did not get that to work with the start/stop syntax (and an own attempt with numbers failed because the toc called it section 1 and it was labelled section 4 in the body part). – TeXnician Oct 27 '19 at 21:24
  • Could you use an enumeration for mysec? – Henri Menke Oct 28 '19 at 0:23
  • @HenriMenke Can this act like a section (e.g. numbered entries to toc and bookmarks to PDF)? – TeXnician Oct 28 '19 at 7:05
6
+50

Section heads in ConTeXt are hierarchical. The default hierarchy is section-1, section-2, ..., section-8, defined in strc-def.mkiv as:

\defineprefixset     [\v!all]  [section-1,section-2,section-3,section-4,section-5,section-6,section-7,section-8] []
% [...]
\definesection[\s!section-1] % part
\definesection[\s!section-2] % chapter
\definesection[\s!section-3] % section
\definesection[\s!section-4] % subsection
\definesection[\s!section-5] % subsubsection
\definesection[\s!section-6] % subsubsubsection
\definesection[\s!section-7] % subsubsubsubsection

These are internal structures. They are are mapped to user-facing section heads using the section key of \definehead:

\definehead
  [\v!part]
  [\c!section=\s!section-1]

\definehead
  [\v!chapter]
  [\c!section=\s!section-2]

\definehead
  [\v!section]
  [\c!section=\s!section-3]

\definehead
  [\v!subsection]
  [\c!section=\s!section-4,
   \c!default=\v!section]

\definehead
  [\v!subsubsection]
  [\c!section=\s!section-5,
   \c!default=\v!subsection]

\definehead
  [\v!subsubsubsection]
  [\c!section=\s!section-6,
   \c!default=\v!subsubsection]

\definehead
  [\v!subsubsubsubsection]
  [\c!section=\s!section-7,
   \c!default=\v!subsubsubsection]

Note that section key can only be set as part of \definehead and cannot be reset using \setuphead. So when you do

\definehead[mysec][section]

The section key is set to section-3 and that is the reason that they share the same counter. So, in principle you could first define your own section and then set it as the section key for your new head:

\definesection[mysection]
\definehead[mysec][section=mysection]

But this will not work. The reason is that the section numbers are expected to be a part of a hierarchy, but the section that we defined is not. So, let's pick one of the existing low-lying numbers, say section-8 (which is actually unused):

\definehead[mysec][section=section-8]

If you want both of them to have the same styling, you can simply set the styling together using setuphead:

\setuphead[section, mysec][ ... ]

which (in a complete examples) gives

enter image description here

Oops, this does not work! What went wrong? Well, section-8 is below section-3, so it gets reset with every new section. So, let's create a reset set that does not reset any section:

\defineresetset[myreset][][0] 

And set this as the resetset:

\definehead[mysec][section=section-8, sectionresetset=myreset]

Adding this to the above example gives:

enter image description here

Much better.

How to handle lists

Let's try a bigger example and see what happens with lists:

\placelist[section,mysec]

enter image description here

What's happening is that mysec is at section level 8, so it is appearing as a subsubsub...subsection of section in the TOC. To pretend that it is a section, we have to ensure that other section levels do not show in the toc entry for mysec. This can be achieved using:

\setuplist[mysec][numbersegments=mysec]

which gives

enter image description here

How to handle references

By default, using \in[ref:mysec] will give the section number followed by mysec number. To get rid of the section number from the reference, use:

\setupreferencestructureprefix[mysec] [default][prefixsegments=8:8]

Here is a complete example:

\defineresetset[myreset][][0] 

\definehead[mysec][section=section-8, sectionresetset=myreset]

\setuplist[mysec][numbersegments=mysec]
\setupreferencestructureprefix[mysec] [default][prefixsegments=8:8]

\setuphead[section, mysec]
          [
            style=\tfa,
            distance=.75\emwidth,
            textdistance=\emwidth plus \emwidth minus .25\emwidth,
            before={\blank[2*big]},
            after=\blank,
          ]



\starttext

\placelist[section, mysec]

\startsection[title=Section, reference=section]

\stopsection
\startmysec[title=My Section]

  Let's check references \in{Section}[section] and \in{My Section}[mysec]
  and \in[mysec2]

\stopmysec
\startsection[title=Section]

\stopsection
\startmysec[title=My Section, reference=mysec]

\stopmysec
\startmysec[title=My Section, reference=mysec2]

\stopmysec

\startsection[title=Section]

\stopsection

\startsection[title=Section]

\stopsection
\startmysec[title=My Section]

\stopmysec
\startmysec[title=My Section]

\stopmysec
\stoptext

What's missing.

So far, I have assumed that there is only one section level. So, how do we handle the case when there is chapter level or a subsection level. The easiest solution will be to hijack section-4 level for mysec and move all other sections one level below.

6
  • Thanks for that comprehensive answer. It works great in my use case. I'm impressed how complicated such a task is in ConTeXt. – TeXnician Nov 3 '19 at 8:04
  • Just a quick question: When giving mysec a label and referencing it with \in the number is printed twice. Is there some easy workaround or should I consider referencing such a section broken? – TeXnician Nov 3 '19 at 8:15
  • @TeXnician: it is complicated because we are trying to work around a design decision in ConText. This would have been simple in Mkii, but other things were complicated (I want to show only sectio.subsection numbers in a subsection head, but chapter.section.subsection number in reference and only subsection number in list: this was very complicated in Mkii but relatively easy in mkiv). But the current design decision means that there cannot be parallel sections. – Aditya Nov 3 '19 at 13:09
  • Okay, thanks for clarifying. Then I will try to avoid doing this in the future :) – TeXnician Nov 3 '19 at 14:53
  • @TeXnician: I added instructions on how to fix referencing. Out of curiosity, what is your use case for such parallel sections? Since they are styled the same as the sections, won't the readers be confused? – Aditya Nov 3 '19 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.