In your question you say
...\hyperlink{target}{text}
and \hyperref[target]{text}
...
but it should probably be
...\hyperlink{⟨named destination⟩}{⟨text⟩}
and
\hyperref[⟨cross-referencing-label⟩]{⟨text⟩}
...
Don't confuse names of LaTeX's cross-referencing-labels with the names of so called "named destinations"="targets"="anchors" which get placed into the .pdf-file for hyperlinking:
Basically a cross-referencing-label is a record of data maintained via the .aux-files during the LaTeX-run and providing pieces of data holding information that is needed for cross-referencing. A cross-referencing-label exists during a LaTeX-run/exists while the LaTeX-compiler is running and creating the .pdf-file/output-file.
It does not exist when the .pdf-file/output-file that was produced during the LaTeX-run is displayed by a pdf-viewing-application.
The name of the cross-referencing-label is the name of the record. Usually such a record consists of several elements like a page-number and the printed value of some LaTeX-sectioning-counter and - in case hyperref is loaded - the heading of the corresponding section and the name of a "named destination" placed into the .pdf-file for hyperlinking that section/for "navigating" to that section while viewing the .pdf-file. Different referencing-commands can retrieve different elements of such a record.
E.g., with \ref
the printed value of the LaTeX-counter is retrieved. In case the hyperref-package is loaded, the name of the "named destination" which due to some sectioning-command (\section
, \subsection
, ... \caption
etc) automatically got placed at the beginning of the corresponding item of sectioning is retrieved also for turning the printed value into a hyperlink leading to the corresponding item of sectioning.
I tried to explain the concepts related to LaTeX 2ε's cross-referencing-mechanism in my answer to the question "How to prevent reference to enumeration inside new environment?".
A named destination=a target=an anchor -- as already explained by Ulrike Fischer -- is an object which gets placed into the .pdf-file itself and which is used by the .pdf-viewing-application for "navigating" to a specific "place" of the document when viewing the .pdf-file.
A named destination/a target/an anchor does exist when the .pdf-file/output-file is displayed by a pdf-viewing-application.
When loading the hypperref-package, then LaTeX does automatically place such objects/named destinations into the .pdf-file when processing sectioning-commands like \section
, \subsection
, ..., \caption
. Due to the \label
-command (which triggers writing to the .aux-file the record of data which you wish to use for cross-referencing) LaTeX beneath other components also stores as a component of the cross-referencing-label the name of the named destination which was placed automatically by LaTeX as the last one before encountering the \label
-command in question. Referencing-commands like \ref
or \pageref
can extract this piece of data for turning things into hyperlinks.
Besides hyperref's automatic placing of named destinations you can use \hypertarget
for placing a named destination into a .pdf-file "by hand".
The difference between \hyperref[sectionheading]{some text}
and \hyperlink{section.1}{some text}
is:
The optional argument of \hyperref[sectionheading]{some text}
denotes a cross-referencing-label and the \hyperref
-command will wrap the phrase "some text" into a hyperlink by obtaining the name of the corresponding named destination from that cross-referencing-label which basically is a record of data whereof one component denotes the name of a named destination that got placed into the .pdf-file.
The first non-optional argument of \hyperlink{section.1}{some text}
directly denotes the name of a named destination that got placed into the .pdf-file. The name of the named destination is given directly and is not to be obtained as a component from a record of data handled as cross-referencing-label.
If you like it cumbersome you can use the refcount-package for obtaining single components of these records of data that are called cross-referencing-labels and do something like this:
\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}
\usepackage{refcount}
...
\section{section}\label{sectionheading}
...
\IfRefUndefinedBabel{sectionheading}{%
\refused{sectionheading}%
}{%
\hyperlink{\getrefbykeydefault{sectionheading}{anchor}{UndefinedDestination}}%
{some text}%
}
...
With this construct during the first LaTeX-run, i.e., while cross-referencing-labels aren't recorded to the .aux-files yet and thus still are undefined, \refused{...}
will be carried out and you get questionmarks into the .pdf-file and warnings into the .log-file and on the console.
In consecutive LaTeX-runs the name of the named destination belonging to the cross-referencing-label sectionheading
will be extracted from the data-record formed by the cross-referencing-label sectionheading
and delivered to the \hyperlink
-command by the \getrefbykeydefault
-command.
But you don't really need this. \hyperref[sectionheading]{some text}
is shorter and does the same. ;-)