3

I have written my own beamer-derived .cls file to avoid copying and pasting my usual preamble. A MWE would be

\NeedsTeXFormat{LaTeX2e}[1995/12/01]%
\ProvidesClass{own_beamer}[2018/06/19 my own slides 2018]
\LoadClass{beamer}
\RequirePackage{booktabs}
\RequirePackage{graphicx}

It works well. I use Emacs for my LaTeX writing and like all the hints it can provide. For instance, when I create a new frame in a beamer class document, Emacs asks for the frame title. In the same manner, when I want to include a picture, Emacs asks me for the picture file (and eventually the options I want to add).

The thing is that when I use my own-beamer document class, I don't get any of these hints. I think it's because AucTeX does not recognize it's derived from beamer. When I use the C-c C-n Emacs command, it does not help.

Any help to fix this?

  • 2
    you could certainly do this but a simpler way might be to use beamer class and then put the requirepackage and other customisations in a custom beamer theme file, so that auctex sees it as beamer – David Carlisle Jun 20 '18 at 20:25
  • 2
    You don't need \RequirePackage{graphicx} if you load beamer – user36296 Jun 20 '18 at 20:48
4

Using M-x TeX-auto-generate in the simplest way

The simplest way is, I think:

  1. Inside Emacs, in a buffer using AUCTeX, do C-h v TeX-auto-private and create the directory corresponding to the variable's value (typically, /home/myusername/.emacs.d/auctex/auto).
  2. Run M-x TeX-auto-generate. At the first prompt, give a directory containing your personal class and style files you would like AUCTeX to know about. For instance, if your own_beamer.cls lives in /home/myusername/texmf/tex/latex/MyName, then you could give this directory, but choosing /home/myusername/texmf/tex would also work because the search is recursive (of course, it would probably find more files). At the second prompt, accept the default (typically, ~/.emacs.d/auctex/auto).

    This is going to create /home/myusername/.emacs.d/auctex/auto/own_beamer.el, and similar .el files for your other personal .sty, .cls, etc. files found under the directory you indicated at the first prompt.

  3. Visit an AUCTeX-using buffer having \documentclass{own_beamer} and type C-c C-n inside that buffer (or just restart Emacs).

Keeping a handcrafted AUCTeX helper in TeX-style-private

A variation on the previous method consists in copying the aforementioned own_beamer.el file to /home/myusername/.emacs.d/auctex/style/own_beamer.el and modifying it by hand, if you want to adjust details (own_beamer.el can also be obtained without running TeX-auto-generate, by visiting own_beamer.cls and looking in subdirectory auto relative to own_beamer.cls, or the directory set up with TeX-auto-local). This way, AUCTeX will find the helper info just as in the previous section (was in /home/myusername/.emacs.d/auctex/auto/own_beamer.el; note the auto path component instead of style), but as far as I understand it, will not modify it. In particular, M-x TeX-auto-generate should never overwrite your changes in directory /home/myusername/.emacs.d/auctex/style.

Sample contents for /home/myusername/.emacs.d/auctex/style/own_beamer.el:

  (TeX-add-style-hook
   "own_beamer"
   (lambda ()
     (TeX-run-style-hooks
      "latex2e"
      "beamer"
      "booktabs"
      "graphicx")
     LaTeX-dialect))

This was mostly auto-generated when visiting or saving own_beamer.cls. Most notably, I replaced the :latex dialect with variable LaTeX-dialect because this is what the AUCTeX documentation suggests:

In case of adding a style hook for LaTeX, when calling function TeX-add-style-hook it is thought more futureproof for argument dialect-expr to pass constant LaTeX-dialect currently defined to :latex, rather than passing :latex directly.

Loading the AUCTeX helper info from .emacs.el and friends

A third way, similar to the previous one but maybe a bit less optimized in terms of load times (code executed every time you enter LaTeX-mode), consists in loading the AUCTeX helper info (Emacs Lisp code) from your Emacs initialization file(s) as shown below. Then restart Emacs and visit your file that has \documentclass{own_beamer}.

Sample code for ~/.emacs.d/init.el, ~/.emacs.el, ~/.emacs or a file of your own loaded by any of these:

(require 'tex-site)

(defun my-LaTeX-add-own-beamer-helper-info ()
  (TeX-add-style-hook
   "own_beamer"
   (lambda ()
     (TeX-run-style-hooks
      "latex2e"
      "beamer"
      "booktabs"
      "graphicx")
     LaTeX-dialect)))

(add-hook 'LaTeX-mode-hook 'my-LaTeX-add-own-beamer-helper-info)
  • Good to know, I have expanded the answer. :) – frougon Jun 21 '18 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.