4

I have a class file where I load hyperref. Now I'd like to change the content of hyperref's \pdftitle from the main .tex file on:

\RequirePackage{filecontents}
\begin{filecontents}{myclass.cls}
\ProvidesClass{myclass}
\RequirePackage{kvoptions}

\DeclareStringOption[default title]{pdftitle}
\ProcessKeyvalOptions*
\PassOptionsToPackage{\myclass@pdftitle}{hyperref}
\RequirePackage{hyperref}

\end{filecontents}
\documentclass[pdftitle={This is my title}]{myclass}
\begin{document}
test
\end{document}

Unfortunately I wasn't successful.

Thorsten
  • 12,872
U2430
  • 43

1 Answers1

6

you should provide a package and not a class:

\RequirePackage{filecontents}
\begin{filecontents}{myclass.sty}
\ProvidesPackage{myclass}
\RequirePackage{kvoptions}
\DeclareStringOption[default title]{pdftitle}
\ProcessKeyvalOptions*
\RequirePackage{hyperref}
\hypersetup{pdftitle=\myclass@pdftitle}
\end{filecontents}

\documentclass{article}
\usepackage[pdftitle={This is my title}]{myclass}
\begin{document}
test
\end{document}

pdfinfo then gives the following output:

voss@shania:~> pdfinfo test.pdf
Title:          This is my title
Subject:        
Keywords:       
Author:         
Creator:        LaTeX with hyperref package
Producer:       pdfTeX-1.40.12
CreationDate:   Sat Feb  4 11:01:15 2012
ModDate:        Sat Feb  4 11:01:15 2012
Tagged:         no
Pages:          1
Encrypted:      no
Page size:      612 x 792 pts (letter)
File size:      10835 bytes
Optimized:      no
PDF version:    1.5

for a class you can use it without kvoptions because hyperref already use it.

\RequirePackage{filecontents}
\begin{filecontents}{myclass.cls}
\ProvidesClass{myclass}[12/02/04]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\PassOptionsToPackage{pdftitle={default title}}{hyperref}
\LoadClass{article}
\RequirePackage{hyperref}
\end{filecontents}

\documentclass[12pt]{myclass}
\hypersetup{pdftitle={This is my title}}
\begin{document}
test
\end{document}
  • Thank you for your answer. I just saw this crucial error in my MWE. Of course I wanted to provide a class. I edited my question. – U2430 Feb 04 '12 at 10:13
  • Is there no possibility to do this with a class? I'd prefer to use a class rather than a package. – U2430 Feb 04 '12 at 15:10
  • @U2430: see my edit –  Feb 04 '12 at 17:04