Hi all,
Please consider the following LaTeX code in a buffer where RefTeX is
enabled:
--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[
caption = Some caption ,
label = lst:1 %
]
foo
\end{lstlisting}
\begin{lstlisting}[
caption = {[Short caption]Long caption},
label = lst:2
]
bar
\end{lstlisting}
\begin{lstlisting}[
language = {[LaTeX]TeX} ,
frame = single ,
caption = {[Short caption]\textit{L\textbf{o}ng} caption} ,
label = lst:3 ]
foobar
\end{lstlisting}
\end{document}
--8<---------------cut here---------------end--------------->8---
When hitting `C-u C-c )' in order to add a \ref, RefTeX fails to see the
last 2 labels. For the first one, it inserts
\ref{lst:1 %
}
The is due to the second regexp in `reftex-label-regexps'. Please find
attached a patch fixing this issue. Any comments welcome.
Best, Arash
>From f6e3a84824f5597ab4f1641edf957b8af4b51564 Mon Sep 17 00:00:00 2001
From: Arash Esbati <[email protected]>
Date: Sat, 23 Feb 2019 14:02:05 +0100
Subject: [PATCH] Improve matching of key-val labels
* lisp/textmodes/reftex-vars.el (reftex-label-regexps): Improve
regexp for key-val labels in order to skip over content in braces.
---
lisp/textmodes/reftex-vars.el | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el
index 9147de6e01..eb1dfc50a3 100644
--- a/lisp/textmodes/reftex-vars.el
+++ b/lisp/textmodes/reftex-vars.el
@@ -891,11 +891,29 @@ reftex-derive-label-parameters
;; so this list mustn't get any more items.
(defconst reftex-label-regexps '("\\\\label{\\([^}]*\\)}"))
(defcustom reftex-label-regexps
- '(;; Normal \\label{foo} labels
+ `(;; Normal \\label{foo} labels
"\\\\label{\\(?1:[^}]*\\)}"
;; keyvals [..., label = {foo}, ...] forms used by ctable,
;; listings, minted, ...
- "\\[[^][]\\{0,2000\\}\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
+ ,(concat
+ ;; Make sure we search only for optional arguments of
+ ;; environments and don't match any other [
+ "\\\\begin[[:space:]]*{\\(?:[^}]+\\)}[[:space:]]*"
+ ;; Match the opening [ and the following chars
+ "\\[[^][]*"
+ ;; Allow nested levels of chars enclosed in braces
+ "\\(?:{[^}{]*"
+ "\\(?:{[^}{]*"
+ "\\(?:{[^}{]*}[^}{]*\\)*"
+ "}[^}{]*\\)*"
+ "}[^][]*\\)*"
+ ;; Match the label key
+ "\\<label[[:space:]]*=[[:space:]]*"
+ ;; Match the label value; braces around the value are
+ ;; optional.
+ "{?\\(?1:[^] ,}\r\n\t%]+\\)}?"
+ ;; We are done. Such search until the next closing bracket
+ "[^]]*\\]"))
"List of regexps matching \\label definitions.
The default value matches usual \\label{...} definitions and
keyval style [..., label = {...}, ...] label definitions. It is
@@ -905,7 +923,7 @@ reftex-derive-label-parameters
When changed from Lisp, make sure to call
`reftex-compile-variables' afterwards to make the change
effective."
- :version "25.1"
+ :version "27.1"
:set (lambda (symbol value)
(set symbol value)
(when (fboundp 'reftex-compile-variables)
--
2.20.1
_______________________________________________
auctex-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex-devel