1

I'm having trouble using \cref in emacs' AUCTeX + RefTeX mode. The pdf shows the reference to a picture as "section 1.3" instead of "Fig.1a" (see snapshot below) as it should, when \usepackage{cleveref} is loaded in the preamble of the main.tex file.

I've read these 2 discussions: link-1, link-2, and I have added the following lines to my .emacs file but can't notice any change in emacs' behaviour.

;;emacs RefTeX
(setq reftex-ref-macro-prompt nil) ;skips picking the reference style

;code taken from SX "Cleveref: AUCTeX and RefTeX set-up"
(eval-after-load
    "latex"
  '(TeX-add-style-hook
    "cleveref"
    (lambda ()
      (if (boundp 'reftex-ref-style-alist)
      (add-to-list
       'reftex-ref-style-alist
       '("Cleveref" "cleveref"
         (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
      (reftex-ref-style-activate "Cleveref")
      (TeX-add-symbols
       '("cref" TeX-arg-ref)
       '("Cref" TeX-arg-ref)
       '("cpageref" TeX-arg-ref)
       '("Cpageref" TeX-arg-ref)))))

Can someone help me out, please?

=MWE=

\documentclass[10pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[italian]{babel}
\usepackage{amsmath,amssymb} 
\usepackage{mathtools}
\usepackage{esdiff}
\usepackage[version=4]{mhchem}
\usepackage[a4paper]{geometry}
\usepackage{fullpage}
\usepackage{lipsum}

% FONT CHOICE
% Palatino for serif & math, Helvetica for ss, Courier for tt
\usepackage{mathpazo} % math & rm
\linespread{1.05}     % Palatino needs more leading (space between lines)
\usepackage[scaled]{helvet} % ss
\usepackage{courier} % tt
\normalfont

\usepackage{siunitx}
    \DeclareSIUnit\Molar{\textsc{m}}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\usepackage{cleveref}

\graphicspath{{./IMGS/}}

\title{sometitle}

\begin{document}
\begin{enumerate}
\item bla bla bla? [cfr. \cref{fig:rame}]
\end{enumerate}

\begin{figure}[ht]
  \centering
   \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[scale=.4]{a}   
     \label{fig:nacl} 
   \end{subfigure} \quad
   \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[scale=0.4]{b}
     \label{rame}
   \end{subfigure}
\label{fig:figure}
\caption{General caption}
 \end{figure}

\end{document}

=SNAPSHOT= in pdf, reference doesn't correspond to picture's capiton

  • Maybe you should tell which version of emacs and auctex, which OS you are using. I won't be able to help you anyway, but maybe these hints would help some experts. Did you go into the same troubles when you compile with latexmk from outside emacs? – sztruks Oct 31 '15 at 19:51
  • 2
    Your two subfigure environments appear to lack \caption statements. Also, for the overall ` figure`, the label should come after the caption. – Mico Oct 31 '15 at 19:57
8

The issues you're experiencing are not related to emacs, and they are only indirectly related to cleveref. You need to do the following:

  • In the main figure, interchange the order of \caption and \label: the \caption statement must come before the \label statement.

  • Provide \caption statements for each of the two subfigure environments. Be mindful of the fact that the \caption statements must come before the \label statements.

  • Fix the argument of the \label instruction in the second subfigure: It currently reads rame, whereas the argument of \cref is fig:rame. I suggest you change the \label statement to \label{fig:rame}.

Finally, if you need \cref to generate Fig. rather than fig., be sure to load the cleveref package with the option capitalize (capitalise works too).

  • Thanks for the capitalize hint! There's still a teeny-tiny problem I'm getting – when I press C-c ) I get \ref{} instead of \cref{}. Also, Emacs still asks for reference style . Is the elisp code above, not effective? – WobblyWindows Nov 1 '15 at 9:45
  • 1
    I'm afraid I'm not an Emacs expert. May I ask you to pose a new question that's specifically about (a) how to get C-c to generate \cref{} and (b) how to answer Emacs's query about reference styles? – Mico Nov 1 '15 at 9:54
  • 1
    @WobblyWindows I have just the thing if you'd like to post a question so it's not hidden in these comments =) – Sean Allred Nov 1 '15 at 14:27

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.