With \makebox
I would just pass [r]
, but how do I do it in latex3? No matter whether I use fills or flush/ragged etc, the contents stay left-aligned. I suspect the updated width does not adjust the contents (and if I set it before, updating the contents will recalculate the width, it seems).
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\test}{m m}
{
\dim_zero_new:N \l_width_dim
\dim_set:Nn \l_width_dim { #1 }
\meide_test:nnn { \l_tmpa_box } { \l_width_dim } { #2 }
\box_use:N \l_tmpa_box
}
\cs_new_protected:Npn \meide_test:nnn #1#2#3
{
\box_clear_new:N {#1}
\hbox_set:Nn {#1} { \hfill #3 } % also tried dotfill/flushright/raggedleft etc
\box_set_wd:Nn {#1} {#2}
}
\ExplSyntaxOff
\begin{document}
result should be aligned to the right: (\test{3em}{test})
\end{document}