4

I look for a way to show the first and last values of a counter in the header, like in this question, but for ConTeXt.

If we, at a page break, are in the middle of a problem, I could live with the reference number to be either to the one starting before the current page, or to the first new one on the current page.

If there is only one problem on the page, I would prefer Problem X instead of Problem X-X.

Question Is there a (simple) way of doing this in ConTeXT?

My try:

I found this question, which looks like it could solve my problem, but I have a counter and not a marking with my enumeration. With the naive

\setuppapersize[A6][A5,landscape]
\setuparranging[2SIDE]
\setupheadertexts[{Problem \getnumber[problem][first]--\getnumber[problem][last]}]

\defineenumeration[problem][
text=Problem,
]

\starttext
\dorecurse{4}{\startproblem[problem:\recurselevel]
\samplefile{ward} We are now in problem 
\in[problem:\recurselevel]\stopproblem}
\stoptext

I get the following, unwanted, output (I would expect the left page to have header "Problem 1–2" and the right one to have "Problem 3–4"):

image with a still problematic result

Perhaps the question could be reformulated as:

Question Is there a way to automatically connect a marking to use with the enumeration counter to obtain what I look for?

mickep
  • 8,685

1 Answers1

4

To show the values of the enumerations in the header you have to create a new mark register with the \definemarking command.

To save the value of the counter you have to use the \marking command and pass the counter value as argument. You can hook this assignment into the numbercommand key.

\setuppapersize [A5]

\definemarking [problem]

\setupheadertexts
  [{Problem \getmarking[problem][top]–\getmarking[problem][bottom]}]

\defineenumeration
  [problem]
  [text=Problem,
   numbercommand=\groupedcommand{}{\expanded{\marking[problem]{\rawcountervalue[problem]}}}]

\starttext

\dorecurse{10}
  {\startproblem
   \samplefile{weisman}
   \stopproblem}

\stoptext

enter image description here

Wolfgang Schuster
  • 9,400
  • 1
  • 16
  • 19
  • 2
    I'd use \directconvertedcounter{problem}{number} instead of \rawcountervalue[problem] to respect the numberconversion of the enumeration (here there is none, so it doesn't matter). – Henri Menke Mar 05 '19 at 20:34
  • Thank you, this solution works like a charm. – mickep Mar 06 '19 at 14:34