I am trying to write a command that will do the following, in order:
- Measure the width of an input word.
- Compare this value to an existing value.
- If the input word's width is greater, then take on that measure as value. Otherwise, do nothing.
What is going wrong with the following code?
\documentclass{article}
\usepackage{ifthen}
\usepackage{calc}
\usepackage{showframe}
\newlength\shape
\setlength{\shape}{1mm}
\newcommand{\shifter}[1]{\ifthenelse
{\shape<\widthof{#1}} % If the width of the input word is greater than the length of \shape,
{\setlength{\shape}{\widthof{#1}}} % then make the length of \shape equal to the width of the input word.
{} % Otherwise, do nothing.
}%
\setlength{\parindent}{0pt}
\begin{document}
\hspace{\shape}Hello % Output as expected: `Hello' is indented 1mm from the left margin.
\shifter{Tyrannosaurus}
\hspace{\shape}Hello % Output not as expected. I wanted Hello' to be indented the width of the wordTyrannosaurus' from the left margin. Instead, `Hello' is indented 1mm from the left margin.
\end{document}
Possibly relevant: I am getting the following error:
A number should have been here; I inserted `0'.
Why?

\widthof{#1}is not a length that can be used in ifthenelse, it is a special construct just valid in calc package expressions (which includes\setlength) – David Carlisle Aug 21 '23 at 21:54\settowidth\colwidth{Yessirino} % <--- select the longest text in the last columnsin Zarko's code in the above link. (The purpose of\colwidthis to locally establish a column width.) – Noah J Aug 21 '23 at 23:19