I am playing around a little with creating a custom package for theorem environments and related functionality. Consider the following MWE:
\RequirePackage{filecontents}
\begin{filecontents}{test.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{test}
%Required packages
\RequirePackage{xkeyval} % For key-value syntax, \DeclareOptionX
\RequirePackage{amsthm} % For theorem environments
%Initialize some variables
\newcommand{\theoremlevel}{}
\newcommand{\@swapnumbersoption}{}
%Default english theorem names
\newcommand{\theoremname}{Theorem}
%Declaring package options
\DeclareOption{babel}{ %Babel Option to adjust theorem names if babel is used
\addto\captionsenglish{
\renewcommand{\theoremname}{Theorem}
}
\addto\captionsngerman{
\renewcommand{\theoremname}{Satz}
}
}
\DeclareOption{swapnumbers}{\renewcommand{\@swapnumbersoption}{\swapnumbers}} %Option to enable number swaps i.e. '1.1 Definition' rather than 'Definition 1.1'
\ProcessOptions\relax
\DeclareOptionX{theoremlevel}{\renewcommand{\theoremlevel}{#1}} %Key value option to specify the level theorem environments are numbered within
\ExecuteOptionsX{theoremlevel=section}
\ProcessOptionsX\relax
%Creating theorem environments
\@swapnumbersoption %Swaps numbers if option 'swapnumbers' is enabled, does nothing otherwise
\theoremstyle{definition}
\newtheorem{theorem}{\protect\theoremname}[\theoremlevel]
\end{filecontents}
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[swapnumbers,theoremlevel=subsection,babel]{test}
\begin{document}
\begin{theorem}
Inhalt...
\end{theorem}
\end{document}
The output is:
So indeed, all three options do what they should: The numbers are swapped, the captions are german and the theorem is numbered within subsubsection. However I get the following errors:
Unknown option `theoremlevel=subsection' for package `test'. \ProcessOptions\relax
Unknown option `swapnumbers' for package `test'. \ProcessOptionsX\relax
Unknown option `babel' for package `test'. \ProcessOptionsX\relax
Writing text ` ' before \end{filecontents} as last line of test.sty
So clearly, once again I am doing something stupid. But what?
\@swapnumbersoption
but you define\@numberswapoption
\ProcessOptions
\@swapnumbersoption
. Regarding k=v syntax I'm not sure I don't want to use\ProvessOptions
at all, since I also have standard options. In the updated question I split standard options and k=v options into two blocks.\processOptions
doesn't knowtheoremlevel=subsection
is related totheoremlevel
it just takes the entire string as an unknown option name\ProcessOptions\relax
then thebabel
and theswapnumbers
option no longer have an effect.