The hyperref
package (for example) provides a \hypersetup
command where key-value options can be provided as an alternative to \usepackage[key=value]{hyperref}
.
I'm trying to do the same, using kvoptions
, but it doesn't seem to be working for me.
As far as I understand it, in my .sty
file I should be able to say
\RequirePackage[patch]{kvoptions}
\newcommand*{\Xsetup}[1]{\setkeys{X}{#1}}
\SetupKeyvalOptions{family=X, prefix=X@}
\DeclareStringOption[default]{key}
\ProcessLocalKeyvalOptions*
and then in my .tex
file say \Xsetup{key=value}
. This would provide the \X@key
macro inside the .sty
file.
Unfortunately, \X@key
is set to default
instead of value
when I do this.
MWE
kvtest.tex
\documentclass{article}
\usepackage{kvtest}
\Xsetup{key=value}
\begin{document}
hi
\end{document}
kvtest.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{kvtest}[2018/05/17]
\RequirePackage[patch]{kvoptions}
\newcommand*{\Xsetup}[1]{\setkeys{X}{#1}}
\SetupKeyvalOptions{family=X, prefix=X@}
\DeclareStringOption[default]{key}
\ProcessLocalKeyvalOptions*
\show\X@key
filecontents
. – TeXnician May 16 '18 at 18:25pdflatex kvtest.tex
. In my log I see >\X@key=macro: ->default.
Very strange that it would work on your machine and not mine. – fionn May 17 '18 at 1:36