# Getting user defined constants into the preamble

I think this is a problem of expandable content, a concept I haven't quite got the hang of yet...

Lets say I have a preamble or cls file that is trying to configure hyperref. If I have manually setup a command for the author using \newcommand{\Me}{EngBIRD} I can then use it when configuring the document properties like so:

\hypersetup{
pdfauthor={\Me},                % author
pdfcreator={\Me},               % creator of the document
pdfproducer={\Me}               % producer of the document
}


Problem: In the template I am creating, the tex file is just a template. It links to content in tex files (such as the demo file LaTeX_Personal_Details.autotex) which have have been automatically created local to the project.

\long\def\PersonalFirstName{I.}
\long\def\PersonalMiddleName{Eng}
\long\def\PersonalLastName{BIRD}
\long\def\PersonalPhoneNumber{Phone Number here}
\long\def\PersonalAddressLineOne{Street Address Here}
\long\def\PersonalAddressLineTwo{City, Province, Country Address Here}
\long\def\PersonalEmail{Email Here}


This content is then included and used using custom designed commands that the MWE will illustrate.

I have tried a bunch of command definitions (see the commented out lines below xparse) but I am sure they aren't working because the hypersetup is populated with an unexpanded macro that hasn't even imported it's data yet... I thought the multiple compile iterations would work around the order problem, so I am left thinking that this is an expandable content problem...

Is there a way I can allow the user information stored in the pdf properties to be driven by the same data that populates the document? Was I maybe on the right track with DeclareExpandableDocumentCommand but just stuck with it's requirement that the last argument not be optional (this I don't understand either when default values can be passed and are not empty)?

\documentclass{article}

\usepackage{xparse}

%\DeclareExpandableDocumentCommand{\Me}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }{#1~#2~#3} % has potential, but doesn't compile with only optional arguments
%\DeclareDocumentCommand{\Me}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }{#1~#2~#3}
%\def\Me#1{\gdef\@Me{#1}}
%\Me{\PersonalFirstName~\PersonalMiddleName~\PersonalLastName}

%\newcommand{\Me}{\PersonalFirstName~\PersonalMiddleName~\PersonalLastName}

\newcommand{\Me}{EngBIRD}

\DeclareDocumentCommand{\CustomTitleBlock}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }
{%
{#1~#2~#3}
}%

\makeatletter
\DeclareDocumentCommand{\PersonalDataBlock}{ }
{%
{E-mail:}\PersonalEmail

{Phone:}\PersonalPhoneNumber

{Address:}\PersonalAddressLineOne{,}\PersonalAddressLineTwo
}%
\makeatother

%=========================================================================================================================================
% PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
%=========================================================================================================================================

\usepackage{hyperref}
\usepackage[noabbrev]{cleveref}

\hypersetup{
breaklinks=true,
hypertexnames=false,
%bookmarks=false,               % show bookmarks bar?
unicode=true,                   % non-Latin characters in Acrobat's bookmarks
pdftoolbar=true,                % show Acrobat's toolbar?
pdfmenubar=true,                % show Acrobat's menu?
pdffitwindow=true,              % window fit to page when opened
pdfstartview={FitV},            % fits the height of the page to the window:  or fits the width of the page to the window  FitH
pdftitle={CV - \Me},            % title
pdfauthor={\Me},                % author
%pdfsubject={Subject},          % subject of the document
pdfcreator={\Me},               % creator of the document
pdfproducer={\Me},              % producer of the document
%pdfkeywords={keyword1} {key2} {key3}, % list of keywords
pdfnewwindow=true,              % links in new window
colorlinks=true,                % false: boxed links; true: colored links
linkcolor=black,                % color of internal links (change box color with linkbordercolor)
citecolor=black,                % color of links to bibliography
filecolor=black,                % color of file links
urlcolor=black                  % color of external links
}

%--------------------BEGIN DOCUMENT----------------------
\begin{document}

%--------------------Load Data for Title and Contact information-------------
\input{LaTeX_Personal_Details.autotex}

%--------------------TITLE-------------
\CustomTitleBlock

%--------------------CONTACT INFORMATION-----------------------------------
\PersonalDataBlock

\end{document}

• You should use \providecommand{\PersonalFirstName}{} etc. to make them at least defined when \Me comes into action. I think that a key-value interface might be better here, using a command with an mandatory argument. – user31729 Mar 31 '16 at 15:19
• at the very least you'd need to input LaTeX_Personal_Details.autotex earlier before you use the commands it defines. – David Carlisle Mar 31 '16 at 15:19
• @ChristianHupfer - Will try that now. Are you suggesting replacing the \long\def\PersonalFirstName with providecommand or are you still using both? Sorry this feels like a dumb question. – EngBIRD Mar 31 '16 at 15:22
• \Me is using commands from LaTeX_Personal_Details.autotex. hypersetup is using \Me. This means the commands must be known when hypersetup is executed. You must input the file earlier as David already wrote. – Ulrike Fischer Mar 31 '16 at 15:27

## 1 Answer

I think you want to generate

Title:          CV - I. Eng BIRD
Subject:
Keywords:
Author:         I. Eng BIRD
Creator:        I. Eng BIRD
Producer:       I. Eng BIRD
CreationDate:   Thu Mar 31 16:27:05 2016
ModDate:        Thu Mar 31 16:27:05 2016


Which I got from

\documentclass{article}

\usepackage{xparse}

\input{LaTeX_Personal_Details.autotex}

\newcommand{\Me}{\PersonalFirstName\space\PersonalMiddleName\space\PersonalLastName}

\DeclareDocumentCommand{\CustomTitleBlock}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }
{%
{#1~#2~#3}
}%

\makeatletter
\DeclareDocumentCommand{\PersonalDataBlock}{ }
{%
{E-mail:}\PersonalEmail

{Phone:}\PersonalPhoneNumber

{Address:}\PersonalAddressLineOne{,}\PersonalAddressLineTwo
}%
\makeatother

%=========================================================================================================================================
% PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
%=========================================================================================================================================

\usepackage{hyperref}
\usepackage[noabbrev]{cleveref}

\hypersetup{
breaklinks=true,
hypertexnames=false,
%bookmarks=false,               % show bookmarks bar?
unicode=true,                   % non-Latin characters in Acrobat's bookmarks
pdftoolbar=true,                % show Acrobat's toolbar?
pdfmenubar=true,                % show Acrobat's menu?
pdffitwindow=true,              % window fit to page when opened
pdfstartview={FitV},            % fits the height of the page to the window:  or fits the width of the page to the window  FitH
pdftitle={CV - \Me},            % title
pdfauthor={\Me},                % author
%pdfsubject={Subject},          % subject of the document
pdfcreator={\Me},               % creator of the document
pdfproducer={\Me},              % producer of the document
%pdfkeywords={keyword1} {key2} {key3}, % list of keywords
pdfnewwindow=true,              % links in new window
colorlinks=true,                % false: boxed links; true: colored links
linkcolor=black,                % color of internal links (change box color with linkbordercolor)
citecolor=black,                % color of links to bibliography
filecolor=black,                % color of file links
urlcolor=black                  % color of external links
}

%--------------------BEGIN DOCUMENT----------------------
\begin{document}

%--------------------Load Data for Title and Contact information-------------

%--------------------TITLE-------------
\CustomTitleBlock

%--------------------CONTACT INFORMATION-----------------------------------
\PersonalDataBlock

\end{document}