ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Passing variables into context
@ 2009-09-30 11:27 Matthijs Kooijman
  2009-09-30 11:29 ` Taco Hoekwater
  0 siblings, 1 reply; 4+ messages in thread
From: Matthijs Kooijman @ 2009-09-30 11:27 UTC (permalink / raw)
  To: Mailing list for ConTeXt users


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

Hi all,

I've been trying to make a metapost graphic, based on the \textwidth. However,
it seems I can't just pass in \textwidth as an option. For example, the
following breaks:

  \startuniqueMPgraphic{HLine}
  draw origin -- (\MPvar{width}, 0mm); 
  \stopuniqueMPgraphic

  \starttext

  \setupMPvariables[HLine][width=\textwidth]
  \uniqueMPgraphic{HLine}

  \stoptext

with the following error:

  mplib | mp terminal: >> textwidth
    ! Undefined x coordinate has been replaced by 0.
    <to be read again>
                   ;
    <*> ...d:=3441; draw origin -- (\textwidth , 0mm);

It seems that the \textwidth option is not expanded before being passed to MP.
Is there any way to force this expansion? I've tried \expandafter (without
really understanding what that does), but that didn't help.

I've tried putting this graphic as an overlay under an \framed, which allows
me to use the \overlaywidth macro in metapost (which I assume is expanded
specially by context?). This worked, but is not very elegant. Is there
something more straightforward possible?

Gr.

Matthijs

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Passing variables into context
  2009-09-30 11:27 Passing variables into context Matthijs Kooijman
@ 2009-09-30 11:29 ` Taco Hoekwater
  2009-09-30 11:36   ` Matthijs Kooijman
  0 siblings, 1 reply; 4+ messages in thread
From: Taco Hoekwater @ 2009-09-30 11:29 UTC (permalink / raw)
  To: Mailing list for ConTeXt users



Matthijs Kooijman wrote:
> 
> It seems that the \textwidth option is not expanded before being passed to MP.
> Is there any way to force this expansion? I've tried \expandafter (without
> really understanding what that does), but that didn't help.

You should try \the\textwidth

Best wishes,
Taco
___________________________________________________________________________________
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Passing variables into context
  2009-09-30 11:29 ` Taco Hoekwater
@ 2009-09-30 11:36   ` Matthijs Kooijman
  2009-09-30 12:07     ` Taco Hoekwater
  0 siblings, 1 reply; 4+ messages in thread
From: Matthijs Kooijman @ 2009-09-30 11:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Hi Taco,

> You should try \the\textwidth
Thanks, that works. Could you enlighten me as to what \the does and why this
helps? Does Context treat \the specially within metapost code (which seems so,
since there are more \the examples in the metafun manual), or is it expanded
before getting inserted into metapost?

Using this in arithmetic gets slightly more complicated (0.5\the\textwidth
doesn't work, but since this gets put into metapost, 0.5 * \the\textwidth does
work).

Gr.

Matthijs

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Passing variables into context
  2009-09-30 11:36   ` Matthijs Kooijman
@ 2009-09-30 12:07     ` Taco Hoekwater
  0 siblings, 0 replies; 4+ messages in thread
From: Taco Hoekwater @ 2009-09-30 12:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users



Matthijs Kooijman wrote:
> Hi Taco,
> 
>> You should try \the\textwidth
> Thanks, that works. Could you enlighten me as to what \the does and why this
> helps? Does Context treat \the specially within metapost code (which seems so,
> since there are more \the examples in the metafun manual), or is it expanded
> before getting inserted into metapost?

\the is an expandable command that 'converts' internal tex parameters
into their value. The expansion takes places during \edef (like inside
\expanded) or during write to a buffer.

> Using this in arithmetic gets slightly more complicated (0.5\the\textwidth
> doesn't work, but since this gets put into metapost, 0.5 * \the\textwidth does
> work).

If you want a single value inside mpost, you could use \dimexpr to do
the calculation in tex.

Best wishes,
Taco
___________________________________________________________________________________
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2009-09-30 12:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-30 11:27 Passing variables into context Matthijs Kooijman
2009-09-30 11:29 ` Taco Hoekwater
2009-09-30 11:36   ` Matthijs Kooijman
2009-09-30 12:07     ` Taco Hoekwater

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