OK, I got the problem: when I define these tcolorbox environments in the document, all works after I do two things
1) C-c C-n 2) reftex-parse-all But when I put the definitions into a separate latex style file, neither reftex nor auctex knows about them and the above two steps won't help. I am attaching the following file tcbcolor_test.tex . This one works after I open it in Emacs and do 1) and 2) above. \documentclass{article} \usepackage[theorems]{tcolorbox} \usepackage{cleveref} \newtcbtheorem[ crefname={definition}{definitions} ] {defn}{Definition}{}{defn} %theorem \newtcbtheorem[ use counter from=defn, crefname={theorem}{theorems} ] {thm}{Theorem}{}{thm} %\usepackage{my} \begin{document} \begin{thm}[label={thm:1}]{Big One}{} $1=2$ \end{thm} \begin{defn}[label={defn:1}]{Bigdef}{} BIG. \end{defn} In \cref{defn:1,thm:1}. \end{document} But if I put the preamble into my.sty, so I have this tcbcolor_test1.tex \documentclass{article} \usepackage{my} \begin{document} \begin{thm}[label={thm:1}]{Big One}{} $1=2$ \end{thm} \begin{defn}[label={defn:1}]{Bigdef}{} BIG. \end{defn} In \cref{defn:1,thm:1}. \end{document} Then AUCTeX won't know about these thm and defn environments and reftex won't offer them when I do C-c ). On Fri, Sep 18, 2020 at 5:05 PM Wierdl Máté <wierdlm...@gmail.com> wrote: > Well, it all worked once. When I closed the latex file and later this > afternoon reopened it in Emacs, it didn't see the key-val labels and auctex > wouldn't enter my theoremlike environments with key-val labels. > > I'll make up a small working example and I'll send my .emacs file. > > Máté > > On Fri, Sep 18, 2020 at 10:56 AM Wierdl Máté <wierdlm...@gmail.com> wrote: > >> I think at stackexchange the file you gave was the same. The possible >> difference hence is the installation of the newer auctex? >> >> >> >> On Fri, Sep 18, 2020 at 10:48 AM Wierdl Máté <wierdlm...@gmail.com> >> wrote: >> >>> Arash, >>> >>> This is fantastic. I installed the new auctex via elpa and your style >>> file, and now when I enter a tcolorbox environment, I get the keyval labels >>> added automatically. I also see the references when I do C-c ). >>> >>> I'll report back if I see any bugs but I am happy! >>> >>> The answer you gave me a while back in stack exchange was only partially >>> working, but now this is all good. Maybe you want to update there? >>> >>> >>> https://tex.stackexchange.com/questions/463855/auctex-reftex-how-do-i-handle-labels-that-use-label-name-syntax-instead-of >>> >>> Thx, bro, >>> >>> Máté >>> >>> On Fri, Sep 18, 2020 at 5:17 AM Arash Esbati <ar...@gnu.org> wrote: >>> >>>> Hi Máté, >>>> >>>> Wierdl Máté <wierdlm...@gmail.com> writes: >>>> >>>> > I am using the tcolorbox latex package which doesn't use the usual >>>> '\label' >>>> > command. Instead, one has to specify a label in key-val form as in >>>> > >>>> > \begin{thm}[label={thm:1}]{}{} >>>> > $1=2/2$ >>>> > \end{thm} >>>> > >>>> > Is there a way to have reftex/auctex work with this variation? >>>> >>>> AUCTeX/RefTeX were designed for vanilla LaTeX. Additional packages are >>>> supported via style files (within AUCTeX) and customization in RefTeX. >>>> key-val labels are possible, but with some limitations (see below). >>>> >>>> > What I mean is this >>>> > >>>> > 1) reftex keeps track of these as labels and when I want to >>>> reference this >>>> > theorem, 'C-c )' will show this to me. >>>> >>>> You can add your environment to `reftex-label-regexps' in order to tell >>>> RefTeX about `thm'. But the regexp is somewhat complicated. >>>> >>>> > (Until today, this was working fine, but now reftex doesn't recognize >>>> > this form of a label. I have no idea what happened, what's changed. ) >>>> >>>> Which version of Emacs are you using? Have you updated to 27.1? >>>> RefTeX's handling of key-val labels was changed there. >>>> >>>> > 2) auctex/reftex enters a label in this key-val form when I do 'C-c >>>> ('. >>>> >>>> You can teach AUCTeX to insert a key-val label when you insert the >>>> environment with `C-c C-e ENV RET'; hitting `C-c (' in an environment >>>> doesn't work. >>>> >>>> > 3) the "renumber simple labels" function works with such references. >>>> >>>> This is indeed a missing feature in RefTeX. I never really looked how >>>> RefTeX does this, hence I can't help. >>>> >>>> Long time ago, I started writing a support file for tcolorbox's theorems >>>> library. That unfinished work is attached. Set the variable >>>> `TeX-style-private' to a directory of your choice, e.g.: >>>> >>>> (setq TeX-style-private >>>> (expand-file-name "~/.emacs.d/auctex-style")) >>>> >>>> save the file there and open your .tex file. Also hit `C-c C-n' to >>>> parse your document. Maybe you can report back if it works. >>>> >>>> Best, Arash >>>> >>>
\documentclass{article} \usepackage[theorems]{tcolorbox} \usepackage{cleveref} \newtcbtheorem[ crefname={definition}{definitions} ] {defn}{Definition}{}{defn} %theorem \newtcbtheorem[ use counter from=defn, crefname={theorem}{theorems} ] {thm}{Theorem}{}{thm} %\usepackage{my} \begin{document} \begin{thm}[label={thm:1}]{Big One}{} $1=2$ \end{thm} \begin{defn}[label={defn:1}]{Bigdef}{} BIG. \end{defn} In \cref{defn:1,thm:1}. \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
\documentclass{article} \usepackage{my} \begin{document} \begin{thm}[label={thm:1}]{Big One}{} $1=2$ \end{thm} \begin{defn}[label={defn:1}]{Bigdef}{} BIG. \end{defn} In \cref{defn:1,thm:1}. \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
\usepackage[theorems]{tcolorbox} \usepackage{cleveref} \newtcbtheorem[ crefname={definition}{definitions} ] {defn}{Definition}{}{defn} %theorem \newtcbtheorem[ use counter from=defn, crefname={theorem}{theorems} ] {thm}{Theorem}{}{thm}
(TeX-add-style-hook "tcbcolor_test" (lambda () (TeX-add-to-alist 'LaTeX-provided-package-options '(("tcolorbox" "theorems"))) (TeX-run-style-hooks "latex2e" "article" "art10" "tcolorbox" "cleveref") (LaTeX-add-tcolorbox-lib-theorems-newtcbtheorems '("defn" "defn") '("thm" "thm"))) :latex)
(TeX-add-style-hook "tcbcolor_test1" (lambda () (TeX-run-style-hooks "latex2e" "article" "art10" "my")) :latex)
(TeX-add-style-hook "my" (lambda () (TeX-add-to-alist 'LaTeX-provided-package-options '(("tcolorbox" "theorems"))) (TeX-run-style-hooks "tcolorbox" "cleveref")) :latex)