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 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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
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 4 '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 4 '12 at 15:10
    
@U2430: see my edit –  Herbert Feb 4 '12 at 17:04
    
Thanks. This is exactly what I've searched for. –  U2430 Feb 4 '12 at 17:15

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.