[Tex/LaTex] makeindex and restricted \write18

nomenclaturepdftexshell-escape

I use the nomenclature package to create nomenclature sections for my papers. I haven't done a paper in a while with a nomenclature, but today it is not working.

In order to use the nomenclature package, I need to run makeindex and then rerun my LaTeX file. I normally have the following at the very first line of my LaTeX file and everything works fine automatically pretty much.

\immediate\write18{makeindex "paper".nlo -s nomencl.ist -o "paper".nls}

Today it isn't working though. It seems as though \write18 restricted mode is the problem. It's possible something changed with TeX Live since I last wrote a paper with a nomenclature section when I upgrade my operating system at some point.

I can get bibtex to run with \write18. Any reason why makeindex would not work? I thought it should be a safe program.

If I run with --shell-escape, everything works fine, but I don't want to do that because restricted mode was created for a reason. I can also run the makeindex command manually in a bash shell and everything works fine, but I am using kile and don't want to have to run another command all the time.

Simplest example file I can create:

\immediate\write18{makeindex "paper".nlo -s nomencl.ist -o "paper".nls}
\documentclass[11pt]{article}
\usepackage{nomencl}
\makenomenclature
\begin{document}
    \printnomenclature
    some text
    \nomenclature{$symbol$}{description}
\end{document}

Running pdflatex paper.tex produces no nomenclature. Running pdflatex --shell-escape paper.tex produces a nomenclature. When testing, make sure you delete all the extra files in the directory after running with --shell-escape or change the symbol name because you may think the problem is solved when in fact the makeindex command was just run by your last test.

How can I see what commands are allowed in restricted mode? If I run kpsewhich --var-value shell_escape_commands in bash, it returns 'bibtex,bibtex8,kpsewhich,makeindex,mpost,repstopdf,'. So, It seems as if makeindex should work.

I am using pdflatex on Ubuntu 13.04.

Best Answer

If I run the example, I get

runsystem(makeindex "donom".nlo -s nomencl.ist -o "donom".nls)...quotation error in system command.

in the log file; tested with MacTeX/TeX Live 2014 on Mac OS X and TeX Live/Debian 2013 on a Debian box.

On the other hand, if I change the line into

\immediate\write18{makeindex "\jobname.nlo" -s nomencl.ist -o "\jobname.nls"}

then the command is executed.

Note that using \jobname instead of the actual file name allows for reusing the code. Also, I'd use

\immediate\write18{makeindex -s nomencl.ist -o "\jobname.nls" "\jobname.nlo"}

because this is a more common syntax (however, makeindex accepts options also after the file name).

There is also a different strategy, that is, using arara:

% arara: nomencl
% arara: pdflatex

\documentclass[11pt]{article}
\usepackage{nomencl}
\makenomenclature
\begin{document}
    \printnomenclature
    some text
    \nomenclature{$symbol$}{description}
\end{document}

If you run the command line

arara -v <filename>

you'll achieve the same effect.

Related Question