I would like to pass user-defined keys. But when the user does not specify values, the default values are used. I need some explanation on what to do in the \setdimensions command. What does .initial work out exactly ?
\documentclass{article}
\ExplSyntaxOn
% Define dimension variables
\dim_new:N \l_mymodule_width_dim
\dim_new:N \l_mymodule_height_dim
\dim_new:N \l_mymodule_margin_dim
% Define a new key-value family
\keys_define:nn { mymodule }
{
width .dim_set:N = \l_mymodule_width_dim,
width .initial:n = 34pt,
width .default:n = 34pt,
height .dim_set:N = \l_mymodule_height_dim,
height .initial:n = 34pt,
height .default:n = 34pt,
margin .dim_set:N = \l_mymodule_margin_dim,
margin .initial:n = 34pt,
margin .default:n = 34pt,
}
% Command to use the keys
\NewDocumentCommand{\setdimensions}{o}
{
% Use the dimensions in your document or perform other actions
\fbox
{
Width: \dim_use:N \l_mymodule_width_dim \
Height: \dim_use:N \l_mymodule_height_dim \
Margin: \dim_use:N \l_mymodule_margin_dim
}
}
\ExplSyntaxOff
\begin{document}
% Example usage
\setdimensions{
width = 8cm,
height = 4cm,
margin = 1.5cm,
}
\end{document}



\setdimensions{width}. I have some doubts that it makes much sense here. – Ulrike Fischer Feb 29 '24 at 15:09initialsets thevalue at the point you use\keys_define:nnanddefaultis the value used if you use the key with no=value. – David Carlisle Feb 29 '24 at 15:20{ width = 8cm, height = 4cm, margin = 1.5cm, }is not an argument to the command, it is simply text typeset after the command has finished. – David Carlisle Feb 29 '24 at 15:25\keys_set:nnbut was wondering how that should be used. – Ragonese Feb 29 '24 at 15:48#1to do whatever you want (set keys in this case) – David Carlisle Feb 29 '24 at 15:51