[Tex/LaTex] link size and color (nameref)

colorhyperref

I create a link with \nameref:

\section*{\Huge {\color{DarkRed}This is a headline}}
\label{sec:headline}

When I reference to this section with

\nameref{sec:headline}

The link is displayed the same size (Huge) and color (Dark Red) as the section title.

The hyperref setup is:

\usepackage[colorlinks=true,linkcolor=black]{hyperref}

How can I avoid that link color and size are taken from the section setup. I want to keep them independent from one another.

EDIT: Minimal working example:

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black]{hyperref}
\begin{document}

\nameref{sec:headline}

\newpage
\section*{\Huge {\color{red}This is a headline}}
 \label{sec:headline}

\end{document}

Best Answer

If you want to change the appearance in general, then use a more powerful class (scrartcl/KOMA-Script, memoir, …) or a package (sectsty, …):

  • Then you have a clean markup.
  • It also works for the table of contents or the page headers.

Package gettitlestring

Package hyperref uses package nameref. Since 2009/12/08 it uses package gettitlestring to get and process the title data. With method expand commands can be redefined via \GetTitleStringDisableCommands similar to hyperref's \pdfstringdefDisableCommands for bookmarks.

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black]{hyperref}
\usepackage{nameref}[2009/12/08]% uses package `gettitlestring'

\GetTitleStringSetup{expand}
\GetTitleStringDisableCommands{%
  \let\Huge\empty % disables \Huge
  % or \renewcommand*{\Huge}{}%
  \let\color\@gobble % disables \color{...}
  % or \renewcommand*{\color}[1]{}%
}

\begin{document}

\nameref{sec:headline}

\newpage
\section*{\Huge {\color{red}This is a headline}}
 \label{sec:headline}

\end{document}

However, only expandable redefinitions can be used. LaTeX's scanning for optional arguments does not work.

Related Question