For foo and baz, widthof return sensible/nonsensible values. When the width of the minipage wrapped around foo and baz is set to these numbers, neither has the desired width, that is, the width of the longest line contained within. In other words, I'm looking to set minipage's width such that no line breaks.
\documentclass[12pt]{report}
\usepackage{calc}
\usepackage{mwe}
\usepackage{xparse}
\usepackage{zebra-goodies}
\newsavebox\foo
\sbox{\foo}{%
% 3456789
abcdefgh
\\abc%
}
\NewDocumentCommand{\baz}{}
{%
% 3456789
abcdefgh\\% "longest line"
abc
}
\begin{document}
\noindent \texttt{foo}
% https://tex.stackexchange.com/a/37294/112708
\begin{tabular}{ll}
w & \widthof\foo \\
h & \heightof\foo \\
d & \depthof\foo
\end{tabular}
\frame{\begin{minipage}{\widthof{\foo}}
\usebox{\foo}
\end{minipage}}
{\tiny\todo{adjust mp's width to fit exactly longest line}}
\noindent \texttt{baz}
\begin{tabular}{ll}
w & \widthof\baz \\
h & \heightof\baz \\
d & \depthof\baz
\end{tabular}
\frame{\begin{minipage}{\widthof{\baz}}
\baz
\end{minipage}}
{\tiny\todo{adjust mp's width to fit exactly longest line}}
\end{document}



\frame{\begin{minipage}{\wd\foo}You want the width of the box and not the width of '\foo', right? For\bazput it in a box if you want to measure it. – cfr Oct 24 '19 at 03:33\frame{\begin{tabular}{l} \baz \end{tabular}}– Fran Oct 24 '19 at 03:41minipageto containabcdefgh\\abcand have the width ofabcdefghsince its the longest. I have the intuition boxes comes into play, just not sure how. – Erwann Oct 24 '19 at 03:54