# How to get ConTeXt to display page numbers with chapters in both TOC and footers?

I would like page number appear in both the Table of Contents, and page footers, just like in old Manuals from Digital Equipment Corporation. That is Chapter#--Page#, where pages restart at 1 with each chapter. This is the best I have:

\setuppagenumbering[alternative=doublesided,location=]
\starttext

% with \headnumber[chapter], page number in TOC appears as "-1".
%   TOC appear as "0-1"
\definestructureconversionset[frontpart:pagenumber][][romannumerals]
\setuppagenumber[way=bychapter,numberconversionset=pagenumber]

\setuplist[chapter][alternative=f,style=\ssb]
\setuplist[section][alternative=c,pageconversionset=pagenumber]
\setupfootertexts%
[{{\bf\userpagenumber}~~\getmarking[chapter][first]}]%
[]%
[]%
[{\getmarking[chapter][first]~~{\bf\userpagenumber}}]

% with \startsectionblockenvironment[frontpart] ConTeXt fails to produce
%   any output, or error message.
\startfrontmatter
\setupinterlinespace[small]
\placecontent[criterium=all]
\startsection[title=Preface]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter
\stopfrontmatter

\startbodymatter
\setcounter[userpage][1]

\startchapter[title=This is my chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is my section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\startchapter[title=This is another chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is another section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\stopbodymatter
\stoptext


I've used \startfrontmatter over \startsectionblockenvironment[frontpart] because ConTeXt cycles once with the latter, and produces no output or error message. The calling of the page conversion seems to work with \startfrontmatter, only I can't find any place that the chapter number is defined at the time of producing the table of contents.

Using ConTeXt version 2019.03.21 21:39, LuaTeX version 1.10.0 (Tex Live 2019) on macOS 10.14.6.

You mix up the following two commands:

• \startsectionblock[⟨NAME〉] ... \stopsectionblock and
• \startsectionblockenvironment[⟨NAME〉] ... \stopsectionblockenvironment.

The sectionblock environment is the same as the bodypart environment but you pass the name of the sectionblock as argument of the start-command. The sectionblockenvironment environment is used to set options which are used at the begin of a certain sectionblock and you put it in the preamble of your document.

To get the chapter value in front of the page number you have to enable the prefix for the userpagenumber (the \setuppagenumber command is a synonym for \setupuserpagenumber).

\setupuserpagenumber
[way=bychapter,
prefix=yes,
prefixset=chapter,
prefixsegments=chapter]

\setuppagenumbering
[alternative=doublesided,
location=none]

\setupfootertexts
[{\prefixedpagenumber\hspace[medium]\getmarking[chapter][first]}]
[]
[]
[{\getmarking[chapter][first]\hspace[medium]\prefixedpagenumber}]

\setuplist
[chapter]
[alternative=f]

\setuplist
[section]
[alternative=c,
pageprefix=yes,
pageprefixsegments=chapter]

\defineconversionset [frontpart:pagenumber] [] [i]
\defineconversionset  [bodypart:pagenumber] [] [n]

[section]
[number=no]

\starttext

\startfrontmatter

\completecontent

\stopfrontmatter

\startbodymatter

\dorecurse{2}
{\chapter{Chapter \convertnumber{word}{#1}}
\dorecurse{4}
{\section{Section ##1}
\dorecurse{3}{\samplefile{weisman}}}}

\stopbodymatter

\stoptext


Answering my own question (although, I'm not entirely sure why this works). It relies upon \setupuserpagenumber[ prefixsegments=chapter ] which is missing from most documentation:

\setuppagenumbering[alternative=doublesided,location=]
\starttext

\definestructureprefixset[pageprefix][chapter][] % ch--pg in \userpage footers
\setuplist[chapter][alternative=f,style=\ssb]
\setuplist[section][alternative=c,pageconversionset=pagenumber]
\setupfootertexts%
[{{\bf\userpagenumber}~~\getmarking[chapter][first]}]%
[]%
[]%
[{\getmarking[chapter][first]~~{\bf\userpagenumber}}]

\startfrontmatter
\setupuserpagenumber[numberconversion=romannumerals]

\setupinterlinespace[small]
\placecontent[criterium=all]
\startsection[title=Preface]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter
\stopfrontmatter

\startbodymatter
\setupuserpagenumber[way=bychapter,prefix=yes,
prefixsegments=chapter, % ch--pg in ToC
prefixset=pageprefix,   % ch--pg in \userpage footers
numberconversion=numbers]
\setcounter[userpage][1]

\startchapter[title=This is my chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is my section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\startchapter[title=This is another chapter title]
\dorecurse{20}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is another section title]
\dorecurse{20}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\stopbodymatter
\stoptext