Quantcast
Channel: Active questions tagged latex3 - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 260

Why can I not correctly reset a key in l3keys?

$
0
0

To help me learn l3keys I created two small demos.

The first uses l3keys for a command and seems to work correctly as far as I can tell.

% !TEX program = lualatexmk% !TEX encoding = UTF-8 Unicode\documentclass{article}\ExplSyntaxOn\prop_gput:Nnn \g_msg_module_type_prop { foo }{ Command }\msg_new:nnnn { foo }{ unknownoption }  { Unknown~option. }{ Try~again~but~with~a~known~option. }\tl_new:N \l__foo_thing_tl\tl_new:N \l__foo_towhom_tl\keys_define:nn { foo }  {    thing   .tl_set:N = \l__foo_thing_tl ,    thing   .default:n = door ,    thing   .initial:n = ice  ,    towhom  .tl_set:N = \l__foo_towhom_tl ,    towhom  .default:n = Dana ,    towhom  .initial:n = Ina  ,    unknown .code:n = \msg_fatal:nn { foo }{ unknownoption }  }\cs_new_protected:Npn \__foo_foo:nn #1#2  {    \group_begin:      \keys_set:nn { foo } { #1 }      #2~\l__foo_thing_tl \c_space_tl to~\l__foo_towhom_tl.    \group_end:  }\DeclareDocumentCommand{ \foosetup } { m }  { \keys_set:nn { foo } { #1 } }\DeclareDocumentCommand{ \foo } { O{} m }  {    \__foo_foo:nn { #1 } { #2 }  }\ExplSyntaxOff\begin{document}This demo shows how to use \texttt{l3keys} for a command.\foo{Give the}                       \par\foo[thing]{Give the}                \par\foo[thing,towhom]{Give the}         \par\foo[thing=car,towhom=Tom]{Give the} \par\foosetup{thing=apple}\foo{Give the}                       \par\foo[towhom]{Give the}               \par\end{document}

Here is the output:

Output from first MWE

The second uses l3keys for a package and seems to work correctly except in one case where a key doesn't correctly initialize.

% !TEX program = lualatexmk% !TEX encoding = UTF-8 Unicode\begin{filecontents}[overwrite,noheader]{foopkg.sty}\ProvidesExplPackage{foopkg}{}{}{}\msg_new:nnnn { foopkg }{ unknownoption }  { Unknown~option. }{ Try~again~but~with~a~known~option. }\tl_new:N \l__foopkg_thing_tl\tl_new:N \l__foopkg_towhom_tl\keys_define:nn { foopkg }  {    thing   .tl_set:N  = \l__foopkg_thing_tl ,    thing   .default:n = door ,    thing   .initial:n = ice  ,    towhom  .tl_set:N  = \l__foopkg_towhom_tl ,    towhom  .default:n = Dana ,    towhom  .initial:n = Ina  ,    unknown .code:n    = \msg_fatal:nn { foopkg }{ unknownoption }  }\ProcessKeyOptions[foopkg]\DeclareDocumentCommand{ \foosetup } { m }  { \keys_set:nn { foopkg } { #1 } }\cs_new_protected:Npn \__foopkg_foo:nn #1#2  {    \group_begin:    \keys_set:nn { foopkg } { #1 }    #2~\l__foopkg_thing_tl \c_space_tl to~\l__foopkg_towhom_tl.    \group_end:  }\DeclareDocumentCommand{ \foo } { O{} m }  {    \__foopkg_foo:nn { #1 } { #2 }  }\end{filecontents}\documentclass{article}%\usepackage[thing=vase,towhom=Val]{foopkg}\usepackage{foopkg}\begin{document}This demo shows how to use \texttt{l3keys} for a package.\foo{Give the}                       \par\foosetup{thing=door}\foo{Give the}                       \par\foosetup{thing,towhom}\foo{Give the}                       \par\foosetup{thing=car,towhom=Tom}\foo{Give the}                       \par\foosetup{thing=apple}\foo{Give the}                       \par\foosetup{towhom}\foo{Give the}                       \par\end{document}

Here is the output:

Output from the second MWE

In the second demo, the second occurrence of Tom should ideally be Ina but I don't understand why the key doesn't reset. This question seems relevant but I'm already, I think, using the solution there and either I'm doing something wrong or I'm not understanding something simple. Can the two demos be made to give the same results?


Viewing all articles
Browse latest Browse all 260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>