[texhax] Finding the widest string

Uwe Lueck uwe.lueck at web.de
Tue May 4 10:00:38 CEST 2010


"José Romildo Malaquias" <j.romildo at gmail.com> wrote at 04.05.2010 03:38:16:
> Given a list of strings, I have to find the widest one.
> I have tried to implement a macro for that, but it does not work. Any help is welcome.
>
>
>
>\documentclass[12pt,a5paper]{article}
>
>\def\Format#1{{\itshape\tiny #1}}
>
>\def\Widest#1#2(#3){%   dimension (the result)    formatter    list of strings
>  \def\EndList{xxx}%
>  \newbox\Box
>  \newdimen\WidthOther
>  \def\xWidest##1,{%
>    \def\temp{##1}%
>    \ifx\temp\EndList
>    \else
>      \setbox\Box{\hbox{#2{##1}}}%
>      \WidthOther=\wd\Box
>      \ifdim#1<\WidthOther
>        #1=\WidthOther
>      \else
>      \fi
>      \expandafter\xWidest
>    \fi
>  }%
>  \xWidest#3,\EndList,
>}
>
>\begin{document}
>
>\newdimen\mydim
>\Widest{\mydim}{\Format}(Good,morning,world)
>\the\mydim
>
>\end{document}

I think it must be 

    \xWidest#3,xxx,

at the end of your macro. You are presenting the string "\EndList" to end the loop while the loop is designed to end at the string "xxx".

BTW, "it does not work" is a typical phrase of no information that may raise a flame war indirectly.

Cheers, 

    Uwe.



More information about the texhax mailing list