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
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
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
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
participants (2)
-
Matthijs Kooijman
-
Taco Hoekwater