Using spaces in class options is basically not supported by the latex2e engine (see github issue). There are some workarounds for that problem but these work not for every class (and therefore it usually won't work for your own class as you usually would write a class which based on another class). General speaking you should avoid spaces in class options (at least for latex2e, maybe there are better solutions for Latex3). However if you insist on it, in the following are given three solutions which at least work with some classes.
Solution 1: Using pgfopts
.tex file:
\documentclass[title={with space and, comma}]{xyz}
\begin{document}
the Title is \title
\end{document}
xyz.cls file:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{xyz}[2020/07/14]
\RequirePackage{pgfopts}
\LoadClass{article}
\pgfkeys{
/xyz/.cd,
title/.store in=\xyz@title
}
\ProcessPgfOptions{/xyz}
\renewcommand{\title}{\xyz@title}
This doesn't work with KOMAscript (in the linked thread is shown a workaround for it but I didn't try it).
Solution 2: Using xkeyval
See this thread for a minimum working example. As shown in the linked thread you need in opposite to the hyperref
package two instead of one curly brackets before and after the value. This will also not work with KOMAScript (for the same reason as for Solution 1).
Solution 3: Loading kvoptions-patch
before \documentclass in the .tex file
I don't know how to get the kvoptions-patch
working in the .cls
file but for some reason it is working with out problem when it is loaded before the \documentclass
command inside the .tex
file.
.tex file:
\RequirePackage{kvoptions-patch}
\documentclass[title=with space]{xyz}
\begin{document}
the Title is: \printTitle
\end{document}
xyz.cls file:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{xyz}[2020/07/14]
\RequirePackage{kvoptions}
\LoadClass{article}
\DeclareStringOption[]{title}
\ProcessKeyvalOptions*
\newcommand{\printTitle}{\xyz@title}
In addition to the obvious disadvantage that it is confusing for class users that they need to load the kvoptions
package before the \documentclass
another drawback of this method is that you can't use commas inside values (e.g in the title in the above example). However this solution also works with KOMAScript.
\documentclass
). Can you make a small MWE, please? – egreg Apr 19 '15 at 12:17xkeyval
andxkvltxp
instead ofkvoptions
. – FKranhold Apr 21 '15 at 19:17