I'm trying to write an aptly-named package
xkeyvalisinsanelydifficult
such that the user can \usepackage either as
\usepackage{xkeyvalisinsanelydifficult}
or
\usepackage[turnedon]{xkeyvalisinsanelydifficult},
but (preferably, if possible) not as
\usepackage[turnedon=42]{xkeyvalisinsanelydifficult}
(just because it wouldn't make much sense in this package's case).
Contents of xkeyvalisinsanelydifficult.sty:
\ProvidesPackage{xkeyvalisinsanelydifficult}[2022/07/22]
\RequirePackage{xkeyval}
\newcommand{\somesimplecommand}{nothing at all}
\define@boolkey{myfamily}{turnedon}{}
\ProcessOptionsX\relax
\ifKV@myfamily@turnedon
\def\somesimplecommand{ON}
\else
\def\somesimplecommand{OFF}
\fi
Contents of sample.tex:
\documentclass{article}
\usepackage{xkeyvalisinsanelydifficult}
\begin{document}
Hello, it's turned \somesimplecommand!
\end{document}
When sample.tex 2nd line is
\usepackage{xkeyvalisinsanelydifficult},
things go well: the document compiles and reads
"Hello, it's turned OFF!"
(which is expected because the xkeyval docs state that
\define@boolkey initializes a boolean to false,
with \newif).
When sample.tex 2nd line is
\usepackage[turnedon]{xkeyvalisinsanelydifficult},
the document doesn't compile with an error that reads
ERROR: LaTeX Error: Unknown option 'turnedon' for package 'xkeyvalisinsanelydifficult'.
How to rewrite these files such that if the 2nd line of sample.tex is
\usepackage[turnedon]{xkeyvalisinsanelydifficult},
it compiles and reads "Hello, it's turned ON!" ?
myfamilyyou must use\ProcessOptionsX<myfamily>\relaxto process them (the default family isxkeyvalisinsanelydifficult.sty.) – Ulrike Fischer Jul 23 '22 at 07:25\usepackage[turnedon=true]{xkeyvalisinsanelydifficult}work using\ProcessOptionsX<myfamily>.\usepackage[turnedon]{xkeyvalisinsanelydifficult}behaves like\usepackage{xkeyvalisinsanelydifficult}, so it would be a minor nuisance to the user, to have to typeturnedon=trueinstead of simplyturnedon. – Daniel Diniz Jul 23 '22 at 13:10\define@boolkey{myfamily}{turnedon}[true]{}to define a default value "true" (that would not be necessary with l3keys, boolean keys by default assume true if no value is given). – Ulrike Fischer Jul 23 '22 at 14:56