Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install auctex #379

Closed
PeterSterner opened this issue Sep 5, 2016 · 22 comments
Closed

Install auctex #379

PeterSterner opened this issue Sep 5, 2016 · 22 comments

Comments

@PeterSterner
Copy link

Hi

I'm converting my init.el to use use-package. It's great :-).

I'm trying to install auctex via use-package (I use Ubuntu and I have removed the auctex ubuntu package).

I can get auctex to work with the following snippet:

(use-package tex-site
:ensure auctex
:defer t
:mode (".tex'" . latex-mode)
:commands (latex-mode LaTeX-mode plain-tex-mode)
:config
(progn
(add-to-list 'load-path "~/.emacs.d/elpa/auctex-11.89.5")
(load "auctex.el" nil t t)
(load "preview.el" nil t t)
)
)

But is there a smarter way? Any help appreciated. Thanks in advance.

@npostavs
Copy link
Contributor

npostavs commented Sep 5, 2016

I think most of that is redundant. Maybe you want something like:

(use-package auctex
  :defer t
  :ensure t)

@PeterSterner
Copy link
Author

Thanks for your help @npostavs.

It works perfectly.

@fice-t
Copy link
Contributor

fice-t commented Sep 11, 2016

@npostavs This doesn't actually work with :defer as auctex.el isn't automatically loaded. To test, try this:

(use-package auctex
  :defer t
  :ensure t
  :config
  (setq TeX-auto-save t))

and open a LaTeX file. Notice how TeX-auto-save is still nil -- the config isn't actually loaded.

I personally use something like the following, which does work with :defer:

(use-package tex
  :defer t
  :ensure auctex
  :config
  (setq TeX-auto-save t))

Note that using tex-site as in use-package's readme doesn't work with :defer as well; it gets loaded immediately instead. Perhaps the readme should be changed.

@npostavs
Copy link
Contributor

Oh, I see, there is no file in the auctex package that provides the auctex feature (it looks there is an auctex.el which calls tex-site).

I personally use something like the following, which does work with :defer:

Makes sense (though such a setq could go in :init anyway, I assume that's just a placeholder expression).

Note that using tex-site as in use-package's readme doesn't work with :defer as well; it gets loaded immediately instead. Perhaps the readme should be changed.

tex-site also doesn't provide a tex-site feature, so possibly you would want (use-package "tex-site"...) instead. Though tex-site.el seems intended to be loaded immediately anyway (it doesn't load the entire auctex package), so you probably don't want to defer it.

@fice-t
Copy link
Contributor

fice-t commented Sep 11, 2016

(I assume that's just a placeholder expression).

Right.

tex-site also doesn't provide a tex-site feature

It does for me with the latest ELPA version. Looks like the git repo has a Makefile that creates that line for whatever reason.

Though tex-site.el seems intended to be loaded immediately anyway (it doesn't load the entire auctex package), so you probably don't want to defer it.

Yeah, I figured that using tex is a better default since it (should) work in all cases. The proper AUCTeX major modes are loaded via override advice for modes defined in the built-in tex-mode.el, and then are either defined in AUCTeX's tex.el, or require that file.

Though perhaps using tex-mode directly would be better?
Scratch that, it could load prematurely.

@npostavs
Copy link
Contributor

It does for me with the latest ELPA version. Looks like the git repo has a Makefile that creates that line for whatever reason.

Oh, yeah, I see it in the ELPA repo (I was looking at the 11.89 tarball before), and also an autoload cookie which explains why it's always loaded immediately:

;;; Ensure that loading the autoloads file also loads this file.
;;;###autoload (require 'tex-site)

(provide 'tex-site)
;;; tex-site.el ends here

@PeterSterner
Copy link
Author

So what is the conclusion :-)?

I can't get this to work:

(use-package tex
  :defer t
  :ensure auctex
  :config
  (setq TeX-auto-save t))

I can only get auctex to work via tex-site.

@fice-t
Copy link
Contributor

fice-t commented Sep 11, 2016

@petey33 What in particular doesn't work with that snippet? Does an AUCTeX major mode not start up for you when loading a .tex file?

What's supposed to happen is that the :config forms are not evaluated until after you load a TeX file.

@PeterSterner
Copy link
Author

@fice-t Yes. AUCTeX major mode do not start up when loading af tex file. I get:

File mode specification error: (error "Autoloading failed to define function TeX-latex-mode")

@fice-t
Copy link
Contributor

fice-t commented Sep 12, 2016

That error occurs when you try to autoload a function with the wrong file. Can you first do M-x toggle-debug-on-error, open a .tex file, and then post the backtrace?

Also, can you reproduce this error using emacs -Q with that snippet?

@PeterSterner
Copy link
Author

PeterSterner commented Sep 13, 2016

Thank you @fice-t .

I can't reproduce the error with emacs -Q.

The backtrace:

Debugger entered--Lisp error: (error "Autoloading failed to define function TeX-latex-mode")
TeX-latex-mode()
apply(TeX-latex-mode nil)
latex-mode()
TeX-tex-mode()
apply(TeX-tex-mode nil)
tex-mode()
set-auto-mode-0(tex-mode nil)
set-auto-mode()
normal-mode(t)
after-find-file(nil t)

@fice-t
Copy link
Contributor

fice-t commented Sep 13, 2016

I can't reproduce the error with emacs -Q.

Okay, so that means the problem lies elsewhere. Your backtrace looks normal, so it might be an issue with your load-path.

With your config, what's the output of M-x locate-library with the input latex? It should be ~/.emacs.d/elpa/auctex-11.89.5/latex.elc.

In any case, that file is supposed to have the definition of TeX-latex-mode. If it doesn't, then that's what's causing the error.

@PeterSterner
Copy link
Author

Thank you so much @fice-t!

It was my load-path. I had some other code where I messed with load-path. Now your snippet works perfectly.

@soupault
Copy link

soupault commented Nov 3, 2016

Neither use-package tex nor use-package auctex worked for me.
Has made it working using the following configuration:

(use-package tex-mode
  :ensure auctex)

emacs 25.1, auctex-11.89.6, use-package-2.2

@jwiegley
Copy link
Owner

jwiegley commented Nov 3, 2016

FWIW, here's what I use, and I work with LaTeX frequently:

(use-package tex-site                   ; auctex
  :load-path "site-lisp/auctex/"
  :defines (latex-help-cmd-alist latex-help-file)
  :mode ("\\.tex\\'" . TeX-latex-mode)
  :init
  (setq reftex-plug-into-AUCTeX t)
  (setenv "PATH" (concat "/Library/TeX/texbin:"
                         (getenv "PATH")))
  (add-to-list 'exec-path "/Library/TeX/texbin")
  :config
  (defun latex-help-get-cmd-alist ()    ;corrected version:
    "Scoop up the commands in the index of the latex info manual.
   The values are saved in `latex-help-cmd-alist' for speed."
    ;; mm, does it contain any cached entries
    (if (not (assoc "\\begin" latex-help-cmd-alist))
        (save-window-excursion
          (setq latex-help-cmd-alist nil)
          (Info-goto-node (concat latex-help-file "Command Index"))
          (goto-char (point-max))
          (while (re-search-backward "^\\* \\(.+\\): *\\(.+\\)\\." nil t)
            (let ((key (buffer-substring (match-beginning 1) (match-end 1)))
                  (value (buffer-substring (match-beginning 2)
                                           (match-end 2))))
              (add-to-list 'latex-help-cmd-alist (cons key value))))))
    latex-help-cmd-alist)

  (use-package ebib
    :load-path "site-lisp/ebib"
    :preface
    (use-package parsebib :load-path "site-lisp/parsebib"))

  (use-package latex
    :defer t
    :config
    (use-package preview)
    (add-hook 'LaTeX-mode-hook 'reftex-mode)
    (info-lookup-add-help :mode 'LaTeX-mode
                          :regexp ".*"
                          :parse-rule "\\\\?[a-zA-Z]+\\|\\\\[^a-zA-Z]"
                          :doc-spec '(("(latex2e)Concept Index" )
                                      ("(latex2e)Command Index")))))

@fice-t
Copy link
Contributor

fice-t commented Nov 4, 2016

@soupault What exactly is not working with use-package tex? I use the same Emacs/AUCTeX/use-package versions and it works for me.

@jwiegley Thanks for sharing. I believe tex-site is right in your case since you use the git version of AUCTeX, which doesn't include this line:

;;;###autoload (require 'tex-site)

ELPA users shouldn't use tex-site since the file gets required during package initialization.

@soupault
Copy link

soupault commented Nov 4, 2016

@fice-t I get

File mode specification error: (error Autoloading failed to define function tex)

, and tex-mode doesn't start automatically on opening .tex-files.

@fice-t
Copy link
Contributor

fice-t commented Nov 4, 2016

@soupault I checked out your emacs config and found this in your use-package form:

:mode "\\.tex\\'"

That will not for tex as it then tries to call the function tex, which does not exist.

In any case, I suggest removing that line as it's redundant: auto-mode-alist already includes an entry to open .tex files in tex-mode.

@soupault
Copy link

soupault commented Nov 4, 2016

@fice-t thanks for looking into it!
I understand that things might be redundant somewhere, but I really like to keep them explicit :).
Apparently, the usage of :mode was not strictly correct, the updated version works well even with use-package auctex.

@fice-t
Copy link
Contributor

fice-t commented Nov 4, 2016

No problem. Though I'd recommend tex over auctex as auctex doesn't automatically work with :defer.

@c-alpha
Copy link

c-alpha commented Mar 25, 2021

This worked for me (emacs 27.1, auctex 13.0.5):

(use-package latex
  :ensure auctex
  ;; your stuff here
)

Hope this helps...

@hongyi-zhao
Copy link

hongyi-zhao commented Sep 25, 2021

I use straight with its use-package integration. The auctex installation and configuration code used by me is given here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants