Question

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.

Was it helpful?

Solution

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\\*?[[{]")))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top