What's wrong with the following package and source file? I get an error at line 14, after [Other]
, of mypackage.sty
, and a "Missing \begin{document}" error resulting.
The source:
\documentclass{article}
\usepackage[what=this]{mypackage}
\usepackage{blindtext}
\begin{document}
\blindtext
\end{document}
The package mypackage.sty
:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}
\RequirePackage{kvoptions}
\RequirePackage{xstring}
\DeclareStringOption{what}
\ProcessKeyvalOptions*
\IfStrEqCase{what}{%
{this}{\dothis}%
{that}{\dothat}%
}%
[Other]%
\newcommand{\dothis}{The magic word is ``this''}
\newcommand{\dothat}{The magic word is ``that''}
\endinput
I strongly suspect there's some simple syntactical error that I can't find. Or else there's something basic that I'm not understanding about either kvoptions
or xstring
I think my syntax for \IfStrEqCase
is OK, because the docs from texdoc xstring
give the form:
\IfStrEqCase⟨[*]⟩{⟨string⟩}{%
{⟨string1⟩}{⟨code1⟩}%
{⟨string2 ⟩}{⟨code2 ⟩}%
etc...
{⟨stringN ⟩}{⟨codeN ⟩}}[⟨other cases code⟩]
My actual purpose
My actual purpose of kvoptions
and xstring
is for a complex document where:
- In one custom package read in as part of the preamble, I set a value for a key for one of several possible document text/math font choices. And in that same package, depending on that value, give the requisite commands to use that text/math font combination. (E.g., with
cm
as the font choice, which will be a default, the requisite command will simply be\usepackage{amsfonts}
; withlucida
as the font choice, instead, the requisite commands will be\usepackage[lucidasmallscale]{lucidabr}
and\linespread{1.04}
.) - A second custom package read in as part of the preamble gives a large set of math command definitions, some of which depend on the math font being used. So this second package will take that key value as option, use it, inside a
\IfStrEqCase
expression, to alter the commands as needed. For example, for thecm
choice, I specify\newcommand{\nsubset}{\not\subset}
and\newcommand{\tendsto}{\rightarrow}
; whereas for thelucida
choice, since\nsubset
is already defined, I don't need to define it, but I usetikz
to create, as the definition for\tendsto
, an arrow that better harmonizes with arrows appearing intikz-cd
diagrams.
The points of this seemingly complicated setup are:
- To allow the font choice to be made by editing a single line in the first package, rather than having to comment and uncomment large blocks of text in source files.
- To allow my second package, with all its math definitions, to be used not just in this particular document, but in any document that may need my specialized math definitions.
kvoptions
orxstring
, but I interpret\IfStrEqCase
as being a choice. If[Other]
is supposed to be within its scope, it should probably be inside the closing brace, but it isn't, and it's being recognized as "text input", so is processed immediately. That's not legit, since text can be accepted only after\begin{document}
, hence the cause of the error message. Better check the documentation for the syntax of\IfStrEqCase
.\IfStrEqCase
syntax is OK, with the[Other]
seemingly dangling at its end.