[texhax] Finding the widest string

José Romildo Malaquias j.romildo at gmail.com
Tue May 4 17:14:20 CEST 2010


On Mon, May 03, 2010 at 11:37:43PM -0700, Stephen Hicks wrote:

[...]
> Other than that, your code looks great!  If you're interested, here's
> how I might have written the same macro:
> 
> ========
> \makeatletter
> \def\wid at helper#1,{%
>   \def\wid at arg{#1}%
>   \ifx\wid at arg\wid at end
>     \let\wid at next\relax
>   \else
>     \setbox\z@\hbox{\wid at fmt{#1}}%
>     \ifdim\wd\z@>\dimen@
>       \dimen@\wd\z@
>     \fi
>   \fi
>   \wid at next
> }
> \def\Widest#1#2(#3){\begingroup
>   \dimen@\z@
>   \def\wid at end{\wid at end}%
>   \def\wid at fmt{#2}%
>   \let\wid at next\wid at helper
>   \wid at next#3,\wid at end,%
>   \expandafter\endgroup\expandafter#1\the\dimen@\relax
> }
> \makeatother
> ========

What excatly are \dimen@ and \z@ ? Are they a pre-defined dimension and
a pre-defined box, respectively? If so, can they be freely used in my
code? Using them would affect any other part of the system, for
instance, other macros that also use them?

In the above example we found the snippet \wid at fmt{#1} of code, where
the macro \wid at fmt was defined to be a macro that is passed as argument,
so one cannot tell what it is in advance. What about if this macro also
makes use of \dimen@ or \z@, using their current value or setting new
values to them?

Romildo


More information about the texhax mailing list