Subject: bug#24070: LaTeX mode doesn't load in 11.89.4

From: Stefan Monnier <[email-masked]>
Date: Tue, 26 Jul 2016 13:44:27 -0400

> Still, this workaround seem a little odd to me.  First, It seems odd that I
> can't start AUCTeX "when I want", i.e., by using the line (load "auctex.el"
> nil t t), even though this worked for me in previous versions of auctex
> (11.89 and 11.88).

Packaging in ELPA aims to follow the way packages bundled with Emacs are
handled, such that they're not "started" automatically, but they are
automatically setup so that you can "start" them by just invoking their
functionality (e.g. loading a .tex file).

> Second, it also seems a little odd that I can't do something like
> (require 'auctex) or (use-package auctex), even though I can load all
> my other 30+ packages that way.  The concept of having nothing in my
> .emacs and the package still being expected to work definitely
> confused me at the beginning.

The only standard/supported way to setup an ELPA package in general is
to load its <pkg>-autoloads.el file (that's what package-initialize does
usually).  In practice, from what you say, loading <pkg>.el tends to
work as well, but that's mostly an accident.

This said, AUCTeX has historically been enabled by (load "tex-site") or
(load "auctex"), so it would make sense for AUCTeX's package to support
this.  I thought it worked, but your bug-report shows that it doesn't.

The (untested) patch/hack below might help cases like yours.
I'm not sure if AUCTeX's maintainers want to go that route or would
prefer to just detect the case and emit a warning instead to try and
help people follow the standard installation method.

        Stefan

diff --git a/tex-site.el b/tex-site.el
index 44edc54..e59ebc7 100644
--- a/tex-site.el
+++ b/tex-site.el
@@ -1,6 +1,6 @@
 ;;; tex-site.el - Site specific variables.  Don't edit.
 
-;; Copyright (C) 2005, 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2005, 2013, 2016 Free Software Foundation, Inc.
 ;;
 ;; completely rewritten.
 
@@ -39,7 +39,14 @@
 ;;; Code:
 
 (if (< emacs-major-version 21)
-  (error "AUCTeX requires Emacs 21 or later"))
+  (error "AUCTeX requires Emacs 21 or later")) ;FIXME: Really?
+
+(unless (or (fboundp 'TeX-modes-set)     ;Avoid inf-looping.
+            (fboundp 'TeX-tex-mode))     ;auctex-autoloads is not loaded.
+  ;; Try and support the case where someone loads tex-site.el or
+  ;; auctex.el directly, in the old way.
+  (provide 'tex-site)        ;Avoid (re)loading tex-site from auctex-autoloads.
+  (load "auctex-autoloads" 'noerror 'nomessage))
 
 ;; Define here in order for `M-x customize-group <RET> AUCTeX <RET>'
 ;; to work if the main AUCTeX files are not loaded yet.