Misunderstanding from l3keys documentation
#1
is the optional argument in your definition, #2
would be the mandatory one: \DeclareDocumentCommand \MyModuleSetup { o m }
. So when you use
\MyModuleSetup[key-start-date={Date}]{Goodbye~World}
#1
is key-start-date={Date}
and #2
is Goodbye~World
. This is exactly what you're seeing.
Also you are defining the key with \keys_define:nn
but aren't setting it it \keys_set:nn
. A working suggestion:
\documentclass[10pt]{article}
\usepackage{xparse}
\ExplSyntaxOn
% define the variable before using it:
\tl_new:N \l_mymodule_start_date_tl
% define key:
\keys_define:nn { mymodule }
{
key-start-date .tl_set:N = \l_mymodule_start_date_tl
}
% #1: set keys (optional)
% #2: do something (mandatory)
\DeclareDocumentCommand \MyModuleSetup { o m }
{
% start a group to keep key setting local:
\group_begin:
% set keys if optional argument #1 is given:
\IfNoValueF {#1} { \keys_set:nn {mymodule} {#1} }
% do something with variable and mandatory argument #2:
Hello~World~The~date~today~is~{\l_mymodule_start_date_tl}~and~I~say~#2
\group_end:
}
\ExplSyntaxOff
\begin{document}
\MyModuleSetup[key-start-date={Date}]{Goodbye World}
\end{document}
keys_set:nn
is missing in the usage of \DeclareDocumentCommand
, so \l_mymodule_tl
is effectively empty.
\documentclass[10pt]{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_mymodule_tl
\keys_define:nn { mymodule }
{
key-start-date .tl_set:N= \l_mymodule_tl
}
\DeclareDocumentCommand \MyModuleSetup {O{}m }
{
\keys_set:nn{mymodule}{#1}
Hello~World~The~date~today~is~{\tl_use:N \l_mymodule_tl}~and~I~say~#1
}
\ExplSyntaxOff
\begin{document}
\MyModuleSetup[key-start-date={Date}]{Goodbye~World}
\end{document}