I'm trying to write a custom package MyUnicodefonts where I'd like to store all my font settings for various math fonts and roman fonts (later also mono and sans).
In my document I intend to choose the font with a key-value option, like:
\documentclass{article}
\usepackage[math=xits,roman=myriad]{MyUnicodefonts}
\usepackage{blindtext}
\begin{document}
\blindmathpaper
\end{document}
For the package file MyUnicodefonts.sty I used the switch from this answer as is appeared handy and sufficient for me and I didn't understood the other answers. I tried to apply it for string comparison.
Using the kvoptions package my file finally looks as follows:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{MyUnicodefonts}[2015/06/21 Load fonts]
\RequirePackage{fontspec}
\RequirePackage{kvoptions}
\DeclareStringOption[minion]{roman}
\DeclareStringOption[xits]{math}
\ProcessKeyvalOptions*
\RequirePackage{xifthen}
\newcommand{\ifequals}[3]{\ifthenelse{\ifstrequal{#1}{#2}{TRUE}{}}{#3}{}}
\newcommand{\case}[2]{#1 #2} % Dummy, so \renewcommand has something to overwrite...
\newenvironment{switch}[1]{\renewcommand{\case}{\ifequals{#1}}}{}
\begin{switch}{\MyUnicodefonts@roman}
\case{minion}{\setmainfont[Numbers = OldStyle,
Ligatures = TeX,
]{Minion Pro}}
\case{myriad}{\setmainfont[Numbers={Uppercase,OldStyle},
]{Myriad Pro}}
\end{switch}
\begin{switch}{\MyUnicodefonts@math}
\case{xits}{%
\RequirePackage{unicode-math}
\setmathfont{XITS Math}
\setmathfont[range={"002B,"002D,"003A-"003E} ]{MnSymbol} % + - < = >
}
\case{iwona}{%
\RequirePackage[math]{iwona}
\RequirePackage[mathscr]{eucal}
}
\end{switch}
\endinput
As the kvoptions manual is lacking a comprehensive example I fail to identify the reason for the appearing Undefined control sequence error.
The error would disappear if I'd load unicode-math
also before the switch, but I don't want that, as there will be cases, where I don't want to use an unicode-math font. However a new error appears:
! Missing number, treated as zero. \begingroup l.18 \case{myriad}{\setmainfont{Myriad Pro}} A number should have been here; I inserted '0'. (If you can't figure out why I needed to see a number, look up 'weird error' in the index to The TeXbook.)
Which I don't understand, as I substituted the \equal{#1}{#2}
from the original switch (see linked answer) to \ifstrequal{#1}{#2}{TRUE}{}
.
I hope you can help me find the error or suggest a completely different approach.
\ifstrequal
. It is defined by packageetoolbox
, which is not loaded. This and how option strings are processed further are not related to packagekvoptions
.