Is there something like a scope of \NewDocumentCommand?
Following along the line of my (confused) post on xparse and expl3, but
this time hopefully with no typos or missing characters, I've devised a
small package just to check a l3keys-based definition and setting of
options. My issue is not (so far) with the passing of options, but with an
unexpected (to me) behavior of a command.
I have a file tmpkgl3.sty with this content:
\ProvidesPackage{tmpkgl3}[2013/08/20 LaTeX2e/LaTeX3 wannabe package]
\RequirePackage{xparse,l3keys2e}
\ExplSyntaxOn
% Some of the variants are already declared in LaTeX3
\cs_generate_variant:Nn \bool_new:N {c}
\cs_generate_variant:Nn \bool_if:NTF {cTF}
\cs_generate_variant:Nn \bool_set_true:N {c}
% I have in mind egreg's remarks in my linked post regarding not using
this as I do.
\tl_const:Nn \c_prefix_tl {g_amod_}
\tl_const:Nn \c_postfix_tl {_bool}
\NewDocumentCommand\MakeBool { m }
{
\bool_new:c
{ \tl_use:N \c_prefix_tl #1 \tl_use:N \c_postfix_tl }
}
\NewDocumentCommand\SetTBool { m }
{
\bool_set_true:c
{ \tl_use:N \c_prefix_tl #1 \tl_use:N \c_postfix_tl }
}
\NewDocumentCommand\WelcherWegBool { m m m }
{
\bool_if:cTF
{ \tl_use:N \c_prefix_tl #1 \tl_use:N \c_postfix_tl }
{ #2 } { #3 }
}
\MakeBool{esp}
\keys_define:nn { amod }
{
lang .choice_code:n =
{ \SetTBool { \tl_use:N \l_keys_choice_tl }
\WelcherWegBool { esp } { True } { False } \par
},
lang .generate_choices:n = { esp },
}
\DeclareDocumentCommand\DocumentSetup { +m }
{ \keys_set:nn { amod }{#1} }
%\ProcessKeysOptions { amod }
\ExplSyntaxOff
Then, I have the next content in a .tex file l3tryout.tex:
\documentclass{memoir}
\usepackage{tmpkgl3}
%\ExplSyntaxOn
%\ProvideDocumentCommand\WelcherWegBool { m m m }
% {
% \bool_if:cTF
% { \tl_use:N \c_prefix_tl #1 \tl_use:N \c_postfix_tl }
% { #2 } { #3 }
% }
\AtBeginDocument{%
\DocumentSetup{ lang = esp }
}
\begin{document}
\WelcherWegBool { esp } { T }{ F }
\end{document}
%\ExplSyntaxOff
With the files like above I get True F, whereas I should get True T (in
two different paragraphs due to the \par in the options definition).
Nonetheless, if I uncomment the commented lines in the l3tryout.tex file,
I get the right result. It's as though the command \WelcherWegBool worked
fine in the package but not so in the tex file. May this have something to
do with having switched off the ExplSyntax switch?
No comments:
Post a Comment