# How to pass comma in value of a (xkeyval) comma separated list of values at \documentclass level?

At \usepackage level, xkeyval allows us to insert commas in value of a comma separated list of values: it is enough to enclose in braces the values containing commas. For instance, the following MCE works well.

\begin{filecontents*}{mypackage.sty}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]%
\ProvidesClass{mypackage}[2013/11/17 v0.1 A test package]%
%
\RequirePackage{xkeyval}%
%
\def\@separator{}%
%
\DeclareOptionX{separator}[]{\def\@separator{#1}}%
\ExecuteOptionsX{separator}%
\ProcessOptionsX\relax%
%
\newcommand{\twoseparatedvalues}[2]{#1\@separator#2}%
%
\end{filecontents*}
%
\documentclass{article}
\usepackage[separator={,}]{mypackage}
%
\begin{document}
\twoseparatedvalues{foo}{bar}
\end{document}


But AFAICS, at \documentclass level, enclosing values in braces is not possible. For instance, the compilation of the following MCE:

\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]%
\ProvidesClass{myclass}[2013/11/17 v0.1 A test class]%
%
\RequirePackage{xkeyval}%
%
\def\@separator{}%
%
\DeclareOptionX{separator}[]{\def\@separator{#1}}%
\ExecuteOptionsX{separator}%
\ProcessOptionsX\relax%
%
\newcommand{\twoseparatedvalues}[2]{#1\@separator#2}%
%
\end{filecontents*}
%
\documentclass[separator={,}]{myclass}
%
\begin{document}
\twoseparatedvalues{foo}{bar}
\end{document}


throws the error:

! LaTeX Error: Missing \begin{document}.


BTW, passing values without commas at \documentclass level and passing afterwards values with commas enclosed in braces work like a charm, as in the following MCE.

\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]%
\ProvidesClass{myclass}[2013/11/17 v0.1 A test class]%
%
\RequirePackage{xkeyval}%
%
\def\@separator{}%
%
\DeclareOptionX{separator}[]{\def\@separator{#1}}%
\ExecuteOptionsX{separator}%
\ProcessOptionsX\relax%
%
\newcommand{\twoseparatedvalues}[2]{#1\@separator#2}%
%
\end{filecontents*}
%
\documentclass[separator=--]{myclass}
%
\begin{document}
\twoseparatedvalues{foo}{bar}

\setkeys{myclass.cls}{separator={,}}{}%
\twoseparatedvalues{foo}{bar}
\end{document}


Hence my question: how to pass comma in value of a (xkeyval) comma separated list of values at \documentclass level?

• Load the package kvoptions-patch before xkeyval. – Marco Daniel Nov 17 '13 at 10:45
• @MarcoDaniel make that an answer, I was going to answer \newcommand\commasep{,}\documentclass[separator=\commasep]{myclass} but your sounds better:-) – David Carlisle Nov 17 '13 at 10:49

In the documentation of the keyval package kvoptions the separat package kvoptions-patch is also documented.

LATEX’s system of package/class options has some severe limitations that especially affects the value part if options are used as pair of key and value.

So to fix some of the limitations you can load the package kvoptions-patch without loosing the facility of xkeyval -- But you switch to kvoptions, too ;-)

\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]%
\ProvidesClass{myclass}[2013/11/17 v0.1 A test class]%
%
\RequirePackage{kvoptions-patch}%%%NEW
\RequirePackage{xkeyval}%
%
\def\@separator{}%
%
\DeclareOptionX{separator}[]{\def\@separator{#1}}%
\ExecuteOptionsX{separator}%
\ProcessOptionsX\relax%
%
\newcommand{\twoseparatedvalues}[2]{#1\@separator#2}%
%

• Indeed, kvoptions-patch does the trick on the MCE I submitted but unfortunately not in my real use case where the class loads babel and a default language: it leads to the ! Package babel Error: You haven't specified a language option. error (I could provide a MCE that shows the trouble if asked). But I was on the right track with kvoptions-patch as its documentation says xkvltxp package has the same goal and, indeed, everything seems okay with it. – Denis Bitouzé Nov 17 '13 at 14:39
• @DenisBitouzé: I didn't notice this package. Normally I am working with kvoptions or l3keys. tex.stackexchange.com/questions/30013/… – Marco Daniel Nov 17 '13 at 14:44
• I was told some key-val packages newer than xkeyval are more robust and I plan to switch to one of them (kvoptions being in the list of the ones I'll consider). But this will be after the first public release of my class which I delayed too much :) – Denis Bitouzé Nov 17 '13 at 14:51