I am trying to get the width of a macro parameter using
\def\getwidthof#1{%
\newdimen\myl%
\settowidth\myl{#1}%
\the\myl%
}
where \settowidth is defined as
\catcode`\@=11
\newbox\@tempboxa
\def\@settodim#1#2#3{\setbox\@tempboxa\hbox{{#3}}#2#1\@tempboxa
\setbox\@tempboxa\box\voidb@x}
\def\settoheight{\@settodim\ht}
\def\settodepth {\@settodim\dp}
\def\settowidth {\@settodim\wd}
\catcode`\@=12
using egreg's answer here. I would like the code \getwidthof{some text} to print out the width of some text, which in this case would be 42.55563pt. The code
\newdimen\myl
\settowidth\myl{some text}
\the\myl
works, but breaks when a parameter is used. Is it because #1 is not expanded when put in \settowidth\myl{#1}?

newdimeninside a command definition is almost certainly wrong. – user202729 Jul 19 '22 at 01:44