Following one of the answers from here for managing two distinct indexes, I need to call

makeindex -t mydoc.plg -o mydoc.pnd mydoc.pdx
makeindex -t mydoc.slg -o mydoc.snd mydoc.sdx

when I want to update my indexes. How can I tell Auctex to call these two lines in an automatic way? Should I do something like "override" the Index command from Auctex?

  • Just notes from an analysis for a general approach: (TeX-add-style-hook "index"...) Therein: Add parsing newindex macros to LaTeX-auto-regexp-list. One gets a list of the new indexes. SubstituteTeX-run-index by an alternative my-TeX-run-indexes in TeX-command-list (e.g., via customization). In my-TeX-run-indexes do essentially the stuff of TeX-run-index for all indexes found via the list of indexes generated by the new entry in LaTeX-auto-regexp-list. – Tobias Dec 7 at 1:56
up vote 1 down vote accepted

The most simple solution is to change the Command part of the Index entry in TeX-command-list via M-x customize-option RET TeX-command-list RET.

I suggest to input

makeindex -t %s.plg -o %s.pnd %s.pdx; makeindex -t %s.slg -o %s.snd %s.sdx;

there. Afterwards click the button Apply.

This works but it has the disadvantage that you must repeat the setting after the next restart of Emacs.

Alternatively you can change the value of TeX-command-list buffer-locally with file local variables in the LaTeX file. That is demonstrated with the file-local variables in the next example. The LaTeX part is stolen from Gilles' answer on tex.se.

One must take care that the modification of TeX-command-list remains buffer local. That makes the form after the ;;; eval: a bit complicated.

Nevertheless you find the above makeindex command line in there and you can modify according to your needs.

\documentclass{article}
\usepackage{index}
\newindex{person}{pdx}{pnd}{Index of named persons}
\newindex{symbol}{sdx}{snd}{Index of symbolism}

\begin{document}

Hello, \index*[person]{vanden} \index*[symbol]{SomeSymbol}.

\printindex[person]
\printindex[symbol]
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-list TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "makeindex -t %s.plg -o %s.pnd %s.pdx; makeindex -t %s.slg -o %s.snd %s.sdx;" TeX-run-index nil t :help "makeindex for index.sty"))
%%% End:

There are several alternatives for the form in %%% eval: .... They all have their pros and cons.

  1. Using copy-alist
(setf (alist-get "Index" (setq-local mylist (copy-alist TeX-command-list)) nil nil #'string-equal) '("makeindex -t %s.plg -o %s.pnd %s.pdx; makeindex -t %s.slg -o %s.snd %s.sdx;" TeX-run-index nil t :help "makeindex for index.sty"))

PROS:

  • somewhat shorter
  • Just calls to setf, alist-get, and copy-alist

CONS:

  • all cons are copied not just the modified ones

  1. Defining a new function in your init file
(defun modified-alist (alist &optional modifications &rest plist)
  "Make a copy of ALIST and apply MODIFICATIONS.
The entries of the association list MODIFICATIONS replace the
corresponding entries of ALIST.
\nKeywords supported:  :test :test-not :key

\n(fn ALIST &optional MODIFICATIONS [KEYWORD VALUE]...)"
  (setq alist (cl-copy-list alist))
  (dolist (m modifications)
    (setcar (or (apply #'cl-member (car m) alist plist) (setq alist (cons nil alist))) m))
  alist)

You can use that function in the ;;; eval:... line:

(setq-local TeX-command-list (modified-alist TeX-command-list '(("Index" "makeindex -t %s.plg -o %s.pnd %s.pdx; makeindex -t %s.slg -o %s.snd %s.sdx;" TeX-run-index nil t :help "makeindex for index.sty")) :key #'car :test #'string-equal)

PROS:

  • including the setq-local just two commands
  • only the modified cons is copied

CONS:

  • requires code in init file
  • Mmmmm... I tried the first approach (the one using the eval) and it does not work for me. I see only one of the two indexes. Do I need to put that code in the master file or also in the others? Does the code work for you (can you see two indexes)? I am afraid that the problem is not your code but the usage of the two indexes as described in the linked question. I will make some more trials and update you – Nisba Dec 10 at 14:19
  • It works from the command line, so the solution using eval is for some reason not working with me. Do I need to tell Emacs that I have changed the eval field? – Nisba Dec 10 at 14:21
  • @Nisba Yes, kill the buffer and find the file again. Emacs will ask you whether to eval the eval forms in the file local variables. Answer yes or t to that question. Alternatively you can also call M-: (hack-local-variables).RET. In that case there is no need to re-load the file. – Tobias Dec 10 at 14:23
  • I have done as you said but Emacs does not ask me to eval the local variables. I also see that changing the TeX-master field has no effect. So the problem could be with my Emacs. I will come back to this answer when I will have fixed my Emacs, for the moment I give you the upvote ;-) – Nisba Dec 10 at 14:33
  • What does C-h v enable-local-variables RET say? It should be t. What happens if you call M-x normal-mode RET. – Tobias Dec 10 at 14:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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