Hi all,

This is a continuation of a topic in last June :-)

>>>>> Ikumi Keita <ik...@ikumi.que.jp> writes:
> I think that AUCTeX built-in bibliography management has fundamental
> flaw.

[...]

> The problem is, that the contents of "auto/jr.el" is not used at all
> afterwards.

[...]

> This means that the `LaTeX-add-bibitems' call added as "jr" style hook
> with ":bibtex" dialect hasn't been called. You can confirm it by
> evaluating `(LaTeX-bibitem-list)', which returns nil.

> The LaTeX mode does load "auto/jr.el". However, it doesn't run the
> associated style hook because the hook is registred as ":bibtex"
> dialect, not ":latex".

> Even when you open "jr.bib", the hook isn't run because bibtex-mode
> doesn't run AUCTeX style hooks.

> In these ways, AUCTeX never runs style hooks with ":bibtex" dialect.

> This defect didn't cause major problem. I think practically all AUCTeX
> users who need bibtex facility use RefTeX (or bib-cite.el?) so defect in
> AUCTeX built-in bibliography management has been overlooked so far.

I came up to a tentative fix as the attached patch. Comments and
suggestions are welcome.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

>From cc5c549131db75a3b1bbbc9fa587f1f6df0a70f8 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <ik...@ikumi.que.jp>
Date: Wed, 10 Nov 2021 01:03:42 +0900
Subject: [PATCH] Fix bibtex dialect

* tex.el (TeX-auto-store): Use `(or :bibtex :latex)' instead of
`:bibtex' as dialect argument for `TeX-add-style-hook' when saving auto
file for BibTeX file.
---
 tex.el | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tex.el b/tex.el
index 9188ccd7..6b80b4e8 100644
--- a/tex.el
+++ b/tex.el
@@ -4101,7 +4101,8 @@ If TEX is a directory, generate style files for all files in the directory."
                                   LaTeX-verbatim-macros-with-delims-local))
             (verb-macros-braces (when (boundp 'LaTeX-verbatim-macros-with-braces-local)
                                   LaTeX-verbatim-macros-with-braces-local))
-            (dialect TeX-style-hook-dialect))
+            (dialect TeX-style-hook-dialect)
+            (bibtex-p (eq major-mode 'bibtex-mode)))
         (TeX-unload-style style)
         (with-current-buffer (generate-new-buffer file)
           (erase-buffer)
@@ -4131,7 +4132,21 @@ If TEX is a directory, generate style files for all files in the directory."
           (mapc (lambda (el) (TeX-auto-insert el style))
                 TeX-auto-parser)
           (insert ")")
-          (if dialect (insert (concat "\n " (prin1-to-string dialect))))
+          (if dialect (insert (concat
+                               "\n "
+                               (prin1-to-string
+                                (if bibtex-p
+                                    ;; Add :latex since functions such
+                                    ;; as `LaTeX-add-bibitems' are
+                                    ;; only meaningful in LaTeX
+                                    ;; document buffer.
+                                    ;; FIXME: BibTeX is available to
+                                    ;; plain TeX through eplain
+                                    ;; (<URL:https://tug.org/eplain/doc/eplain.html#Citations>).
+                                    ;; It would be nice if AUCTeX
+                                    ;; supports such usage.
+                                    `'(or ,dialect :latex)
+                                  dialect)))))
           (insert ")\n\n")
           (write-region (point-min) (point-max) file nil 'silent)
           (kill-buffer (current-buffer))))
-- 
2.35.1

Reply via email to