Subject: bug#78296: Hand-written styles with `LaTeX-provided-package-options'

From: Ikumi Keita <[email-masked]>
Date: Fri, 09 May 2025 18:05:51 +0900

Hi Arash,

>>>>> Arash Esbati <[email-masked]> writes:
> --8<---------------cut here---------------start------------->8---
> \documentclass[11pt]{article}

> \usepackage{mypackage}

> \begin{document}
> foo
> \end{document}

> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: t
> %%% End:
> --8<---------------cut here---------------end--------------->8---

> loading mypackage.sty and you have also written an AUCTeX style file
> mypackage.el which looks like this:

> --8<---------------cut here---------------start------------->8---
> ;;;   -*- lexical-binding: t; -*-

> (TeX-add-style-hook
>  "mypackage"
>  (lambda ()
>    (TeX-add-to-alist 'LaTeX-provided-class-options
>                      '(("article" "11pt")))
>    (TeX-add-to-alist 'LaTeX-provided-package-options
>                      '(("babel" "english")
>                        ("booktabs" "")
>                        ("fontspec" "")
>                        ("geometry" "a4paper")
>                        ("graphicx" "")
>                        ("lastpage" "")
>                        ("microtype" "activate")
>                        ("parskip" "")
>                        ("siunitx" "")
>                        ("tabularx" "")
>                        ("titlesec" "pagestyles")
>                        ("xcolor" "svgnames")
>                        ("xspace" "")))
>    (TeX-run-style-hooks
>     "article"
>     "babel"
>     "booktabs"
>     "fontspec"
>     "geometry"
>     "graphicx"
>     "lastpage"
>     "microtype"
>     "parskip"
>     "siunitx"
>     "tabularx"
>     "titlesec"
>     "xcolor"
>     "xspace"))
>  TeX-dialect)
> --8<---------------cut here---------------end--------------->8---

> IIUC, the hand-written additions to `LaTeX-provided-package-options' and
> `LaTeX-provided-class-options' are never activated in the .tex file.

Hmm, indeed.

> The best solution I can currently offer is:

> --8<---------------cut here---------------start------------->8---
> diff --git a/latex.el b/latex.el
> index 3a32c4e7..8b35851a 100644
> --- a/latex.el
> +++ b/latex.el
> @@ -1943,6 +1943,8 @@ For example, its value will be
>     ...)
>  See also `LaTeX-provided-package-options'.")

> +(add-to-list 'TeX-normal-mode-reset-list 'LaTeX-provided-class-options)
> +
>  (defun LaTeX-provided-class-options-member (class option)
>    "Return non-nil if OPTION has been given to CLASS at load time.
>  The value is actually the tail of the list of options given to CLASS."
> @@ -1966,6 +1968,8 @@ For example, its value will be
>     ...)
>  See also `LaTeX-provided-class-options'.")

> +(add-to-list 'TeX-normal-mode-reset-list 'LaTeX-provided-package-options)
> +
>  (defun LaTeX-provided-package-options-member (package option)
>    "Return non-nil if OPTION has been given to PACKAGE at load time.
>  The value is actually the tail of the list of options given to PACKAGE."
> @@ -2140,8 +2144,8 @@ TYPE is one of the symbols mac or env."
>                                  LaTeX-auto-bibliography)))

>    ;; Reset class and packages options for the current buffer
> -  (setq LaTeX-provided-class-options nil)
> -  (setq LaTeX-provided-package-options nil)
> +  ;; (setq LaTeX-provided-class-options nil)
> +  ;; (setq LaTeX-provided-package-options nil)

>    ;; Cleanup document classes and packages
>    (unless (null LaTeX-auto-style)
> --8<---------------cut here---------------end--------------->8---

> I.e., adding the variables to `TeX-normal-mode-reset-list' and deleting
> the forms inside `LaTeX-auto-cleanup'.  Am I missing something?

I think that would be a reasonable solution. (Maybe we should tune
`LaTeX-auto-cleanup' to skip, for efficiency, additions to
`LaTeX-provided-package-options' and `LaTeX-provided-class-options' when
those variables already have non-nil bindings.)

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