Subject: bug#76615: 14.0.9; error with amsmath style hooks

From: Ikumi Keita <[email-masked]>
Date: Sat, 01 Mar 2025 00:57:06 +0900

Hi Paul and Arash,

>>>>> Arash Esbati <[email-masked]> writes:
> "Paul D. Nelson" <[email-masked]> writes:

>> Evaluating the following after Emacs -Q
>> 
>> (progn
>> (package-initialize)
>> (package-activate 'auctex)
>> (add-hook 'LaTeX-mode-hook #'turn-on-reftex)
>> (with-temp-buffer
>> (LaTeX-mode)
>> (TeX-run-style-hooks "amsmath")))
>> 
>> gives the backtrace:
>> 
>> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>> expand-file-name(nil)
>> reftex-TeX-master-file()
>> reftex-tie-multifile-symbols()
>> reftex-add-to-label-alist((AMSTeX))

> I think this is because of this part of amsmath.el[1]:

>    ;; RefTeX support: Tell RefTeX about amsmath environments.
>    (when (fboundp 'reftex-add-to-label-alist)
>      (reftex-add-to-label-alist '(AMSTeX)))

I tried commenting out this part, but it still fails at another part im
amsmath.el:
   (and LaTeX-reftex-ref-style-auto-activate
        (fboundp 'reftex-ref-style-activate)
        (reftex-ref-style-activate "AMSmath"))

>> The issue arose when using log-edit-generate-changelog-from-diff for a
>> commit involving tex files.  I distilled it down to the above example.

> I'd say the form above was in amsmath.el since forever :-)

The fundamental origin of the problem is that RefTeX presumes that it
always works in the buffer associated with files. In other words, RefTeX
pays no attention to non-file buffer. (I have such impression, skimming
over the RefTeX code. Please correct me if I'm wrong.)

>>>>> "Paul D. Nelson" <[email-masked]> writes:
> The attached patch addresses the issue for me.  Thoughts?

I have basically the same idea, but I think such partial treatment
inctroduces inconsistent internal state of RefTeX and can be potential
problems. Rather I propose to wrap the whole RefTeX management
part in amsmath.el by (when buffer-file-name ... ). In addition, we
should turn off RefTeX mode in `TeX-mode-cleanup' like
  (unless buffer-file-truename
    (if (bound-and-true-p reftex-mode) <-- addition
      (reftex-mode -1))                <-- addition
    (TeX-update-style))
to avoid inconsistency.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW