How to provides title and author variable to hypersetup?

I try to set dynamicaly pdf metadata with:

\def\date#1{\def\@date{#1}}
\def\author#1{\def\@author{#1}}
\def\title#1{\def\@title{#1}}
\def\subtitle#1{\def\@subtitle{#1}}
\def\location#1{\def\@location{#1}}
\def\thesisdirector#1{\def\@thesisdirector{#1}}
\def\thesiscodirector#1{\def\@thesiscodirector{#1}}
\def\discipline#1{\def\@discipline{#1}}
\def\doctoralschool#1{\def\@doctoralschool{#1}}
\def\doctoralschoolnumber#1{\def\@doctoralschoolnumber{#1}}
\def\nationalthesisnumber#1{\def\@nationalthesisnumber{#1}}

\makeatletter
\hypersetup{
final       = true,
urlcolor    = blue,
citecolor   = blue,
unicode     = true,
pdfauthor   = {\@author},
pdfkeywords = {biocomputing, biotechnology, software , scientific},
pdftitle    = {\@title},
pdfsubject  = {Genomic expert annotation}
}
\makeatother


or this

\makeatletter
\def\date#1{\def\@date{#1}}

\def\author#1{\gdef\@author{#1}\gdef\@@author{#1}}
\let\@@author\@empty
\def\title#1{\gdef\@title{#1}\gdef\@@title{#1}}
\let\@@title\@empty

\def\subtitle#1{\def\@subtitle{#1}}
\def\location#1{\def\@location{#1}}
\def\thesisdirector#1{\def\@thesisdirector{#1}}
\def\thesiscodirector#1{\def\@thesiscodirector{#1}}
\def\discipline#1{\def\@discipline{#1}}
\def\doctoralschool#1{\def\@doctoralschool{#1}}
\def\doctoralschoolnumber#1{\def\@doctoralschoolnumber{#1}}
\def\nationalthesisnumber#1{\def\@nationalthesisnumber{#1}}

\hypersetup{
final       = true,
urlcolor    = blue,
citecolor   = blue,
unicode     = true,
pdfauthor   = {\@@author},
pdfkeywords = {biocomputing, biotechnology, software , scientific},
pdftitle    = {\@@title},
pdfsubject  = {Genomic expert annotation}
}
\makeatother


This piece of code is put right after required package into my cls file.

But that do not build:

You can't use \spacefactor' in internal vertical mode. \maketitle


I agree with you is a common error. I found lot of report (some ref: 1, 2)

But each time the answer do not have a MWE or do not works

• you have right, I should do it. I found my mistake. I put hypersetup command after required package declaration while title and author variable was defined before begin document. Moving the hypersetup declation after defnied variable fix my problem. Unfortunately I do not found how to do a lazy evaluation to let the hypersetup command into my cls file. Thanks @samcarter, I hope my answer is enough – – bioinfornatics Sep 30 '16 at 12:38

SOLVED

Problem was hypersetup declaration was into my cls file after required package. At this position variable was defined but set to their final values. I move the hypersetup statement after that title and author variable are set. And that works.

in my cls file

\RequirePackage[xetex]{hyperref}
\def\date#1{\def\@date{#1}}
\let\@date\@empty

\def\author#1{\def\@author{#1}}
\let\@author\@empty

\def\title#1{\def\@title{#1}}
\let\@title\@empty

\def\keywords#1{\def\@keywords{#1}}
\let\@keywords\@empty


into main tex file:

\author{blah}
\title{blah}

\makeatletter
\hypersetup{%
final       = true,
urlcolor    = blue,
citecolor   = blue,
unicode     = true,
`