ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* passing dimensions to metapost
@ 2008-08-27 22:07 Thomas A. Schmitz
  2008-08-28  7:45 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas A. Schmitz @ 2008-08-27 22:07 UTC (permalink / raw)
  To: mailing ConTeXt users list for

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
___________________________________________________________________________________


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

* Re: passing dimensions to metapost
  2008-08-27 22:07 passing dimensions to metapost Thomas A. Schmitz
@ 2008-08-28  7:45 ` Hans Hagen
  2008-08-28 13:02   ` Thomas A. Schmitz
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2008-08-28  7:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thomas A. Schmitz wrote:
> 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.)

\startluacode
document.mymodule = document.mymodule or { }

function document.mymodule.checkdimen(str)
     return (str:find("%a%a$") and str) or (str .. "mm")
end
\stopluacode

\ctxlua{document.mymodule.checkdimen("#1")}

or more fancy:

function document.mymodule.checkdimen(str)
     if not str:find("%a%a$") then
         str = str .. "mm"
         ctx.writestatus("mymodule","you forgot a dimension unit, so I 
made it up for you: %s",str)
     end
     return str
end

for mkii you can use \doifdimensionelse (it reminds me to implement that 
in mkiv)

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: passing dimensions to metapost
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas A. Schmitz @ 2008-08-28 13:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users


On Aug 28, 2008, at 9:45 AM, Hans Hagen wrote:

Hans, thanks a lot for your reply. Amazing - the lua code is so simple  
that even I can understand it! I'm certain to use it later; for the  
time being, I want to remain compatible for mkii and XeTeX as well.

> \startluacode
> document.mymodule = document.mymodule or { }
>
> function document.mymodule.checkdimen(str)
>     return (str:find("%a%a$") and str) or (str .. "mm")
> end
> \stopluacode
>
> \ctxlua{document.mymodule.checkdimen("#1")}
>
> or more fancy:
>
> function document.mymodule.checkdimen(str)
>     if not str:find("%a%a$") then
>         str = str .. "mm"
>         ctx.writestatus("mymodule","you forgot a dimension unit, so I
> made it up for you: %s",str)
>     end
>     return str
> end
>
> for mkii you can use \doifdimensionelse (it reminds me to implement  
> that
> in mkiv)

Hey, I WAS using \doifdimensionelse and \doifnumberelse! :-) And it  
appears to be working in mkiv as well! I found out the error in my  
code (it was too complex, and I was overwriting a variable with the  
same name; it looks like Metapost assigns "sp" as default unit to  
\MPvar). Problem solved, but it took me half a day...

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
___________________________________________________________________________________


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

* "Padding" in natural tables
  2008-08-28 13:02   ` Thomas A. Schmitz
@ 2008-08-28 13:34     ` B. Tommy Jensen
  2008-08-28 15:04       ` B. Tommy Jensen
  2008-08-29 15:46       ` Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: B. Tommy Jensen @ 2008-08-28 13:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,,
I have been searching the documentation on natural tables (\bTABLE), but  
haven't been
able to resolve the following issue:

I would like to specify an internal padding in the table cells, e.g. text  
content should start 0.4cm
 from the left edge of the table cell. Also, it would be nice to specify  
the distance from the top border.
(In HTML this is accomplished with the "padding" option.)

The table is composed with horizontal lines only.

I have tried the "distance" option for the table columns, but this gives  
ugly "broken" horizontal lines.

What is the best solution - is there an undocumented parameter, or do I  
have to add a block within the cell
and specify an external margin for that block?

Best regards,
Tommy Jensen
___________________________________________________________________________________
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] 7+ messages in thread

* Re: "Padding" in natural tables
  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
  1 sibling, 1 reply; 7+ messages in thread
From: B. Tommy Jensen @ 2008-08-28 15:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Sorry for "polluting" the mailing list with my question - I just
discovered an "offset" property in the mail list archive that seems
to do what I want.

The TABLE package in Context is really powerful - it would be very nice
to have an updated documentation for it, summarising all available
options.

Best regards,
Tommy Jensen


> Hi,,
> I have been searching the documentation on natural tables (\bTABLE), but
> haven't been
> able to resolve the following issue:
>
> I would like to specify an internal padding in the table cells, e.g. text
> content should start 0.4cm
>  from the left edge of the table cell. Also, it would be nice to specify
> the distance from the top border.
> (In HTML this is accomplished with the "padding" option.)
>
> The table is composed with horizontal lines only.
>
> I have tried the "distance" option for the table columns, but this gives
> ugly "broken" horizontal lines.
>
> What is the best solution - is there an undocumented parameter, or do I
> have to add a block within the cell
> and specify an external margin for that block?
>
> Best regards,
> Tommy Jensen
___________________________________________________________________________________
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] 7+ messages in thread

* Re: "Padding" in natural tables
  2008-08-28 15:04       ` B. Tommy Jensen
@ 2008-08-28 15:47         ` Thomas A. Schmitz
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas A. Schmitz @ 2008-08-28 15:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users


On Aug 28, 2008, at 5:04 PM, B. Tommy Jensen wrote:

> Sorry for "polluting" the mailing list with my question - I just
> discovered an "offset" property in the mail list archive that seems
> to do what I want.

Glad you found what you were looking for. One little hint about  
"pollution": don't take an existing mail and use the "reply" function  
to start a new discussion; it confuses all mail clients which do  
proper threading.

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
___________________________________________________________________________________


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

* Re: "Padding" in natural tables
  2008-08-28 13:34     ` "Padding" in natural tables B. Tommy Jensen
  2008-08-28 15:04       ` B. Tommy Jensen
@ 2008-08-29 15:46       ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2008-08-29 15:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users

B. Tommy Jensen wrote:
> Hi,,
> I have been searching the documentation on natural tables (\bTABLE), but  
> haven't been
> able to resolve the following issue:
> 
> I would like to specify an internal padding in the table cells, e.g. text  
> content should start 0.4cm
>  from the left edge of the table cell. Also, it would be nice to specify  
> the distance from the top border.
> (In HTML this is accomplished with the "padding" option.)
> 
> The table is composed with horizontal lines only.
> 
> I have tried the "distance" option for the table columns, but this gives  
> ugly "broken" horizontal lines.
> 
> What is the best solution - is there an undocumented parameter, or do I  
> have to add a block within the cell
> and specify an external margin for that block?

there is a setups key and you can add settings to a setup then

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2008-08-29 15:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-27 22:07 passing dimensions to metapost Thomas A. Schmitz
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

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