# Distinguish \nameref references in print version

I used the \nameref command to reference to names of captions etc. I also used the option colorlinks=true so I have colored references which can be distinguished form "normal" text.

In my print version of the document I colored the links to black. Now I'd like to set them to italic or surround them with apostrophes or something like that.

I already tried to renew the \nameref command, but I didn't get it to work

\renewcommand{\nameref}{\emph{\nameref{#1}}}


I allways get an error message, which says

LaTeX Error: \namref undefined.

Any ideas?

-
Welcome to TeX.sx! – hpesoj626 Oct 28 '12 at 22:54
If it is exactly that message then you have a typo. The redefinition can't work this way, though. See tex.stackexchange.com/a/48575/5049 for reasons why. – clemens Oct 28 '12 at 23:04

Option hidelinks is available since hyperref 2011/02/05 v6.82a. \nameref can be redefined the following way (assuming the star form is not needed):

\documentclass{article}
\usepackage{hyperref}[2011/02/05]

\usepackage{letltxmacro}
\makeatletter
\AtBeginDocument{%
\@ifdefinable{\myorg@nameref}{%
\LetLtxMacro\myorg@nameref\nameref
\DeclareRobustCommand*{\nameref}[1]{%
\emph{\myorg@nameref{#1}}%
}%
}%
}
\makeatother

\begin{document}
\section{Hello World}
\label{sec:hello}
This is section \nameref{sec:hello}.
\end{document}


-
Would you consider something like \LetLtxMacro*\newcs\oldcs that checks whether \newcs is already defined? – egreg Oct 28 '12 at 23:22
@egreg You can already use \LetLtxMacro\newcs\oldcs if \oldcs is undefined. Then \newcs is just undefined (as \let would have done). An error/warning message does not help much, if then \newcs is defined with \oldcs. Therefore I have used \@ifdefinable to get an error message and to disable the redefinition. – Heiko Oberdiek Oct 29 '12 at 1:21
The error would be raised anyway, and such redefinitions by a user (as opposed to a package writer) are usually made during document preparation, so it's not so important that the compilation is "almost successful". In any case the code must be corrected. – egreg Oct 29 '12 at 8:36

Starting of what you wrote, I've made this :

\newcommand{\Newnameref}[1]{\textit{\nameref{#1}}}


The [1] says that this command will only take one input, and the #1 is what you'll write bewteen braces in yous source file.

You'll use it like this :

\Newnameref{sec:section1}


It works for me ;)

-