ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de>
To: mailing ConTeXt users list for <ntg-context@ntg.nl>
Subject: passing dimensions to metapost
Date: Thu, 28 Aug 2008 00:07:44 +0200	[thread overview]
Message-ID: <E73C2705-F254-454B-9F12-130F53655238@uni-bonn.de> (raw)

Hi all,

cleaning up the code in my module, I run into a very interesting  
problem. I want to pass a user-defined value to Metapost. Until now,  
the value "scale" had to be numeric, and I used it like this:

draw fullcircle scaled \MPvar{scale}mm

and Metapost was happy, and I was too. Now Aditya made the reasonable  
suggestion that users should be allowed to input any dimension and not  
be restricted to "mm." Easy enough. However, I also want a fallback  
just in case they input a number, in that case, I want to fall back to  
mm as a default. So I tried (after Taco's excellent explanation on the  
wiki):

\expandafter\processaction\expandafter[\CVERscale]%
      [\v!unknown=>{\doifdimensionelse%
		    {\CVERscale}%
		    {\setupMPvariables[CircleSomething][scale=\CVERscale]}%
		    {\doifnumberelse%
			{\CVERscale}%
			{\newdimen\CIscale \global\CIscale=\CVERscale mm  
{\setupMPvariables[CircleSomething][scale=\the\CIscale]}}%
			{\setupMPvariables[CircleSomething][scale=10mm\relax]%
			   \message{Please give a proper value for the "scale" argument!}}}},
       \v!default=>{\setupMPvariables[CircleSomething][scale=10mm 
\relax]}]


So what I want: first check if \CVERscale is a dimension; if it is,  
assign it to the "scale" parameter. If it isn't, check if it is a  
number; if this is the case, append the unit "mm" to it and put it  
into a dimension register. If it isn't a number either, make the value  
sufficiently absurd for the user to realize and write a message to the  
terminal. This is all fine and dandy and works, sort of: it works  
perfectly with dimensions, but when I try with a number as input, it  
doesn't fall back to the unit "mm," but to "pt," AFAICS. That's nice  
too, but I have no clue why, and I would prefer mm. If it helps, I can  
try to give you a minimal test file tomorrow, but maybe somebody spots  
what I'm doing wrong? (I tried both with mkii and mkiv, and always get  
the same result.)

All best

Thomas
___________________________________________________________________________________
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
___________________________________________________________________________________


             reply	other threads:[~2008-08-27 22:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27 22:07 Thomas A. Schmitz [this message]
2008-08-28  7:45 ` Hans Hagen
2008-08-28 13:02   ` Thomas A. Schmitz
2008-08-28 13:34     ` "Padding" in natural tables B. Tommy Jensen
2008-08-28 15:04       ` B. Tommy Jensen
2008-08-28 15:47         ` Thomas A. Schmitz
2008-08-29 15:46       ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E73C2705-F254-454B-9F12-130F53655238@uni-bonn.de \
    --to=thomas.schmitz@uni-bonn.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).