I wish to redefine \nameref so that its output is printed in italics. However, I'm apparently doing something wrong, because I'm getting an error saying
\nameref undefined. \renewcommand{\nameref}
MWE:
\documentclass{article}
\usepackage{hyperref}
\let\namerefOld\nameref
\renewcommand{\nameref}[1]{\textit{\namerefOld{#1}}}
\begin{document}
\section{A}
\label{sec:A}
bla bla foo bar
\section{B}
yada yada yada \nameref{sec:A}
\end{document}
What is the issue here? I would expect this to work, following the example in this question.
Using \nameref without the \let and \renewcommand in the preamble works fine, as well as simply surrounding it with \textit{...}, which yields the desired output. I don't want to surround every occurrence of \nameref with \textit, though.
\typeout{\meaning\nameref}before and after\begin{document}and look in the log (after you outcomment your two lines. As you'll notice\namerefis actually not defined in the preamble, it is delayed. Try wrapping your two lines in\AtBeginDocument{...}. BTW: I'd probably now overwrite the original macro like this, it just make\itnamerefand use that instead. – daleif Mar 16 '18 at 13:20\show\namerefinstead, since it also writes the name of the macro whose definition is shown and thus makes it easier to find in the log file. – schtandard Mar 16 '18 at 13:23\nameref, leading to inconsistency. – PixelMaster Mar 16 '18 at 13:31\show\namerefto the preamble will not compile, my version with two\typeout{\meaning...}does – daleif Mar 16 '18 at 14:18\showis a TeX primitive.. What is the error you are getting? (If you are not running LaTeX in nonstopmode (which most editors use), it will stop when it reaches a\show(which is good, because then you can just see the definition you are looking for in the command line without looking at the log file), but that is not an error. Simply pressing enter makes LaTeX continue and compile the document just fine.) – schtandard Mar 16 '18 at 15:13Argument of \nameref has an extra }. typeout{\show\nameref}andParagraph ended before \nameref was complete. \typeout{\show\nameref}– PixelMaster Mar 16 '18 at 15:30\show\nameref, not\typeout{\show\nameref}. (\show doesn't put anything into your document.) – schtandard Mar 16 '18 at 15:52\show\namerefto the preamble would produce an error. After all, it is the designated TeX primitive for printing the definition of a macro to the log file (unlike the rather akward workaround of combining\meaningwith\typeout). It should produce> \nameref=undefined.. – schtandard Mar 16 '18 at 15:57\showyou'll need two compilations and an out comment to to that generally (assuming everyone is running nonstopmode is bad, I don't for example) – daleif Mar 16 '18 at 16:17\showis that it tells you which macro it is showing and on which line you asked for that, which can be very helpful when you want to know the definitions of several macros. (Also,\showis shorter). But whatever, the OP's problem seems to be solved. – schtandard Mar 16 '18 at 16:42