2

Usually, AUCTeX activates beamer-specific settings (e.g. syntax highlighting) depending on \documentclass. In my LaTeX templates, however, I have separated the preamble from the rest of the document using \input{beamer-preamble}.

Here's an MWE:

\input{beamer-preamble}  % `beamer-preamble.tex` only contains `\documentclass{beamer}`
\begin{document}

\title{Some title}

\begin{frame}
\frametitle{Some frame title}
\end{frame}

\end{document}

In this example, the argument of \frametitle should be highlighted similarly to the argument of \title.

How can I tell AUCTeX to still apply the beamer-specific settings?

5
  • Can you show your beamer-preamble and a .tex file where you use it and do the actual typesetting? Commented Apr 26, 2017 at 8:09
  • @ArashEsbati I've updated the question. Interestingly, AUCTeX sometimes does it right, but not always.
    – Timm
    Commented Apr 26, 2017 at 14:13
  • What is your setting of Tex-auto-local? Have you updated the local files? Commented Apr 26, 2017 at 15:23
  • @AndrewSwann Tex-auto-local points to some directory under .emacs.d. In fact, when I remove the AUCTeX files there, the highlighting changes for the worse.
    – Timm
    Commented Apr 26, 2017 at 16:11
  • It us usually just "auto" so that information can be stored in that subdirectory where your current tex file is. Have you changed the defaults? Commented Apr 26, 2017 at 16:38

1 Answer 1

4

First of all, I suggest you create a proper class file beamer-preamble.cls like this:

\NeedsTeXFormat{LaTeX2e} 
\ProvidesClass{beamer-preamble}
  [2017/04/26 v0.1 My Beamer Preamble]
\LoadClass[<beamer-options>]{beamer}

Next, you want to have an AUCTeX style file for beamer-preamble.cls. Doing M-x TeX-auto-generate RET in one way. But I recommend writing your own style file. Something like this should suffice:

(TeX-add-style-hook
 "beamer-preamble"
 (lambda ()
   (TeX-run-style-hooks "beamer"))
 LaTeX-dialect)

Customize TeX-style-private to a directory of your choice and save the code above as beamer-preamble.el there. Add this to your init file,

(setq TeX-parse-self t)

restart Emacs and open your .tex file.

1
  • 2
    Thanks for your answer, which brought me to think about an even simpler (but more ad-hoc) solution: just add eval: (TeX-run-style-hooks "beamer") to the local variables of the file. Still, I really like the more generic approach of defining classes and including them globally.
    – Timm
    Commented Apr 28, 2017 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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