I use XeLaTeX with fontspec, polyglossia, biblatex and hyperref packages (etc.) to typeset my documents as \documentclass[11pt,a4paper]{article} . The hyperref package is just awesome, however, I have found a really annoying bug.

I want the pdftitle to use a combination of some static text and a previously defined variable \thetitle. So far so good. The problem arises when this variable contains line breaks (\\). hyperref seems to simply omit them automatically but I want to be able to control this manually.

To get rid of the line breaks I use this macro \replacelinebreaks{}{}:

% A macro to remove line breaks from any text #1 and replace them 
% with #2 (can be void). E.g.: \replacelinebreaks{\thetitle}{\ }. 

(The credit for it goes mostly to Easy way to remove formatting (e.g. linebreaks).) This macro works fine everywhere throughout the document - except in \hypersetup{pdftitle= ...}.

What am I missing here? There are quite a lot of very similar questions on this site, but none seems to solve my particular problem:

Here is my MWE:

% !BIB TS-program = biber
% !TeX program = xelatex
% !TeX encoding = UTF-8
% !TeX spellcheck = en_GB



\def\thetitle{Type the\\Minimum Working Example\\Title Here\\}      
\def\firstauthor{Abra}      % Only the first author 
\def\theauthor{\firstauthor %  Add all other authors (no spaces! Use "\\" and "%")

    pdftitle    = MWE No.1 \space -- \replacelinebreaks{\thetitle}{\ },
    pdfauthor   = \replacelinebreaks{\theauthor}{; },


It results in:

enter image description here

Please help me understand and correct this behaviour, so I could either use my \replacelinebreaks macro or achieve my goal in some other way. Your help is much appreciated.

  • 1
    Why don't you provide some code for tests? Commented Feb 3, 2017 at 12:06
  • @Ulrike Fischer: MWE is now provided. I am running some tests for your proposed solution. Commented Feb 3, 2017 at 13:06

1 Answer 1


You always can redefine the way hyperref handles such tokens:



\hypersetup{pdftitle= abc\\ cde\myvar}



enter image description here

Or you can define your variable so that it uses in sensible places \texorpdfstring:



\hypersetup{pdftitle= abcXXXcde\myvar}


  • Do these commands affect only hyperref or the whole document? In my case, the \pdfstringdefDisableCommands{\def\\{ }}works fine for \thetitle, but not for \theauthor, where line breaks have to be replaced not with space, but with "; ". It seems that I cannot have two such exceptions at once ... Commented Feb 3, 2017 at 13:37
  • You can add another set: \pdfstringdefDisableCommands{\def\\{YYY}}\hypersetup{pdfauthor= abc\\ cde\myvar} and later set the definition to someelse, e.g. for the bookmarks. Commented Feb 3, 2017 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .