ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Struggling with startuseMPgraphic and string argument!
@ 2020-09-16 14:32 Geert Verhaag
  2020-09-17  8:01 ` Hans Hagen
  2020-09-17 19:41 ` Geert Verhaag
  0 siblings, 2 replies; 5+ messages in thread
From: Geert Verhaag @ 2020-09-16 14:32 UTC (permalink / raw)
  To: ntg-context


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

Hi,

I'm trying to pass a string argument value to an MPgraphic but it 
doesn't seem to work:

Tried the following:

\startuseMPgraphic{name}{lbl}
   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
\stopuseMPgraphic

\starttext
   \useMPgraphic{name}{lbl=1}
\stoptext

The above works as expected!

But the following doesn't:

\startuseMPgraphic{name}{lbl}
   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
\stopuseMPgraphic

\starttext
   \useMPgraphic{name}{lbl=abc}
\stoptext

It yields:

  1 \startuseMPgraphic{name}{lbl}
  2       pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
  3     \stopuseMPgraphic
  4
  5     %\startuseMPgraphic{name}fill fullcircle scaled 200pt withcolor 
.625yellow ;\stopuseMPgraphic
  6
  7     \starttext
  8      Example:
  9 >>    \useMPgraphic{name}{lbl=abc}
10     \stoptext
11

<to be read again>
a
\m_meta_current_variable a-a
                             bc
<argument> ... \hbox {\scratchdimen \m_meta_current_variable
                                                   sp}\ifzeropt \wd 
\b_meta_v...
\secondoftwoarguments #1#2b-#2

\9>>1 #1,2-\meta_prepare_instance_variable {#1}
\syst_helpers_do_process_comm...
\syst_helpers_do_process_comma_list ...rgument #1,
                                                   ]\relax \global 
\advance \...
...
l.9   \useMPgraphic{name}{lbl=abc}

So it seems that only numbers can be passed not character strings! Why 
is that? Is there a possibility to achieve this functionality?

Regards,
Gerard


[-- Attachment #1.2: Type: text/html, Size: 3467 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] 5+ messages in thread

* Re: Struggling with startuseMPgraphic and string argument!
  2020-09-16 14:32 Struggling with startuseMPgraphic and string argument! Geert Verhaag
@ 2020-09-17  8:01 ` Hans Hagen
  2020-09-17 19:41 ` Geert Verhaag
  1 sibling, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2020-09-17  8:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Geert Verhaag

On 9/16/2020 4:32 PM, Geert Verhaag wrote:
> Hi,
> 
> I'm trying to pass a string argument value to an MPgraphic but it 
> doesn't seem to work:
> 
> Tried the following:
> 
> \startuseMPgraphic{name}{lbl}
>    pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
> \stopuseMPgraphic
> 
> \starttext
>    \useMPgraphic{name}{lbl=1}
> \stoptext
> 
> The above works as expected!
> 
> But the following doesn't:
> 
> \startuseMPgraphic{name}{lbl}
>    pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
> \stopuseMPgraphic
> 
> \starttext
>    \useMPgraphic{name}{lbl=abc}
> \stoptext
> 
> It yields:
> 
>   1 \startuseMPgraphic{name}{lbl}
>   2       pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>   3     \stopuseMPgraphic
>   4
>   5     %\startuseMPgraphic{name}fill fullcircle scaled 200pt withcolor 
> .625yellow ;\stopuseMPgraphic
>   6
>   7     \starttext
>   8      Example:
>   9 >>    \useMPgraphic{name}{lbl=abc}
> 10     \stoptext
> 11
> 
> <to be read again>
> a
> \m_meta_current_variable a-a
>                              bc
> <argument> ... \hbox {\scratchdimen \m_meta_current_variable
>                                                    sp}\ifzeropt \wd 
> \b_meta_v...
> \secondoftwoarguments #1#2b-#2
> 
> \9>>1 #1,2-\meta_prepare_instance_variable {#1}
> \syst_helpers_do_process_comm...
> \syst_helpers_do_process_comma_list ...rgument #1,
>                                                    ]\relax \global 
> \advance \...
> ...
> l.9   \useMPgraphic{name}{lbl=abc}
> 
> So it seems that only numbers can be passed not character strings! Why 
> is that? Is there a possibility to achieve this functionality?
magic:

\startuseMPgraphic{name}{s::lbl}
   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
\stopuseMPgraphic

\starttext
   \useMPgraphic{name}{lbl=abc}
   \useMPgraphic{name}{lbl=def}
\stoptext

-----------------------------------------------------------------
                                           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] 5+ messages in thread

* Re: Struggling with startuseMPgraphic and string argument!
  2020-09-16 14:32 Struggling with startuseMPgraphic and string argument! Geert Verhaag
  2020-09-17  8:01 ` Hans Hagen
@ 2020-09-17 19:41 ` Geert Verhaag
  2020-09-18  7:03   ` Hans Hagen
  1 sibling, 1 reply; 5+ messages in thread
From: Geert Verhaag @ 2020-09-17 19:41 UTC (permalink / raw)
  To: ntg-context


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

Hi ConTeXt users,

That's indeed magic and it works! Hans, thanks for your prompt answer!

But I would like to take this a step further, by introducing a macro 
within the start/stopuseMPgraphic structure like so:

\startuseMPgraphic{name}{s::lbl}
   def mymacro (text lb) =
     pair a ; a := (3cm,3cm) ;label.top("String: " & str lb,a) ;
   enddef ;
   mymacro(\MPvariable{lbl}) ;
\stopuseMPgraphic

and this works too, but what if I introduce another text argument like:

\startuseMPgraphic{name}{s::lbl,s::label}
   def mymacro (text lb,lbx) =
     pair a ; a := (3cm,3cm) ;label.top("String: " & str lb & ", " & str 
lbx,a) ;
   enddef ;
   mymacro(\MPvariable{lbl},\MPvariable{label}) ;
\stopuseMPgraphic

However this doesn't work!  It gives the following error:

! Missing argument to mymacro.

Isn't that weird? But perhaps it has to do with me not understanding 
argument passing properly within METAPOST macros!

Can someone please explain why this 2 argument example doesn't work?

(But maybe this isn't the proper list to ask questions like these. If 
so, I'm sorry for bothering you!)

Regards,
Gerard


On 16-09-2020 16:32, Geert Verhaag wrote:
>
> Hi,
>
> I'm trying to pass a string argument value to an MPgraphic but it 
> doesn't seem to work:
>
> Tried the following:
>
> \startuseMPgraphic{name}{lbl}
>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
> \stopuseMPgraphic
>
> \starttext
>   \useMPgraphic{name}{lbl=1}
> \stoptext
>
> The above works as expected!
>
> But the following doesn't:
>
> \startuseMPgraphic{name}{lbl}
>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
> \stopuseMPgraphic
>
> \starttext
>   \useMPgraphic{name}{lbl=abc}
> \stoptext
>
> It yields:
>
>  1 \startuseMPgraphic{name}{lbl}
>  2       pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>  3     \stopuseMPgraphic
>  4
>  5     %\startuseMPgraphic{name}fill fullcircle scaled 200pt withcolor 
> .625yellow ;\stopuseMPgraphic
>  6
>  7     \starttext
>  8      Example:
>  9 >>    \useMPgraphic{name}{lbl=abc}
> 10     \stoptext
> 11
>
> <to be read again>
> a
> \m_meta_current_variable a-a
>                             bc
> <argument> ... \hbox {\scratchdimen \m_meta_current_variable
>                                                   sp}\ifzeropt \wd 
> \b_meta_v...
> \secondoftwoarguments #1#2b-#2
>
> \9>>1 #1,2-\meta_prepare_instance_variable {#1}
> \syst_helpers_do_process_comm...
> \syst_helpers_do_process_comma_list ...rgument #1,
>                                                   ]\relax \global 
> \advance \...
> ...
> l.9   \useMPgraphic{name}{lbl=abc}
>
> So it seems that only numbers can be passed not character strings! Why 
> is that? Is there a possibility to achieve this functionality?
>
> Regards,
> Gerard
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________


-- 

Sender:G.C.H.M. Verhaag
St. Jorisstraat 29
5954 AN Beesel
NETHERLANDS

       Tel.: +31-(0)619502702, E-mail: verhaaggchm@ziggo.nl

Ik vertrouw erop dat de persoonlijke gegevens, te vinden in deze mail,
uitsluitend voor correspondentie met ondergetekende worden gebruikt en
beslist niet voor reclamedoeleinden of welke andere wijze dan ook. Het
opnemen van deze gegevens, in welk soort van opslagsysteem dan ook,
evenals het doorgeven ervan aan derden, zie ik als een schending van
mijn privacy.

	


[-- Attachment #1.2.1: Type: text/html, Size: 9713 bytes --]

[-- Attachment #1.2.2: pasfoto_17112017_cropped_113x78_72dpi.png --]
[-- Type: image/png, Size: 15518 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] 5+ messages in thread

* Re: Struggling with startuseMPgraphic and string argument!
  2020-09-17 19:41 ` Geert Verhaag
@ 2020-09-18  7:03   ` Hans Hagen
  2020-09-18 11:48     ` Geert Verhaag
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2020-09-18  7:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Geert Verhaag

On 9/17/2020 9:41 PM, Geert Verhaag wrote:
> Hi ConTeXt users,
> 
> That's indeed magic and it works! Hans, thanks for your prompt answer!
> 
> But I would like to take this a step further, by introducing a macro 
> within the start/stopuseMPgraphic structure like so:
> 
> \startuseMPgraphic{name}{s::lbl}
>    def mymacro (text lb) =
>      pair a ; a := (3cm,3cm) ;label.top("String: " & str lb,a) ;
>    enddef ;
>    mymacro(\MPvariable{lbl}) ;
> \stopuseMPgraphic
> 
> and this works too, but what if I introduce another text argument like:
> 
> \startuseMPgraphic{name}{s::lbl,s::label}
>    def mymacro (text lb,lbx) =
>      pair a ; a := (3cm,3cm) ;label.top("String: " & str lb & ", " & str 
> lbx,a) ;
>    enddef ;
>    mymacro(\MPvariable{lbl},\MPvariable{label}) ;
> \stopuseMPgraphic
> 
> However this doesn't work!  It gives the following error:
> 
> ! Missing argument to mymacro.
> 
> Isn't that weird? But perhaps it has to do with me not understanding 
> argument passing properly within METAPOST macros!
> 
> Can someone please explain why this 2 argument example doesn't work?
> 
> (But maybe this isn't the proper list to ask questions like these. If 
> so, I'm sorry for bothering you!)
> 
> Regards,
> Gerard
> 
> 
> On 16-09-2020 16:32, Geert Verhaag wrote:
>>
>> Hi,
>>
>> I'm trying to pass a string argument value to an MPgraphic but it 
>> doesn't seem to work:
>>
>> Tried the following:
>>
>> \startuseMPgraphic{name}{lbl}
>>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>> \stopuseMPgraphic
>>
>> \starttext
>>   \useMPgraphic{name}{lbl=1}
>> \stoptext
>>
>> The above works as expected!
>>
>> But the following doesn't:
>>
>> \startuseMPgraphic{name}{lbl}
>>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>> \stopuseMPgraphic
>>
>> \starttext
>>   \useMPgraphic{name}{lbl=abc}
>> \stoptext
>>
>> It yields:
>>
>>  1 \startuseMPgraphic{name}{lbl}
>>  2       pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>>  3     \stopuseMPgraphic
>>  4
>>  5     %\startuseMPgraphic{name}fill fullcircle scaled 200pt withcolor 
>> .625yellow ;\stopuseMPgraphic
>>  6
>>  7     \starttext
>>  8      Example:
>>  9 >>    \useMPgraphic{name}{lbl=abc}
>> 10     \stoptext
>> 11
>>
>> <to be read again>
>> a
>> \m_meta_current_variable a-a
>>                             bc
>> <argument> ... \hbox {\scratchdimen \m_meta_current_variable
>>                                                   sp}\ifzeropt \wd 
>> \b_meta_v...
>> \secondoftwoarguments #1#2b-#2
>>
>> \9>>1 #1,2-\meta_prepare_instance_variable {#1}
>> \syst_helpers_do_process_comm...
>> \syst_helpers_do_process_comma_list ...rgument #1,
>>                                                   ]\relax \global 
>> \advance \...
>> ...
>> l.9   \useMPgraphic{name}{lbl=abc}
>>
>> So it seems that only numbers can be passed not character strings! Why 
>> is that? Is there a possibility to achieve this functionality?
\startuseMPgraphic{name}{s::lbl,s::label}
     def mymacro(expr a, b) =
         label.top("str:(" & a & "," & b & ")",(3cm,3cm)) ;
     enddef ;
     mymacro("\MPvariable{lbl}","\MPvariable{label}")
\stopuseMPgraphic

\starttext
   \useMPgraphic{name}{lbl=abc,label=pqr}
   \useMPgraphic{name}{lbl=def,label=xyz}
\stoptext

-----------------------------------------------------------------
                                           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] 5+ messages in thread

* Re: Struggling with startuseMPgraphic and string argument!
  2020-09-18  7:03   ` Hans Hagen
@ 2020-09-18 11:48     ` Geert Verhaag
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Verhaag @ 2020-09-18 11:48 UTC (permalink / raw)
  To: Hans Hagen, mailing list for ConTeXt users

On 18-09-2020 09:03, Hans Hagen wrote:
> On 9/17/2020 9:41 PM, Geert Verhaag wrote:
>> Hi ConTeXt users,
>>
>> That's indeed magic and it works! Hans, thanks for your prompt answer!
>>
>> But I would like to take this a step further, by introducing a macro 
>> within the start/stopuseMPgraphic structure like so:
>>
>> \startuseMPgraphic{name}{s::lbl}
>>    def mymacro (text lb) =
>>      pair a ; a := (3cm,3cm) ;label.top("String: " & str lb,a) ;
>>    enddef ;
>>    mymacro(\MPvariable{lbl}) ;
>> \stopuseMPgraphic
>>
>> and this works too, but what if I introduce another text argument like:
>>
>> \startuseMPgraphic{name}{s::lbl,s::label}
>>    def mymacro (text lb,lbx) =
>>      pair a ; a := (3cm,3cm) ;label.top("String: " & str lb & ", " & 
>> str lbx,a) ;
>>    enddef ;
>>    mymacro(\MPvariable{lbl},\MPvariable{label}) ;
>> \stopuseMPgraphic
>>
>> However this doesn't work!  It gives the following error:
>>
>> ! Missing argument to mymacro.
>>
>> Isn't that weird? But perhaps it has to do with me not understanding 
>> argument passing properly within METAPOST macros!
>>
>> Can someone please explain why this 2 argument example doesn't work?
>>
>> (But maybe this isn't the proper list to ask questions like these. If 
>> so, I'm sorry for bothering you!)
>>
>> Regards,
>> Gerard
>>
>>
>> On 16-09-2020 16:32, Geert Verhaag wrote:
>>>
>>> Hi,
>>>
>>> I'm trying to pass a string argument value to an MPgraphic but it 
>>> doesn't seem to work:
>>>
>>> Tried the following:
>>>
>>> \startuseMPgraphic{name}{lbl}
>>>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>>> \stopuseMPgraphic
>>>
>>> \starttext
>>>   \useMPgraphic{name}{lbl=1}
>>> \stoptext
>>>
>>> The above works as expected!
>>>
>>> But the following doesn't:
>>>
>>> \startuseMPgraphic{name}{lbl}
>>>   pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>>> \stopuseMPgraphic
>>>
>>> \starttext
>>>   \useMPgraphic{name}{lbl=abc}
>>> \stoptext
>>>
>>> It yields:
>>>
>>>  1 \startuseMPgraphic{name}{lbl}
>>>  2       pair a ; a := (3cm,3cm) ;label.top("\MPvariable{lbl}",a) ;
>>>  3     \stopuseMPgraphic
>>>  4
>>>  5     %\startuseMPgraphic{name}fill fullcircle scaled 200pt 
>>> withcolor .625yellow ;\stopuseMPgraphic
>>>  6
>>>  7     \starttext
>>>  8      Example:
>>>  9 >>    \useMPgraphic{name}{lbl=abc}
>>> 10     \stoptext
>>> 11
>>>
>>> <to be read again>
>>> a
>>> \m_meta_current_variable a-a
>>>                             bc
>>> <argument> ... \hbox {\scratchdimen \m_meta_current_variable
>>>                                                   sp}\ifzeropt \wd 
>>> \b_meta_v...
>>> \secondoftwoarguments #1#2b-#2
>>>
>>> \9>>1 #1,2-\meta_prepare_instance_variable {#1}
>>> \syst_helpers_do_process_comm...
>>> \syst_helpers_do_process_comma_list ...rgument #1,
>>>                                                   ]\relax \global 
>>> \advance \...
>>> ...
>>> l.9   \useMPgraphic{name}{lbl=abc}
>>>
>>> So it seems that only numbers can be passed not character strings! 
>>> Why is that? Is there a possibility to achieve this functionality?
> \startuseMPgraphic{name}{s::lbl,s::label}
>     def mymacro(expr a, b) =
>         label.top("str:(" & a & "," & b & ")",(3cm,3cm)) ;
>     enddef ;
>     mymacro("\MPvariable{lbl}","\MPvariable{label}")
> \stopuseMPgraphic
>
> \starttext
>   \useMPgraphic{name}{lbl=abc,label=pqr}
>   \useMPgraphic{name}{lbl=def,label=xyz}
> \stoptext
>
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------

Hi Hans,

It really is in the details!!!

I was convinced that I did something wrong somewhere, but couldn't 
figure out what.

Thanks very much for your kind help!

Regards,
Gerard
___________________________________________________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2020-09-18 11:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 14:32 Struggling with startuseMPgraphic and string argument! Geert Verhaag
2020-09-17  8:01 ` Hans Hagen
2020-09-17 19:41 ` Geert Verhaag
2020-09-18  7:03   ` Hans Hagen
2020-09-18 11:48     ` Geert Verhaag

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).