I sometimes encounter a problem when I attempt to use \widthof from the calc package, and don't know why. In the past I have just worked around it using a two step process of defining a \newdimen{} and using \settowidth (or \setlength and \widthof) to determine the value before attempting to use this length.
The MWE below shows how this fails when I attempt to use the \widthof as the length of a \kern (i.e., the \KernA macro), but the two step process works just fine:

Questions:
- Why does
\KernAnot work? - When can I use
\widthofdirectly?
References:
Code:
\documentclass{article}
\usepackage{calc}
\newcommand*{\KernA}{\kern\widthof{$text$}}%
\newdimen{\KernAmount}%
\newcommand*{\KernB}{%
\setlength{\KernAmount}{\widthof{$text$}}%
\kern\KernAmount%
}%
\newcommand*{\KernC}{%
\settowidth{\KernAmount}{$text$}%
\kern\KernAmount%
}%
\begin{document}
x~$text$~y
%x~\KernA~y \verb|\kernA: \widthof| ??
x~\KernB~y \verb|\KernB: \setlength and \widthof|
x~\KernC~y \verb|\KernC: \settowidth|
\end{document}
\hphantom{$text$}instead. – Martin Scharrer May 01 '12 at 20:47