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:



\def\pdftitle{} % define the token to be called in the options
%   sets the token to be a recognizable command in the class options:



        pdftitle = \pdftitle,
        pdfsubject = \pdfsubject

And here an usage example of the class:

    pdftitle = Do You See Spaces Here?,
    pdfsubject = Where Are My Spaces?

    dummy text

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.

  • Even though when I enclose the string with brackets I got no spaces. – Levy Jan 4 '19 at 23:07
  • 3
    That's expected, I'm afraid. The code for absorbing global options zaps all spaces. – egreg Jan 4 '19 at 23:10
  • 2
    Related/possibly interesting github.com/latex3/latex2e/issues/85. – moewe Jan 4 '19 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 '19 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 '19 at 23:23

You can make this work:

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

using input

    pdftitle = {{Do You See Spaces Here?}} ,
    pdfsubject = {{Where Are My Spaces?}}

    dummy text

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.