6

I'm using KOMA-script, which offers the use of letter-class-options, which can be stored in a file: *.lco.

One command I define in a "zrp.lco" is very simple:

\newcommand{\Beweis}[1]{Beweis: #1}

Now I'd like to teach Emacs to know about this command. I tried to put into my .emacs:

 (TeX-add-style-hook
      "zrp"
      (lambda ()
        (TeX-add-symbols
     '("Beweis" 1))))

But Emacs spills out an error while loading:

eval-buffer: Symbol's function definition is void: TeX-add-style-hook

What is wrong?

9
  • TeX-add-style-hook is defined in auctex, presumably you are doing this too early (I just ran your code in my scratch buffer without error) – David Carlisle Apr 8 '14 at 9:38
  • @DavidCarlisle OK, thank you. But loading AUCTeX directly is not possible, (require 'auctex) inside .emacs gives an error. So what I probably need is a kind of hook: if AUCTeX is loaded, run this code... – Keks Dose Apr 8 '14 at 9:43
  • 1
    Wrap an eval-after-load "tex" around TeX-add-style-hook. – giordano Apr 8 '14 at 9:44
  • 1
    or put it in LaTeX-mode-hook – David Carlisle Apr 8 '14 at 9:46
  • 1
    On the other hand, auctex has a powerful auto-parsing mechanism for such user-defined commands, it might be an even better idea to investigate how to get it to parse your .lco files. – T. Verron Apr 8 '14 at 9:53
9

The proper way to add support for a new style file is to create a style hook file, as explained in the AUCTeX manual.

Note that you can autogenerate the style hook file for a *TeX source issuing M-x TeX-auto-generate RET, see Automatic Customization for a User.

If you want to put your style hook inside your .emacs, you have to insert it inside an eval-after-load so it will be run only when AUCTeX is loaded. In particular, your code should be changed to

(eval-after-load "latex"
  '(progn
     (TeX-add-style-hook
      "zrp"
      (lambda ()
    (TeX-add-symbols
     '("Beweis" 1))))))

Note that the hook defined will be automatically executed only if there is an explicit

\usepackage{zrp}

in your LaTeX code, otherwise you have to use

(TeX-run-style-hooks "zrp")

to run it.

1

After switching to AucTeX 11.88 I took a second look at the matter. TeX-add-style-hook now has a third argument and I found this simple solution for my .emacs file:

(add-hook 'LaTeX-mode-hook
      (lambda ()
    (TeX-add-symbols
      '("Beweis" 1)
      '("AnlageK" t)
      '("AnlageB" t)
      '("signed" 1)
      )))

If a wiser man / woman notices a drawback of this solution, please leave a comment.

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.