8

I'm using \keys_set_groups:nnn to process only subsets of key lists. The problem is that unknown keys doesn't raise an error in this case and so typos can be overlooked easily.

I can get around it by putting every key in a "known" group and using \keys_set_filter:nnn first, but I wonder if there is some better way ...

\documentclass[]{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\keys_define:nn {test} 
{
 keya .code:n =   {keya=#1~},
 keya .groups:n = {A, known},
}

%This recognize the typo keyA
\keys_set_filter:nnn {test} { known }
 {keya=test, keyA=XXX}

%this not 
\keys_set_groups:nnn {test} { A }
 {keya=abc, keyA=XXX}

\ExplSyntaxOff 
\end{document}
2
  • The design idea for key groups was they can be used to 'fish out' some keys from a longer list. As such, the fact that unknown keys are skipped is by-design. I can see a case for related alternatives, but to me that looks like an area for discussion: one for LaTeX-L. – Joseph Wright Jun 12 '15 at 18:30
  • @JosephWright: I do understand the rationale, but I also know how easy it is to make typos in key lists (linewidth or line width or line widht?) and so imho if the key_set... doesn't do the check for known keys by default then some external command to the same effect is needed. (It is not very difficult to write such a command with \keys_if_exist.. and \keyval_parse:.. so it is not a pressing matter, only a suggestion for improvement). – Ulrike Fischer Jun 15 '15 at 8:35
1

You could define your own, say \keys_set_groups_filter:nnn. Therefore I copied the definition of \keys_set_groups:nnn from expl3-code.tex and replaced the occurence of \keys_set:nn {#1} {#3} by \keys_set_filter:nnn {#1} {known} {#3}. Voilà, there's your desired error.

In the inner level you could also use \keys_set_known:… which rather ignores the unkown keys than raising an error.

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn

\cs_new_protected:Npn \keys_set_groups_filter:nnn #1#2#3
  {
    \bool_set_true:N \l__keys_selective_bool
    \bool_set_false:N \l__keys_filtered_bool
    \seq_set_from_clist:Nn \l__keys_selective_seq {#2}
    \keys_set_filter:nnn {#1} {known} {#3}
    \bool_set_false:N \l__keys_selective_bool
  }
\cs_generate_variant:Nn \keys_set_groups_filter:nnn { nnV , nnv , nno }

\keys_define:nn {test} 
 {
  keya .code:n =   { keya=#1~ },
  keya .groups:n = { A, known },
 }

\keys_set_groups_filter:nnn {test} { A }
 { keya=abc, keyA=XXX }

\ExplSyntaxOff 
\end{document}
2
  • I would still have to put every key in a "known" group which looks a bit curious as l3keys knows which keys are known. – Ulrike Fischer Jun 10 '15 at 19:00
  • @UlrikeFischer Then the only option I see is to use \keys_set_known:… and waive the error message. – Henri Menke Jun 10 '15 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.