[NTG-context] working on page refs with MP

Werner Hennrich wehe at gmx.at
Thu Mar 18 18:14:00 CET 2021


Hello everyone,

I'm having page references and want to calc / draw 'Page x of y' for
some subsections in MP.
How can I pass 'em down so I end up with numbers to do calculations with?

    \setuplayout[header=15mm]
    \def\myHeader[#1]#2{
    \ignorespaces
    \getdummyparameters[ref=,next=,#1]
    \pagebreak[yes]
    \pagereference[\dummyparameter{ref}]
    \doassign[header][first=\dummyparameter{ref}]
    \doassign[header][next=\dummyparameter{next}]
    {\tfc\bf{#2}}\par
    \vskip3mm
    }
    \def\fillWithText[#1]{
    \dorecurse{#1}{
    \input tufte
    \input knuth
    }
    }
    \setupheadertexts[\setups{page:header}]%
    \startsetups page:header
    \setupMPvariables[hdrPgs]
    [curr=\pagenumber,
    first={\ref[page][\headerfirst]},
    next={\ref[page][\headernext]}]
    \framed[
    frame=off,
    background={hdrPgs}
    ]{}% all to be done in MP
    \stopsetups
    \defineoverlay[hdrPgs][\useMPgraphic{hdrPgs}]
    \startuseMPgraphic{hdrPgs}
    StartPage; % calc and draw 'Page x of y'....
    numeric numCurr; numCurr := \MPvar{curr};
    string strFirst; strFirst := "\MPvar{first}";
    string strNext; strNext := "\MPvar{next}";
    message("=======================");
    message("MP_hdrPageNrs: curr="& tostring numCurr & ", sFirst="&
    strFirst & ", sNext="& strNext);
    % fails:
    numeric numFirst; numFirst := \MPvar{first};
    StopPage;
    \stopuseMPgraphic
    \starttext
    \myHeader[ref=a,next=b]{AAAA aaaa AaAaAaAa}
    \fillWithText[10]
    \myHeader[ref=b,next=c]{BBBB bbbb BbBbBbBbBb}
    \fillWithText[3]
    \myHeader[ref=c,next=d]{CCCC ccccc CcCcCcCc}
    \fillWithText[8]
    \myHeader[ref=c,next=last]{DDDD ddddd DdDdDdDdDd}
    \fillWithText[8]
    \pagebreak[yes]
    \pagereference[last]
    This is the last page, goodby
    \stoptext

metapost        > message : MP_hdrPageNrs: curr=1, sFirst=\ref
[page][a], sNext=\ref [page][b]
metafun         > log >
metafun         > log > error: Improper subscript has been replaced by zero
metapost        > log > <*> ... numeric numFirst; numFirst := \ref [page]
metafun         > log >
metafun         > log > A bracketed subscript must have a known numeric
value;

So MP gets the macro and tries array access... I tried \expanded,
\numeric, and resolving the page numbers via \ref[page][id] at the
various code levels - unsuccessfully so far - and out of wit now.

TIA, Werner


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20210318/1b29f3ca/attachment-0001.htm>


More information about the ntg-context mailing list