28

I am trying to generate a PDF file (using pdflatex) with hyperref references; both the title and author should be visible as pdf properties, and both contain accents or non us-ASCII. The rest of the document compiles fine using \documentclass[a4paper,openright]{book}, \usepackage[utf8]{inputenc} and \usepackage[spanish]{babel}.

I would expect this to work:

\usepackage[pdftex,colorlinks=true,
    % ...
    pdftitle={Título con acentos o eñes},
    pdfauthor={Migueláñez}
]{hyperref}

-- it generates around 54 warnings and outputs something like

Title:          T19 tulo con acentos o en126 nes
Author:         Miguela19 an126 nez
Creator:        LaTeX with hyperref package
Producer:       pdfTeX-1.40.10

I have also tried leaving the pdfauthor empty and later using

\pdfstringdef{myauthor}{Miguel\'{a}\~{n}ez}

or

\pdfstringdef{myauthor}{Migueláñez}

and

\hypersetup{pdfauthor={\myauthor}}

But all variants result in errors instead of warnings.

1
  • You can define pdfstringdef like that: \pdfstringdef\mtGEP{gedit \176/.profile} where \176 in this example is octal notation of tilde character. Commented Sep 3, 2013 at 6:34

3 Answers 3

34

Try setting the properties with the command \hypersetup{...} instead of supplying them directly when loading hyperref (hyperref manual, page 4):

\usepackage[colorlinks=false]{hyperref}
\hypersetup{pdftitle={A Perfect Day}}

As seen in the previous example, information entries (pdftitle, pdfauthor, . . . ) should be set after the package is loaded. Otherwise LaTeX expands the values of these options prematurely.

So the following code works fine for me, with the correct author and title displayed in Adobe Reader:

\documentclass[a4paper,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[pdftex,colorlinks=true]{hyperref}
\hypersetup{pdftitle={Título con acentos o eñes},pdfauthor={Migueláñez}}
\begin{document}
    The document
\end{document}
1
  • Works like a charm. And I thought I had tried all the variants. Thanks!
    – tucuxi
    Commented Mar 9, 2011 at 9:26
15

While I think diabonas answer is preferable for Spanish or other non-English documents which anyway use inputenc and babel I like to post an answer which works without them. Just in case of a English-only document written by someone with non-ASCII letters in its name. Especially journals like when you minimize the number of used packages.

The trick is to escape the non-ASCII characters in the following way. Please note, that you can't use them as package option because the LaTeX kernel expands the \<number> sequences first and complains about that e.g. \3 is not defined. Inside \hypersetup they work fine:

\documentclass{book}
\usepackage{hyperref}
\hypersetup{%
    pdfauthor={Miguel\341\361ez},
    pdftitle={T\355tulo con acentos o e\361es}
}
\begin{document}
   Text
\end{document}

Result (output of pdfinfo file.pdf):

Title:          Título con acentos o eñes
Subject:        
Keywords:       
Author:         Migueláñez
...

A list of the needed numbers of special characters can be found e.g. under: http://www.pjb.com.au/comp/diacritics.html

3
  • Thanks Martin - wish I could vote two answers as correct, but diabonas' is slightly easier (no arcane reference for PDF characters required)
    – tucuxi
    Commented Mar 9, 2011 at 9:25
  • @tucuxi: No problem. As I already wrote diabonas answer is normally preferable. I just wanted to add an alternative for other people which want to avoid e.g. babel etc. Commented Mar 9, 2011 at 9:57
  • 1
    With variants like xetex that accept full unicode input (I think) could you just type the name in the document using the real unicode characters? Commented Jun 28, 2012 at 11:36
9

I know that two answers have already been provided but I think mine is different and really handy. Why loading something in the preamble? If one uses inputs it is good to specify the TITLE in the real DOCUMENT FILE, as it logically goes there. If you edit your file with UTF-8 and unicode settings just use

\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[unicode=true,,]{hyperref} %with more options specified if you like

then there is no problem in doing

\newcommand\longtitle{Właśnie tu długi tytuł} %translation: long title
\newcommand\authors{Przemysław Majewski}
\newcommand\headtitle{A tu króciutki} %translation: short title for headers

and then simply stating

%pdf authors and titles for hyperref ---> document specific
\hypersetup{
  pdfauthor={\authors},
  pdftitle={\longtitle},
  pdfsubject={},
  pdfkeywords={hypergeometric,,}
 }

Does it work?

3
  • 1
    Welcome to TeX.sx!
    – Mensch
    Commented Feb 7, 2013 at 19:20
  • thanks for the "unicode=true" option! without this option my characters were transliterated into latin letters.
    – MariusM
    Commented Feb 4, 2016 at 16:12
  • 1
    The accepted solution does not work with LuaLaTeX. This one works with LuaLaTeX, while PDFLaTeX and XeLaTeX still work. So I might add [unicode=true] from now on by default. Or has it any drawbacks?
    – John
    Commented Feb 8, 2018 at 8:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .