5

I am currently working on a document for which I use a custom index style file. When I type C-c C-c to compile my document, Emacs/AucTeX offers to run its Index command (which I assume runs makeindex). This works fine, except that the style is not applied. Is there a way to tell AucTeX that it should use a certain style file for this specific LaTeX file (i.e. that it should run makeindex -s mystile.ist)? I looked around in AucTeX's customizations, but couldn't find any commands related to indexing.

Edit It seems that the index command is defined in TeX-command-list. Is there a way to overwrite this for a given file? For example, by adding something to the Local Variables at the bottom of my .tex file?

1 Answer 1

5

Very good question, it's strange that no one ever asked for this feature. Luckily, AUCTeX allows you to expand it with a bit of Lisp code. The trick is to add a new command to TeX-command-list and a new expander to TeX-expand-list (for more details see (info "(auctex)Selecting a command")).

Add the following to your init file:

(eval-after-load "tex"
  '(progn
     ;; Define a new safe buffer-local variable to change its value on a
     ;; per-file basis
     (defvar mg-TeX-index-options "")
     (make-variable-buffer-local 'mg-TeX-index-options)
     (put 'mg-TeX-index-options 'safe-local-variable 'stringp)
     ;; Add new expansion string
     (add-to-list 'TeX-expand-list
          '("%(indexopts)" (lambda () mg-TeX-index-options)))
     ;; Add new command.
     (add-to-list 'TeX-command-list
          '("MyIndex"
            "makeindex %(indexopts) %s"
            TeX-run-index nil t
            :help "Run makeindex to create index file"))))

Compile the index with MyIndex command rather than Index when you need to specify a style file, and add mg-TeX-index-options as a file local variable, that is a string holding the options you want to pass to makeindex:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% mg-TeX-index-options: "-s mystile.ist"
%%% End:
4
  • This variable can't be safe without a lot more validation. It allows executing arbitrary code via the command shell. Commented Jun 10, 2016 at 20:53
  • I can remove the safe-local-variable in order to make users more conscious about what they're going to do, but that's the only way to make it work.
    – giordano
    Commented Jun 10, 2016 at 22:34
  • I am not able to make it work with this: tex.stackexchange.com/questions/65247/… is it my fault?
    – Nisba
    Commented Jun 8, 2018 at 17:10
  • @giordano Thanks for this advice. It works for me partially. The cons of this solution are (to me): it only works locally, i.e. if you are compiling from this buffer. If you split your document with \include, this won't work, as MyIndex will be run without style file. Furthermore, C-c C-a won't use MyIndex but still plain Index (and of course again no index style!). Your answer is now 3,5 yrs old, still AUCTeX uses the old mechanism as before. Furthermore, xindy isn't even mentioned by AUCTeX at all, which I think, it should. This part needs an update, as BibLaTeX has got.
    – Jan
    Commented Dec 12, 2019 at 14:49

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.