In my pursue to switch as much as possible from LaTeX2e
code to LaTeX3/expl3
, I got stuck with the usage of some of the calc
package facilities. I've read of the l3calc
package, but it seems it is currently deprecated. In particular, I'm running into trouble with the calc
pkg command \widthof
. What's the LaTeX3/expl3
way to proceed in this regard without declaring a box? I mean, something like \widthof{This text}
chez LaTeX3/expl3
.
To be more precise, I run into trouble with:
\documentclass{memoir}
% Loading explicitly the calc pkg doesn't help
%\usepackage{calc}
\usepackage{xparse}
\ExplSyntaxOn
\dim_new:N \g_tmp_dim
\dim_set:Nn \g_tmp_dim { \widthof{This ~ text} } % { 3pt } It works with this
\NewDocumentCommand \ShowWidth { }
{ \dim_use:N \g_tmp_dim }
\ExplSyntaxOff
\begin{document}
\ShowWidth
\end{document}
Maybe my trouble has something to do with the expansion of the n
argument here and I should define a variant for the function \dim_set:Nn
that manages the expansion in a different way? Just pondering over it...
\widthof
inexpl3
; the function\dim_set:Nn
wants a<dimension expression>
as its second argument, which must be expandable; nothing like\widthof
can be, because a box must be set for measuring it.calc
-based commands returning a length (or dimension) without requiring to set up a box beforehand.