1

With RefTeX C-c C-) invokes reftex-citation which first asks for type of label one wants to reference then asks one to select a reference from a list. The list is a list of labels in a document. For LaTeX figures the list includes the caption of each figure (the arguments of \caption). Whenever a document contains subcaptions done with \subcaption they are not recognized and therefore not included in the list. Can RefTeX be made to recognize them such that they are put next to their respective labels in the list?

I guess a solution is to modify the variable reftex-label-alist by letting a regexp find \subcaption.

Here follows an example to make the problem clearer. Say that you have the following LaTeX document:

\documentclass{article}

\usepackage{subcaption}

\begin{document}

\begin{figure}
  \begin{minipage}{.5\linewidth}
    \subcaption{A subfigure}\label{fig:1a}
  \end{minipage}
  \caption{A figure}\label{fig:1}
\end{figure}

\end{document}

If you do C-c C-) you will see something like the following:

*RefTeX Select* of reftex-citation: No match for content regexp

Notice that the main figure's caption is shown but not the subfigure's caption.

N.N.
  • 8,336
  • 12
  • 54
  • 94

1 Answers1

1

You can customize reftex-default-context-regexps and change the regular expression of the caption entry from \\\(rot\)?caption\*?[[{] to \\\(rot\|sub\)?caption\*?[[{].

I think you might have to restart emacs, or run (reftex-set-dirty 'reftex-default-context-regexps reftex-default-context-regexps), or something, so that AUCTeX will update the proper variables. It's supposed to do that automatically, but I've had some problems with it.

If you dislike Customize you can set it with the following code:

(eval-after-load "reftex-vars"
  '(progn (setcdr (assoc 'caption reftex-default-context-regexps)
                  "\\\\\\(rot\\|sub\\)?caption\\*?[[{]")))
apaderno
  • 28,547
  • 16
  • 75
  • 90
Ivan Andrus
  • 5,221
  • 24
  • 31
  • That works. Is it possible to set this without using customize-variable? It makes my .emacs so ugly! – N.N. Feb 13 '12 at 20:19
  • I tried `(eval-after-load "reftex-vars" (setcdr (assoc "caption" reftex-default-context-regexps) "\\\\\\(rot\\|sub\\)?caption\\*?[[{]"))` which is similar to the technique used in http://stackoverflow.com/a/9116029/789593 but it throws an error. – N.N. Feb 13 '12 at 20:35
  • It's not `"caption"` (a string), it's `'caption` a quoted symbol. – Ivan Andrus Feb 13 '12 at 21:44
  • Thank you. Adding `(eval-after-load "reftex-vars" '(progn (setcdr (assoc 'caption reftex-default-context-regexps) "\\\\\\(rot\\|sub\\)?caption\\*?[[{]")))` to my .emacs worked. Maybe adding it to the customize-variable answer in your answer might make sense. – N.N. Feb 14 '12 at 06:42