3

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]
\LoadClass[12pt,a4paper]{report}

\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:

No spaces in the title and subject

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.

Levy
  • 1,167

1 Answers1

5

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....

David Carlisle
  • 757,742