Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  cgnieder Oct 28 '12 at 23:04
add comment

1 Answer

up vote 4 down vote accepted

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]

\hypersetup{hidelinks}
\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}

Result

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.