# How to link from a browser to a specific section of document using hyperref?

Hyperref automatically generates bookmarks for document divisions (part, chapter, section) in the PDF output. When opening a document with a browser we can use anchor syntax to link to a specific page or section:

http://website.net/document.pdf#page=4
http://webiste.net/document.pdf#introduction


But what is the format of the default hyperref bookmarks? It's not always their name as it appears in a standard pdf viewer. I haven't been able to find either (a) hyperref's naming procedure or (b) a way of parsing PDFs to display the actual anchor names.

I've found a few Q&A on how to change hyperref's defaults bookmarks. But I want to use the default bookmarks.

My test document below shows the problem. It has parts and chapters. If I open it in a browser using:

/path/to/file/document.pdf#Introduction


The document correctly opens at the introduction chapter page. So linking to divisions works in principle. But I can't find the bookmarks names for other parts and chapters. For instance, the following fail and land me on the title page instead:

/path/to/file/document.pdf#Baby
/path/to/file/document.pdf#Baby Logic
/path/to/file/document.pdf#Baby%20Logic
/path/to/file/document.pdf#Part%20I%20Baby%Logic
/path/to/file/document.pdf#I%20Baby%20Logic
/path/to/file/document.pdf#Syntax%20%and%semantics


Even though some of these are the bookmarks that appear in a PDF viewer.

Added challenge: some sections within different chapters have the same name, and some chapters within different parts have the same name. I don't know how hyperref handles bookmarking those.

Here is the test document:

\documentclass[a4paper]{memoir}

\RequirePackage{hyperref}
bookmarks,
bookmarksopen,
bookmarksopenlevel=1,
urlcolor=dark-gray}

\begin{document}

% title page

{\Huge Title of the book}

\frontmatter

\newpage

\tableofcontents*

\mainmatter

\chapter{Introduction}

\section{dummy section 1}
\section{dummy section 2}
\section{FAQ}

\part{Baby Logic}

\chapter{Syntax and semantics}

\section{dummy section 3}
\section{dummy section 4}
\section{FAQ}

\chapter{Exercises}

\section{dummy section 5}

\chapter{Syntax and semantics}

\section{dummy section 6}
\section{dummy section 7}
\section{FAQ}

\chapter{Exercises}

\end{document}


In your example hyperref generates destinations like chapter.1, part.2, section.4.2 so a name plus the number.

You can find that out by creating an uncompressed pdf with e.g.

\documentclass[a4paper]{memoir}
\usepackage{l3pdf}
\ExplSyntaxOn
\pdf_uncompress:
\ExplSyntaxOff
....


and then search in the pdf for objects with a /Names entry (there can be more than one). E.g.

182 0 obj
<<
/Names [(section.2.3) 34 0 R (section.3.1) 42 0 R (section.4.1) 54 0 R (section.4.2) 58 0 R (section.4.3) 62 0 R]
/Limits [(section.2.3) (section.4.3)]
>>


Alternatively you can use the package option destlabel

\usepackage[destlabel]{hyperref}


then hyperref will try to build destination names based on labels. E.g.

\chapter{Introduction}\label{chap:introduction}


will create the destination chap:introduction

Section 3.2 Options for destination names of the documentation contains more information.

• Anchor names associated with lables, toc, lof or lot will also show up in the aux file. \hypertarget names will not. And don't forget to mention \href{file#name}. – John Kormylo Oct 4 '19 at 22:27