While \cref works quite well for me, it doesn't seem to recognise section labels when used in emulateapj.cls framework. Here's an example:



\title{Towards Unifying Time Domain Astronomy}
\shorttitle{Towards Unifying Time Domain Astronomy}

\author{G.\ B\'elanger}
\affil{European Space Astronomy Centre (ESA/ESAC), Science Operations Department, \\
Villanueva de la Ca\~nada (Madrid), Spain; \\

Time domain astronomy concerns itself with the study of astrophysical systems 
by characterising the properties of the light they emit in order to deduce and 
infer something about the physical mechanisms that could be responsible for 
giving rise to this emission.
\keywords{methods: data analysis -- methods: statistical}


The task is divided in three the categories mentioned earlier, which relate to
the characterisation of constance, which also includes searching for new or 
transient sources (\cref{s:constancy}); periodicity at any scale and whatever 
the nature (\cref{s:periodicity}); and stochastic variability, including the 
tracing and detection of state changes (Section \ref{s:variability}).

\section{Characterising Constancy}

\section{Characterising Periodicity}

\section{Characterising Stochastic Variability}


The output looks like this: enter image description here

Tom from the TeXBlog suggested

\newcommand\sref[1]{Section \ref{#1}}

which works. It would be nice to find the cause of the problem and fix it for everyone in cleveref or emulateapj, but this is far beyond my level of competence as just a user and not a latex dev.

  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – jub0bs Apr 16 '14 at 10:08
  • I believe that the problem is in that emulateapj loads revtex4 (or revtex4-1, but then defines sectional commands in a different way, and probably this confuses cleveref. – egreg Apr 16 '14 at 17:46
  • Thank you. Any suggestions for a fix? – Guillaume Belanger Apr 21 '14 at 14:34

After spending half a day digging through the sources, I think I may have discovered the cause of this problem.

All LaTeX \section commands contain the macro \refstepcounter, which is responsible for updating section counters. It is redefined by cleveref to store additional information about the current section in \cref@currentlabel. This information is later written out by a redefined \label command to the .aux file. If we now look at the redefinition of \@sect (renamed to \H@old@sect by hyperref) in emulateapj.cls, we find that \refstepcounter is now enclosed between a pair of \begingroup and \endgroup, so all changes to \cref@currentlabel are lost upon exiting the group. A kludge is to make the assignment inside the group global.

We illustrate by the following example:


% patch


If we were to typeset the document without the patch, we would find the following lines in the .aux file:


This is the section information written out by \label; clearly something is missing between the empty braces in the second and fourth lines. With the patch in place, we get instead:


The information is now present, and section references work as well.

  • Thank you so much for taking the time to look into this and identify the problem. If we were to correct this issue at the source, should the patch be added to emulateapj.cls, cleveref.sty or hyperref.sty? Just wanted to know if I should try to contact the respective authors to share the solution you have found and fix the problem for everyone. – Guillaume Belanger Apr 22 '15 at 7:26
  • 1
    For the time being, I'd suggest adding the patch to the document itself. But as luck would have it, a friend asked me a similar question. It's hard to say which package is to 'blame' for this. But if you look into the source of emulateapj, you'll see that it has to manually set \@currentlabel after the group, so it seems a reasonable place to set \cref@currentlabel as well, but I don't want to dig into cleveref to figure out how it sets \cref@currentlabel in the first place, and I'm not sure there's much overlap between users of emulateapj and cleveref. – photon.engine Apr 22 '15 at 16:01
  • Thank you. I sent a note to Alexey about this to see if he will add a little fix to emulateapj. – Guillaume Belanger Apr 23 '15 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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