On 11/25/2025 10:54 PM, Max Chernoff via ntg-context wrote:
Hi Hraban,
On Tue, 2025-11-25 at 18:09 +0100, Henning Hraban Ramm wrote:
\define[2]\Conv{\scratchdimen #1 \the\nodimen #2 \scratchdimen}
I tried to use \unit within the definition above or like
\unit{\Conv{1dk}{mm}}, but the result is empty – probably an expansion
problem?
\define[2]\Conv{\unit{\dimexpr\scratchdimen #1 \the\nodimen #2
\scratchdimen\relax}}
1. Setting a dimension isn't expandable, so you need to do that before
using \unit.
2. You need to make sure that the argument to \unit is expanded before
\unit itself is.
The following should work as expected:
\mainlanguage[de]
\setupunit[method=3,space=small,]
\define[2]\Conv{%
\scratchdimen=#1
\normalexpanded{\noexpand\unit{\the\nodimen #2 \scratchdimen}}
}
\starttext
\bTABLE
\bTR\bTH Einheit \eTH\bTH mm \eTH\bTH pt \eTH\eTR
\bTR\bTD 1 dk \eTD\bTD \Conv{1dk}{mm} \eTD\bTD \Conv{1dk}{pt} \eTD\eTR
\bTR\bTD 1 es \eTD\bTD \Conv{1es}{mm} \eTD\bTD \Conv{1es}{pt} \eTD\eTR
\bTR\bTD 1 ts \eTD\bTD \Conv{1ts}{mm} \eTD\bTD \Conv{1ts}{pt} \eTD\eTR
\eTABLE
\stoptext
-- Max
Hi Max,
So here's some low level treat for you. \unit doesn't expand in an \edef
comparable situation so no need for \noexpand. Actually, you can expand
by prefixing with \expand if needed. The \scratchimen can also be
avoided which has some benefits.
\define[2]\Conv{%
\normalexpanded{\unit{\the\nodimen #2 {#1}}}%
}
I'd do:
\starttexdefinition Conv #1#2
\normalexpanded {
\unit {
\the\nodimen #2 {#1}
}
}
\stoptexdefinition
Now Hraban can also go wild with two Sundqvist units in one go:
\bTR
\bTD 1ts+2es \eTD
\bTD \Conv{1ts+2es}{mm} \eTD
\bTD \Conv{1ts+2es}{pt} \eTD
\eTR
And of course, he can guess how \nodimen is defined. I admit that I had
to look it up .. so long ago .. interesting that you found it (and
remembered).
Hans
-----------------------------------------------------------------
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 : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________