[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?

    \input tufte
    \input knuth
    \startsetups page:header
    ]{}% all to be done in MP
    StartPage; % calc and draw 'Page x of y'....
    numeric numCurr; numCurr := \MPvar{curr};
    string strFirst; strFirst := "\MPvar{first}";
    string strNext; strNext := "\MPvar{next}";
    message("MP_hdrPageNrs: curr="& tostring numCurr & ", sFirst="&
    strFirst & ", sNext="& strNext);
    % fails:
    numeric numFirst; numFirst := \MPvar{first};
    \myHeader[ref=a,next=b]{AAAA aaaa AaAaAaAa}
    \myHeader[ref=b,next=c]{BBBB bbbb BbBbBbBbBb}
    \myHeader[ref=c,next=d]{CCCC ccccc CcCcCcCc}
    \myHeader[ref=c,next=last]{DDDD ddddd DdDdDdDdDd}
    This is the last page, goodby

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

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