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?

4

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:
  • This variable can't be safe without a lot more validation. It allows executing arbitrary code via the command shell. – Gilles 'SO- stop being evil' Jun 10 '16 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 Jun 10 '16 at 22:34
  • I am not able to make it work with this: tex.stackexchange.com/questions/65247/… is it my fault? – Nisba Jun 8 '18 at 17:10

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.