# String parameter passed to a class vanish the spaces between words

I created a class in which I'd like to pass some parameters in \documentclass[parameters]{}. The parameters I need to pass are pdftitle and pdfsubject to the hyperref package. I succeeded in doing so, but if exist spaces in the title they simply vanish. So far I have written the following in my class:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{klass}[2019/01/02]

\RequirePackage{xkeyval}

\def\pdftitle{} % define the token to be called in the options
%   sets the token to be a recognizable command in the class options:
\define@key{klass.cls}{pdftitle}[]{\def\pdftitle{#1}}

\def\pdfsubject{}
\define@key{klass.cls}{pdfsubject}[]{\def\pdfsubject{#1}}

\ExecuteOptionsX{pdftitle,pdfsubject}
\ProcessOptionsX

\RequirePackage{hyperref}
\hypersetup{
pdftitle = \pdftitle,
pdfsubject = \pdfsubject
}


And here an usage example of the class:

\documentclass[
pdftitle = Do You See Spaces Here?,
pdfsubject = Where Are My Spaces?
]{klass}

\begin{document}
dummy text
\end{document}


You can see in the options that the pdftitle and pdfsubject got rid of the spaces:

Although I could simply write those options in the document, they need to be in the class file. So here's my question: how do I preserve the spaces in the string I pass as a parameter? I'm compiling it with LuaLaTeX.

• Even though when I enclose the string with brackets I got no spaces. – Levy Jan 4 at 23:07
• That's expected, I'm afraid. The code for absorbing global options zaps all spaces. – egreg Jan 4 at 23:10
• Related/possibly interesting github.com/latex3/latex2e/issues/85. – moewe Jan 4 at 23:11
• @moewe I changed the name of class in the code (it was different), try to compile again to see if it works now. – Levy Jan 4 at 23:21
• Sure. LaTeX zaps them as egreg explained and you can't even protect spaces from zapping by enclosing them in a brace group. – moewe Jan 4 at 23:23

You can make this work:

Title:          Do You See Spaces Here?
Subject:        Where Are My Spaces?


using input

\documentclass[
pdftitle = {{Do You See Spaces Here?}} ,
pdfsubject = {{Where Are My Spaces?}}
]{klass}

\begin{document}
dummy text
\end{document}


The fact that you need braces to protect the spaces is an unfortunate feature of the core latex option handling, the fact that you need double braces and a space before the comma seems to be a feature of xkeyval's version of key=value parsing.

There are some plans to have an option not to drop spaces here but it is a tricky area, changing anything has the potential to break every latex document....