# KOMAscript gives error when using parenthesis within options

Coming up from my previous question How to use equal sign inside class option with pgfopts I switched the base class from article to scrartcl and ran into a compile error.

l.451 \FamilyProcessOptions{KOMA} \relax

Missing character: There is no , in font nullfont! Missing character: There is no , in font nullfont! ! You can't use macro parameter character #' in horizontal mode. > @removeelement #1#2#3->\def \reserved@a ##1,#1,## 2\reserved@a {##1,##2\rese... l.451 \FamilyProcessOptions{KOMA}

Here is the example I've used

\begin{filecontents}{\jobname.cls}
\ProvidesClass{\jobname}[2018-11-20 v1.0 SE Test package]
\RequirePackage{pgfopts}
\pgfkeys{
testproj/.cd,
mystuff/.store in = \myValue,
mystuff = {} % <-- Set default to empty
}
\ProcessPgfOptions{/testproj}
\endinput
\end{filecontents}
\documentclass[mystuff={hello=SE,test=1}]{\jobname}
%\pgfkeys{/testproj/mystuff = {hello=SE}} % <-- working as aspected
\begin{document}
myValue: \myValue
\end{document}


Is this a bug in KOMAScript or do I miss something else? The goal is using scrreprt and scrbook.

• basically you can not use {} in \documentclass options. As it happens I'm currently looking at whether it is possible to extend latex here (the easy part) in a way that it is compatible with all existing packages (the hard part) – David Carlisle Nov 20 '18 at 19:45
• Well, I see it is not that easy as expected. But why was it working using article? – faltfe Nov 20 '18 at 19:51
• the KOMA classes have their own key-val handler (they have to process keys like fontsize=12pt), and this is interfering. – Ulrike Fischer Nov 20 '18 at 19:55
• you might have got lucky but \@removeelement  is in the latex format and if the element you try to remove (typically an option from the unused option list) has a brace group it fails rather spectacularly, it just was not written with key=value processing in mind at all. – David Carlisle Nov 20 '18 at 20:01

This might possibly be safe but it's a very delicate area of latex2e code

\begin{filecontents}{\jobname.cls}
\ProvidesClass{\jobname}[2018-11-20 v1.0 SE Test package]
\RequirePackage{pgfopts}
\pgfkeys{
testproj/.cd,
mystuff/.store in = \myValue,
mystuff = {} % <-- Set default to empty
}
\let\zzz \@expandtwoargs
\def\@expandtwoargs#1#2#3{%
\edef\tmp@zz{\noexpand\zzz\noexpand#1{\noexpand\detokenize{#2}}{\noexpand\detokenize{#3}}}%
\tmp@zz}
\ProcessPgfOptions{/testproj}

it detokenizes the arguments (making {} safe) before using \in@` but this may have unexpected consequences elsewhere....