TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First off, I'm very grateful of the help this community has provided me so far. Anyway, to my problem:

I feel like I'm missing something obvious here. I want...



\section{Section Title} \label{anchor}
Blah Blah Blah. \ref{anchor}

to print as...

1 Section Title

Blah Blah Blah. section 1

but instead I get ...

1 Section Title

Blah Blah Blah. 1

... so \ref is not being replaced with \autoref. How can I correct this? Do I have no option but to do a find-and-replace to change \ref to \autoref?

share|improve this question
Hmmm... Interesting.... I tried everything I know from \renewcommand, \def, \let, and \LetLtxMacro, but was not able to get \ref to produce the same output as \autoref. – Peter Grill Dec 2 '12 at 5:56
I suggest you not to try this; \ref and \autoref are semantically different and using one or the other changes how the text is laid out. – egreg Dec 2 '12 at 10:43
up vote 14 down vote accepted

Ok, figured out a solution:

enter image description here


  • None of the usual tricks of using:

    1. \renewcommand{\ref}[1]{\autoref{#1}}
    2. \def\ref#1{\autoref{#1}}
    3. \let\ref\autoref
    4. \LetLtxMacro\ref\autoref

    seem to work in this case.

    I suspect it is because hyperref does an \AtBeginDocument, so that some things get defined at the the start of the document. So using \AtBeginDocument puts our redefinition at the end of queue of commands that get executed \AtBeginDocument.

    And since placing the \AtBeginDocument to be before \usepackage{hyperref} does not work, this confirms that the suspicion was correct.





\section{Section Title} \label{anchor}
Blah Blah Blah.  \autoref{anchor}  \ref{anchor}
share|improve this answer
Or simply put the command after \begin{document} – Harish Kumar Dec 2 '12 at 6:02
@HarishKumar: But then that would be required in each document. Putting in the preamble is better in my opinion. – Peter Grill Dec 2 '12 at 6:06
@PeterGrill: \ref is defined \Hy@AtBeginDocument - similar to \AtBeginDocument. – Werner Dec 2 '12 at 6:22

Your Answer


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.