I’ve created a simple package with options settable via l3keys2e
. I was able to figure out how to make the syntax
\usepackage[format = international]{phone}
work, but I’d like to make the syntax
\usepackage[international]{phone}
be a synonym. The method I’m using in the code below works, but is very repetitive, especially when I’ve got more formatting options. Is there a simpler way?
Here’s the code:
\RequirePackage{expl3, l3keys2e, xparse}
\ProvidesExplPackage
{phone}{2013/06/19}{0.1}{Format phone numbers}
\cs_new_nopar:Npn \phone_international_fmt:NNN #1#2#3
{ +1 - #1 - #2 - #3 }
\cs_new_nopar:Npn \phone_parendash_fmt:NNN #1#2#3
{ (#1) \nobreakspace #2 - #3 }
\keys_define:nn { phone }
{
format .choice_code:n =
{
\cs_new_eq:Nc \phone_fmt:NNN
{ phone_ \tl_use:N \l_keys_choice_tl _fmt:NNN }
},
format .generate_choices:n =
{
international,
parendash,
},
% These next lines will become repetitive if I have many more formatting options
international .meta:n = { format = international },
parendash .meta:n = { format = parendash },
}
\ProcessKeysOptions { phone }
\NewDocumentCommand \phone
{ >{ \SplitArgument {2} {-} } m }
{ \phone_fmt:NNN #1 }
\endinput
A minimal example using this package looks like this:
\documentclass{article}
% \usepackage[parendash]{phone}
\usepackage[format = parendash]{phone}
\begin{document}
\phone{212-555-1212}
\end{document}
This yields the desired result
(212) 555-1212
\cs_new_nopar:Npn \phone_international_fmt:NNN
isn't really encouraged, and I'd suggest\cs_new:Npn \phone_international_fmt:NNN
instead. Apart from a few specific internals, we've standardised on a position that functions with arguments should be 'long'.:NNN
argument spec rather be:nnn
?:NNN
should be:nnn