# Change nameddest default name

Adobe defines parameters that allow you to open a PDF document with a command or URL that specifies exactly what to display (a named destination or specific page), and how to display it (using such characteristics as a specific view, scrollbars, bookmarks, annotations, or highlighting).

My question is:

Is there a way to change the pdf nameddest generated by a LyX document? The default parameters are Chapter.1, Chapter.2, Chapter.3... Section.1.1, Section.1.2, Section.3.2...

for example, in the browser, to open a pdf document (generated by lyx or tex) on a determinated spot:

file:///C:/teste1.pdf#nameddest=chapter.4
file:///C:/teste1.pdf#nameddest=section.2.4


I need to change these default names, the document is always being updated so references to chapters and sections have a high turnover.

Maybe a renew command, like \renewcommand{\section}{}?

-
nobody knows? :( –  Marco Coradini Oct 21 '11 at 19:49
You could try asking in the lyx-users mailing list, that can be found at lyx.org/MailingLists –  Torbjørn T. Dec 3 '11 at 23:57

The links and destinations are added by package hyperref. Because destinations need different names, the names are composed by the counter name and the counter value.

But having a symbolic destination name is indeed a useful feature. Therefore I have implemented such a feature in hyperref 2012/07/28 v6.82u. It is enabled by package option destlabel. Later it cannot be enabled using \hypersetup.

With option destlabel the name of the first \label after an anchor setting is used to set the destination name that is used in the next LaTeX run.

For a better understanding of the destination name stuff in hyperref I have written a section to the hyperref manual that I here quote for convenience.

Options for destination names

Destinations names (also anchor, target or link names) are internal names that identify a position on a page in the document. They are used in link targets for inner document links or the bookmarks, for example.

Usually anchor are set, if \refstepcounter is called. Thus there is a counter name and value. Both are used to construct the destination name. By default the counter value follows the counter name separated by a dot. Example for the fourth chapter:

chapter.4


This scheme is used by:

• \autoref displays the description label for the reference depending on the counter name.
• \hyperpage is used by the index to get page links. Page anchor setting (pageanchor) must not be turned off.

It is very important that the destination names are unique, because two destinations must not share the same name. The counter value \the<counter> is not always unique for the counter. For example, table and figures can be numbered inside the chapter without having the chapter number in their number. Therefore hyperref has introduced \theH<counter> that allows a unique counter value without messing up with the appearance of the counter number. For example, the number of the second table in the third chapter might be printed as 2, the result of \thetable. But the destination name table.2.4 is unique because it has used \theHtable that gives 2.4 in this case.

Often the user do not need to set \theH<counter>. Defaults for standard cases (chapter, \dots) are provided. And after hyperref is loaded, new counters with parent counters also define \theH<counter> automatically, if \newcounter, \@addtoreset or \numberwithin of package amsmath are used.

Usually problems with duplicate destination names can be solved by an appropriate definition of \theH<counter>. If option hypertexnames is disabled, then a unique artificial number is used instead of the counter value. In case of page anchors the absolute page anchor is used. With option plainpages the page anchors use the arabic form. In both latter cases \hyperpage for index links is affected and might not work properly.

If an unnumbered entity gets an anchor (starred forms of chapters, sections, …) or \phantomsection is used, then the dummy counter name section* and an artificial unique number is used.

If the final PDF file is going to be merged with another file, than the destination names might clash, because both documents might contain chapter.1 or page.1. Also hyperref sets anchor with name Doc-Start at the begin of the document. This can be resolved by redefining \HyperDestNameFilter. Package hyperref calls this macro each time, it uses a destination name. The macro must be expandable and expects the destination name as only argument. As example, the macro is redefined to add a prefix to all destination names:

\renewcommand*{\HyperDestNameFilter}[1]{\jobname-#1}


In document docA the destination name chapter.2 becomes docA-chapter.2.

Destination names can also be used from the outside in URIs(, if the driver has not removed or changed them), for example:

http://somewhere/path/file.pdf#nameddest=chapter.4


However using a number seems unhappy. If another chapter is added before, the number changes. But it is very difficult to pass a new name for the destination to the anchor setting process that is usually deep hidden in the internals. The first name of label after the anchor setting seems a good approximation:

\section{Introduction}
\label{intro}


Option destlabel checks for each \label, if there is a new destination name active and replaces the destination name by the label name. Because the destination name is already in use because of the anchor setting, the new name is recorded in the .aux file and used in the subsequent LaTeX run. The renaming is done by a redefinition of \HyperDestNameFilter. That leaves the old destination names intact (e.g., they are needed for \autoref). This redefinition is also available as \HyperDestLabelReplace, thus that an own redefinition can use it. The following example also adds a prefix for all destination names:

\renewcommand*{\HyperDestNameFilter}[1]{%
\jobname-\HyperDestLabelReplace{#1}%
}


The other case that only files prefixed that do not have a corresponding \label is more complicate, because \HyperDestLabelReplace needs the unmodified destination name as argument. This is solved by an expandable string test (\pdfstrcmp of pdfTeX or \strcmp of XeTeX, package pdftexcmds also supports LuaTeX):

\usepackage{pdftexcmds}
\makeatletter
\renewcommand*{\HyperDestNameFilter}[1]{%
\ifcase\pdf@strcmp{#1}{\HyperDestLabelReplace{#1}} %
\jobname-#1%
\else
\HyperDestLabelReplace{#1}%
\fi
}
\makeatother


With option destlabel destinations can also named manually, if the destination is not yet renamed:

\HyperDestRename{<destination>}{<newname>}


Hint: Anchors can also be named and set by \hypertarget.

-