PDF Bookmarks and Headers

From ConTeXt wiki
Revision as of 11:26, 6 August 2010 by Peter (talk | contribs) (PDF Bookmarks: "force=yes" needed)

PDF Bookmarks

(There are some problems with bookmarks, so the following code may not work, but it should. New pdfTeX should solve the problem - not tested.)

For the impatient (like me), here is a complete example showing typical and useful commands, which are explained below:

\setupinteraction[state=start] % don't forget this line!
% make chapter, section bookmarks visible when opening document
\placebookmarks[chapter,section,subsection][chapter,section]
\setupinteractionscreen[option=bookmark]
\starttext
\chapter{The beginning}
Hi!
\chapter{A very, very\\ long title}
Greetings!
\section{Why so long}
I don't know
\subsection{Why not?}
Good point.
\chapter{The never-ending story}
Oh no.
\chapter{The never-ending story}
\bookmark{Forever!}
Oh no.
\stoptext

You need to activate the interaction handling in order to see the bookmarks by doing \setupinteraction[state=start].

The bookmarks window is not visible by default. To have the bookmark window open automatically when the document is opened:

\setupinteractionscreen
   [option=bookmark] % alternatives are max, fit, doublesided

Disclaimer: On my Ubuntu Linux system, xpdf v3.01 opens the bookmark window whether or not I specify \setupinteractionscreen. I don't know how Adobe's acroread behaves.

To get bookmarks for chapters, sections, and subsections, use:

\placebookmarks[chapter,section,subsection]

In the bookmark window, only chapter bookmarks are visible by default. If chapter and section bookmarks should be visible:

\placebookmarks
   [chapter,section,subsection]
   [chapter]

This will open the document with the bookmarks for chapters and sections visible (read as: and open up the chapter bookmarks)

\title, \subject etc. (the unnumbered headings) do not create bookmarks, even when listed in \placebookmarks. In order to create the bookmarks, you need to add force=yes, for example like this:

\placebookmarks[title, subject][force=yes]

With a long heading in a huge font, you might want to add linebreaks by hand. No problem, just use \\. The bookmark code ignores \\, so the bookmark itself won't have a linebreak. For example:

\setupinteraction[state=start]
\placebookmarks[chapter]
\setupinteractionscreen[option=bookmark]
\starttext
\chapter{Long\\ title}
hello
\stoptext

A more general method, also usable for the above problem, is to use the \bookmark command to specify the bookmark text explicitly. For example:

\setupinteraction[state=start]
\placebookmarks[chapter]
\setupinteractionscreen[option=bookmark]
\starttext
\chapter{A very long chapter\\ about splines}
\bookmark{Splines}
hello
\stoptext

PDF Headers

In order to add Author, Title, Keywords, ... to PDF headers, use:

\setupinteraction
   [state=start,
    title={...},
    author={...},
    subtitle={...},
    keyword={...}]

Prevent certain characters from appearing in pdf headers

To ignore certain TeX commands in \setupinteraction add them to \simplifiedcommands. For example, to ignore \quad in pdfauthor use the following

 \appendtoks
     \let\quad\space
 \to \simplifiedcommands

\setupinteraction
    [author={Author1\quad Author2}]

Using Unicode characters (Mark II, works out of the box in Mark IV)

Accented characters like ä, č, ... will turn into their unaccented counterparts a, c, ... by default. If you want to prevent that, use

\input spec-tst

For example

\enableregime[utf]

\setupinteraction
   [state=start]
\setupinteractionscreen
   [option=bookmark]

% before \placebookmarks
\input spec-tst.tex 

\placebookmarks
   [chapter,section,subsection]
   [chapter]

... and here is your document with accented characters in titles & bookmarks ...