I know hypersetup from hyperref needs to be added before \begin{document} but after \usepackage{hyperref} and \usepackage{bookmark}.
For example, you can inject it like the following to ensure this:
\AtBeginDocument{\hypersetup{}}
Problem
I'd like to have links (particularly linkcolor) that appear in section headings inherit the color of the section heading (I am using titlesec to redefine all of my headings). This means I would need to redefine / override the original colors defined within \hypersetup{}.
Code
Note that I only kept bookmark in there because of its fastidious relationship with hyperref.
\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{bookmark}
\hypersetup{
colorlinks=true,
linkcolor=red!80!black,
urlcolor=green!50!black,
hyperfootnotes=false,
hypertexnames,
bookmarks=true}% Causes clash if hyperref parameters loaded before bookmark, because bookmark loads hyperref without any parameters
\renewcommand{\sectionautorefname}{Section}
\usepackage[compact,explicit,noindentafter]{titlesec}
\titleformat{\section}[hang]{\bookmarksetupnext{bold,color=blue!50!black,open=false}\color{blue!50!black}\large\bfseries}{\thesection}{1em}{\hyphenchar\font=-1 #1}[\hyphenchar\font=\defaulthyphenchar] % \hyphenchar\font=-1 disables hyphenation, which I reset back to 1 after typesetting the section. see https://tex.stackexchange.com/a/44362/13552
\begin{document}
\section{Always remember that you are absolutely unique. Just like everyone else.}
\label{sec:quote}
Margaret Mead
\section{Should not be colored: \nameref{sec:quote}}
This link should be colored: \nameref{sec:quote}. And this one: Section~\ref{sec:quote}. And this one: \autoref{sec:quote}. And this one: \pageref{sec:quote}.
\end{document}




\hyphenchar\font=-1is not good practice. You turn off hyphenation but text will still be forced to a justified layout. Prepare for underfull/overfull boxes.\raggedrightis much better! – Henri Menke Apr 19 '16 at 07:30\raggedrightdoes not always work. I think it had something to do with the scope of\raggedrightnot affectingtikz's scope within my section definition (not in my minimal example).\hyphenchar\font=-1has a much broader scope, which is why I needed to redefine it to\hyphenchar\font=1just before finishing the heading code. This way it is not harmful to the rest of the body. A couple underfull/overfull boxes never hurt anybody :-p They actually look good in my setup (I have some fancy TikZ action going on with much whitespace) – Jonathan Komar Apr 19 '16 at 07:34\hypersetup{hidelinks}instead. – sodd Apr 19 '16 at 07:44\hyphenchar\font=\defaulthyphencharor\hyphenchar\font=`-. – Henri Menke Apr 19 '16 at 07:52hidelinksaffects all types of links not justlinkcolor(url color, link color, etc.). This makes the color macro idea still viable. Good tip though! – Jonathan Komar Apr 19 '16 at 07:59\colorlet{sectioncolor}{blue!50!black}and specifysectioncoloras the textcolor andlinkcolorin section titles. No need to make simple things complicated. Am I missing something? – sodd Apr 19 '16 at 08:10titlesecheading definitions would be nice). Note that we are talking about shades here, but nevertheless, they are different. Examples I that provide use striking, non-harmonious colors to ensure that the differences between them are obvious. – Jonathan Komar Apr 19 '16 at 08:13