# Using Nomenclature and emacs

I'm learning how to `\usepackage{nomencl}`. So far so good.

I added the nomenclature compile option to the Emacs commands by editing my .emacs file, adding:

``````;; nomenclature for latex
'("Nomenclature" "makeindex %s.nlo -s nomencl.ist -o %s.nls" TeX-run-command nil t :help "Create nomenclature file")))
``````

to it, this works: when I press `C-c C-c` (the shortcut for `TeX-command-list` I can use the `Nomenclature` command and the appropriate file is generated. I am unhappy though, for the following reason:

When I run BibTeX, and then press `C-c C-c` again, Emacs offers to run LaTeX (as appropriate, and if references have changed, it will offer `Command: (default) LaTeX` again, finally, it will offer `Command (default) View`, once the .log doesn't report references have changed. When I run Nomeclature, the next command offered by Emacs is `Command (default) View`, which is always inappropriate.

How can I tell Emacs to default to LaTeX as the next `TeX-command-list` command after running Nomenclature (same behavior as BibTeX)?

-
I've also posted this on StackOverflow, as I'm not sure where is more appropriate. –  Yossi Farjoun Nov 30 '11 at 5:58
It might be nice to add links between the questions, particularly since they have different titles. –  Ivan Andrus Dec 2 '11 at 16:31
Link to SO qn: stackoverflow.com/questions/8321742/… –  Charles Stewart Nov 20 '12 at 12:41

The easiest way (that I know of) is to use a function in the place of `TeX-run-command` like:

``````;; nomenclature for latex
'("Nomenclature" "makeindex %s.nlo -s nomencl.ist -o %s.nls"
(lambda (name command file)
(TeX-run-compile name command file)
(TeX-process-set-variable file 'TeX-command-next TeX-command-default))
nil t :help "Create nomenclature file")))
``````

You should use `TeX-command-default` instead of `"LaTeX"` since that will automatically choose between latex or plain tex etc. Note that I used `TeX-run-compile` instead of `TeX-run-command` since for some reason I couldn't get that to work.

You can also create a custom "sentinel" function which will check for errors etc. See `TeX-BibTeX-sentinel` as an example. This would allow you to conditionally change what the next command is based on whether there are errors etc. I don't think you have to, or even want to, do that in this case, but you can if you need to in the future.

-
Awesome! thanks. and thanks for all the details in your answer. –  Yossi Farjoun Dec 3 '11 at 4:21
Thansk for asking this question and forcing me to finally fix my setup. I've had it partly broken for a long time now. `:-)` –  Ivan Andrus Dec 10 '11 at 20:23