1

I'm working on the ConTeXt layout of a document that should have chapters (but not sections) numbered from zero. The body text is being converted with pandoc from markdown pulled from a github repository, so I'm looking for a simple command that I can use before \starttext.

The numbering structure should look like this:

A table of contents showing the first chapter numbered 0 with sections numbered 0.1 and 0.2, and the second chapter numbered 1 with sections numbered 1.1 and 1.2

Something like this MWE seems like it should do what I want, but the output is still numbered starting from 1:

\setcounter[chapter][0]

\starttext

\chapter{Zero Unit}
  \input knuth

\chapter{One More Time}
  \input knuth

\stoptext

Output of the preceding code. "Zero Unit" is numbered 1 instead of 0, "One More Time" is numbered 2 instead of 1.

Using \setcounter[chapter][-1] doesn't work any better.

Consulting the ConTeXt Manual (2013) I found a reference for \setupheadnumber. However this does not work either, as the numbering is for some reason suppressed if a section has zero-valued number:

\setupheadnumber[chapter][-1]

\starttext

\chapter{Zero Unit}
  \input knuth
  \section{Inner Zero.One}

\chapter{One More Time}
  \input knuth
  \section{Inner One.One}

\stoptext

enter image description here

enter image description here

That output is especially bad since it conflates the numbering of Chapter 0, section 0.1 with Chapter 1.

I know about using ownnumber= in sectioning commands, but that would require writing a filter for pandoc that calculates and embeds it throughout the context output, and I'd really like to avoid that. With \setupheadnumber I could get 99% of the way there and manually set the number in the body text for Chapter Zero, but again I would like to avoid programmatic or manual edits to the body text.

Is it possible to start chapter/section numbering from zero using only commands before \starttext?

2
  • You could also think about the reason why a chapter should start at 0. The reader doesn't expect this and I see no advantage. I know that this comment is off topic, but I could not resist. Sep 28, 2020 at 8:14
  • @HaraldLichtenstein I know, it's weird and a pain. But it's is a hard requirement of the document style and isn't something I can alter. (The zero-based numbering scheme is being used as the bug-reporting reference during ongoing development of the text.) It's also a common enough request for other TeX-based engines, so it's only fair that ConTeXt fans get to do it too. :) Sep 28, 2020 at 16:57

2 Answers 2

3

The mailing list https://www.mail-archive.com/ntg-context@ntg.nl/msg79582.html says that it is not possible to set the counter to zero, but you can change the appearance so that 1 looks like 0. Imho a rather odd solution but it seems to work:

\defineexpandable[1]\PreviousNumber
   {\number\numexpr#1-1\relax}

\defineconversion[PreviousNumber][\PreviousNumber]

\defineconversionset[zerostart][n,PreviousNumber][n]

\setuphead[chapter,section][sectionconversionset=zerostart]

\starttext

 \chapter{Zero}

 \chapter{One}

\stoptext

As of sometime after August 2018, the conversion zero is already defined, so now you can use the slightly shorter:

\defineconversionset[zerostart][n,zero][n]

\setuphead[chapter,section][sectionconversionset=zerostart]

\starttext

 \chapter{Zero}

 \chapter{One}

\stoptext
3
  • There is no need to create a new number conversion because ConTeXt already provides one for this with the name zero, to use it change the definition of the conversionet to \defineconversionset [zerostart] [n,zero] [n]. Sep 28, 2020 at 14:00
  • 1
    @WolfgangSchuster I simply copied from your message (but as it was from 2015 it is quite possible that something changed ;-)). Sep 28, 2020 at 14:12
  • Perfect! This does the job, and as much as it seems to be just disguising the number, for all intents so far it seems to work as if the real counter starts from zero, particularly in correctly showing up in section numbering. Sep 28, 2020 at 17:08
0

To start from 0 count, you need to provide -1 in the chapter counter. As shown below:

\documentclass{book}

\usepackage[margin=1in]{geometry}

\setcounter{chapter}{-1}

\begin{document}
    \chapter{Zero}
    
    \chapter{One}
\end{document}

Chapter 0

chapter one

1
  • Sorry, it's a ConTeXt question. I know it's easy in LaTeX, which is why I'm hopeful there's an answer for ConTeXt. Sep 28, 2020 at 4:40

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.