# Using a variable as a package setting within a class

I have defined a new class. Within this class, I am calling on the hyperref package, and I set the following options:

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


Now, I have defined certain variables within this class (which I can call with \variablename{}). However, if I use these within this package, as part of the option settings, then this fails (undefined control sequence). Am I not using the right syntax?

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



• How have you defined \variablename? Can you post an MWE? – cgnieder May 7 '13 at 20:04

The following combination correctly sets the pdfauthor to "Andrew":

test.sty:

\newcommand{\myname}{Andrew}

\RequirePackage{hyperref}

\hypersetup{pdfauthor={\myname}}


main.tex:

\documentclass{article}

\usepackage{test}

\begin{document}
Text.
\end{document}


It is important not to call the \hypersetup command before the variable \myname has been set. However, it could be put in an \AtBeginDocument command to delay processing to the that point.