ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* working on page refs with MP
@ 2021-03-18 17:14 Werner Hennrich
  2021-03-18 18:55 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Werner Hennrich @ 2021-03-18 17:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2513 bytes --]

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



[-- Attachment #1.2: Type: text/html, Size: 6100 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: working on page refs with MP
  2021-03-18 17:14 working on page refs with MP Werner Hennrich
@ 2021-03-18 18:55 ` Hans Hagen
  2021-03-19 10:56   ` Werner Hennrich
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2021-03-18 18:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Werner Hennrich

On 3/18/2021 6:14 PM, Werner Hennrich wrote:

> metafun         > log >
> metafun         > log > error: Improper subscript has been replaced by zero
> metapost        > log > <*> ... numeric numFirst; numFirst := \ref [page]
watch closely to the previous log line ... you're missing quotes so mp 
sees \ref [page] and as it ignores a \ it sees ref[page] which unless 
you defined 'ref' and 'page' triggers an error

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: working on page refs with MP
  2021-03-18 18:55 ` Hans Hagen
@ 2021-03-19 10:56   ` Werner Hennrich
  0 siblings, 0 replies; 3+ messages in thread
From: Werner Hennrich @ 2021-03-19 10:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1718 bytes --]

yes I had realized this already but I still don't know how to get those
page numbers down into MP - they keep being strings with macro code instead

is there a way the I can get \setupMPvariables[hdrPgs] in
\setupheadertexts[\setups{page:header}]
to be fully evaluated and stored as the page number in the MPvariables
first= and next= ??

    \startsetups page:header
         \setupMPvariables[hdrPgs]
             [curr=\pagenumber,
             first={\ref[page][\headerfirst]},
             next={\ref[page][\headernext]}]

     I've tried \expanded and \numeric without success

or alternatively in MP how would I call TeX (from MP) with a string like
"\ref[page][a]" and have the page number stored in a numeric var?

Thanks in advance,
Werner


Am 18.03.21 um 19:55 schrieb Hans Hagen:
> On 3/18/2021 6:14 PM, Werner Hennrich wrote:
>
>> metafun         > log >
>> metafun         > log > error: Improper subscript has been replaced
>> by zero
>> metapost        > log > <*> ... numeric numFirst; numFirst := \ref
>> [page]
> watch closely to the previous log line ... you're missing quotes so mp
> sees \ref [page] and as it ignores a \ it sees ref[page] which unless
> you defined 'ref' and 'page' triggers an error
>
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------



[-- Attachment #1.2: Type: text/html, Size: 3710 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-19 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 17:14 working on page refs with MP Werner Hennrich
2021-03-18 18:55 ` Hans Hagen
2021-03-19 10:56   ` Werner Hennrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).