Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use the hyperref package and defined custom settings as follows:

\usepackage{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{url}
\usepackage{hyperref}

\hypersetup{
    bookmarks=true,         % show bookmarks bar?
    unicode=false,          % non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        % show Acrobat’s toolbar?
    pdfmenubar=true,        % show Acrobat’s menu?
    pdffitwindow=false,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={My title},    % title
    pdfauthor={Author},     % author
    pdfsubject={Subject},   % subject of the document
    pdfcreator={Creator},   % creator of the document
    pdfproducer={Producer}, % 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=red,          % color of internal links
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=OliveGreen     % color of external links
}

I saw here that I can somehow put these settings into an external file to slim down the preamble. I created a hyperref.sty and moved the \hypersetup{} part in there. I noticed that it is considered in the compilation process, however, it fails.

Question:

What is the proper way to externalize the options for the hyperref package?

share|improve this question
1  
If you load the package xcolor there is no need to load color. You can externalize the setup in an extra file which can be include by input –  Marco Daniel Sep 7 '12 at 17:32

2 Answers 2

up vote 8 down vote accepted

just place the hypersetup command into myfile.tex then

\input{myfile}

don't create a file called hyperref.sty or you will prevent the original loading.

share|improve this answer

hyperref.cfg

If the file hyperref.cfg exists, then package hyperref loads this file right before it processes its options. Therefore you can put many option settings via \hypersetup in this file. Options for PDF informations should be loaded after the package hyperref is loaded. In hyperref.cfg this can be done via:

\AtEndOfPackage{%
  \hypersetup{pdfauthor={me}, ...}%
}

An extended example for hyperref.cfg:

\hypersetup{%
  bookmarks,%
  pdfencoding=auto,%
  colorlinks,%
  ...
}%
\AtEndOfPackage{%
  \hypersetup{%
    pdfauthor={...},%
    ...
  }%
  \RequirePackage{bookmark}%
}%

myhyperref.cfg

In your original approach you cannot use hyperref.sty as file name, because this name is already used by the package itself. But via \input a different file name can be loaded:

\input{myhyperref.cfg}

But after hyperref is loaded, some options cannot be changed anymore.

Package myhyperref

A third approach is to write a small package:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myhyperref}[2012/09/07 v1.0]

\RequirePackage[dvipsnames]{xcolor}
\RequirePackage[
  bookmarks,
  colorlinks,
  pdfencoding=auto,
]{hyperref}
\RequirePackage{bookmark}
\bookmarksetup{
  numbered,
  open,
}
\hypersetup{
  linkcolor=red,
  % ...
  pdfauthor={me},
  % ...
}

\endinput

Then the package is loaded via \usepackage in the main document:

\documentclass{...}
...
\usepackage{myhyperref}
...
\begin{document}
...
\end{document}
share|improve this answer
    
How do I know which options have to be loaded before or after the package hyperref is loaded? –  JJD Sep 7 '12 at 19:29
    
hyperref warns if an option is used too late. –  Heiko Oberdiek Sep 7 '12 at 19:33
    
When I use your myhyperref example I end up with this error: Option clash for package hyperref. at line 10. I load the package as the last one. –  JJD Sep 7 '12 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.