I'm trying to create my own style file (.sty-file) where more or less the whole preamble is defined. The reason behind is, that users of my stylefile just have to use my package and don't have to care about styling.

In my stylefile I create some new commmands like the following:

\newcommand{\theversion}{Version 1.0}
\newcommand{\thedocumenttitle}{My Basic Title}
\newcommand{\theauthor}{John Doe}

Users of my stylefile can now "override" these settings with renewcommand in their actual main file like so:

\renewcommand{\theversion}{Version 2.0}
\renewcommand{\thedocumenttitle}{My Overwritten Title}

Now my problem is the following: I use the hyperref package in the stylefile and also use the hypersetup command:

pdftitle={\thedocumenttitle{} - \theversion{}},

Although I renew the commands in the main file, the old values are used in the hypersetup because the hypersetup is defined in the style and not in the main file. The renewing happens in the main file and therefore after the hypersetup command i guess.

So my questions are:

  1. In general: Is it a good aproach to define commands in the stylefile and let the users of the stylefile renew these commands if needed?
  2. How can I solve my hypersetup issue? Sure, I could put the hypersetup in the main file after the renewcommands. But I don't want the users of the stylefile care about such things. Is there any different (better) approach?

You can delay the execution of \hypersetup for the information entries. However, it must be set before hyperref uses it. Usually this time is \begin{document}, that means, \AtBeginDocument can be used before hyperref is loaded:

    pdftitle={\thedocumenttitle\space - \theversion},%


  • Do not use empty braces inside the entries (\theauthor{}). Macro \theauthor does not have an argument and the braces will remain in the entry.
  • The drawback of this method is that if the end user wants its linkcolor to be red and inserts \hypersetup{linkcolor=red} in its preamble, the \AtBeginDocument{\hypersetup{...,linkcolor=black,...}} from the .sty file will overwrite his setup. Hence the end user has to be told to specify its own \hypersetup choices not in the preamble but in the document's body. I asked a specific question on this subject: tex.stackexchange.com/q/191887/18401. – Denis Bitouzé Jul 17 '14 at 8:20

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.