Sunday, 18 August 2013

How to obtain formatted page number in ConTeXt?

How to obtain formatted page number in ConTeXt?

Problem
The \pagenumber macro does not reflect the conversion attribute value
within the context of front matter vs. body matter. The front matter uses
Roman numerals, the body matter uses regular text.
Code
A minimum working example to show the problem:
\setuppapersize[letter][letter]
% See: http://tex.stackexchange.com/a/128858/2148
\setuplayout[
% Allow text to be flush with the top
topspace=\zeropoint,
% Stretch the text to its maximum (to place page number at very bottom)
height=fit,
% Allow text to be flush with the bottom
footerdistance=\zeropoint,
]
\setupcolors[state=start]
\definecolor[colourhighlight][h=F5F6CE]
\definecolor[colourtocseparator][colourtertiary]
% Use Roman numerals for the front matter
\definestructureconversionset[frontpart:pagenumber] [] [romannumerals]
% Put a coloured box around the page number
\setuppagenumbering[
command={\inframed[
frame=no,
background=color,
backgroundcolor=colourhighlight,
width=2em,
height=2em,
]{\pagenumber}},
]
% Right-align the page number in the footer and assume single-sided pages
\setuppagenumbering[location={footer,right,margin},alternative=singlesided]
% Do not define a double-sided document environment.
% See: http://tex.stackexchange.com/a/122349/2148
\setupmakeup[standard][page=yes, doublesided=no]
\starttext
\startfrontmatter
\setuppagenumbering[conversion=romannumerals]
\setcounter[userpage][1]
% Title page (front cover)
\startstandardmakeup
Title page
\stopstandardmakeup
% Copyright page
\startstandardmakeup
Copyright
\stopstandardmakeup
% Table of Contents
\completecontent
\stopfrontmatter
\startbodymatter
\setuppagenumbering[conversion=numbers]
\setcounter[userpage][2]
\startchapter[
title={chapter},
reference=sec:chapter,
]
\input knuth
\stopchapter
\stopbodymatter
\stoptext
Actual Results
The output for the front matter shows the normal page number (this is not
desirable: it should be a roman numeral) beside the page number converted
to a Roman numeral:

The output for the body matter shows the normal page number (this is
desirable) beside the page number converted to a regular number:

Expected Results
I was expecting the page number to keep the context of the conversion
value, thus showing up as a roman numeral within the \inframed macro. I am
trying to accomplish the following in the front matter:

If possible, I'd rather avoid creating a layer.
Question
How can you create a page number in a \framed (or \inframed) that is
formatted according to the conversion value specified by:
\setuppagenumbering[conversion=romannumerals]
Related
Eliminate topspace and bottomspace in ConTeXt

No comments:

Post a Comment