5

I am using the nomencl package, and so far it has worked out flawlessly. However, today I decided to introduce some notation that includes an exclamation mark, and it failed.

There is a minimal example here:

\documentclass{article}
\usepackage{nomencl}
\makenomenclature

\begin{document}
\nomenclature{$n!$}{factorial of $n$}
\[
 n! = \prod_{i=1}^n i
\]
\printnomenclature
\end{document}
  • pdflatex text.tex runs OK
  • makeindex test.nlo -s nomencl.ist -o test.nls runs OK, and reports "1 entries accepted, 0 rejected)", etc (no problem).
  • pdflatex text.tex, ran for the second time after makeindex, fails.

The error is this:

Writing nomenclature file test.nlo
(./test.aux) (./test.nls
! Missing $ inserted.
<inserted text> 
                $
l.6     \subitem
                 [{$n
? 

If I remove the exclamation mark, like this:

\nomenclature{$n$}{factorial of $n$}

then the document compiles and produces the correct output.

I have tried using $n{!}$ and $n\!$, but that didn't fix the problem.

What would be the right way to include $n!$, or $!n$, or other expressions with exclamation marks in nomenclature?

Jay
  • 2,895
  • 2
  • 27
  • 38

1 Answers1

11

! is a special character for MakeIndex (that is used for sorting the nomenclature). Quote it with MakeIndex's method, that is, adding % in front of it:

% arara: pdflatex
% arara: nomencl
% arara: pdflatex

\documentclass{article} \usepackage{nomencl} \makenomenclature

\begin{document} \nomenclature{$n%!$}{factorial of $n$} [ n! = \prod_{i=1}^n i ] \printnomenclature \end{document}

I added the suitable arara calls for taking care of the nomenclature. See https://tex.stackexchange.com/a/77879/4427 for more information and links about arara.

Note. Before 2018, the quote character was " instead of %. The change makes it impossible to hide such nomenclature entries in macros, so beware.

egreg
  • 1,121,712
  • I'm still having this issue with the exclamation mark. Saved your code as main.tex file and then I ran pdflatex main.tex / makeindex main.nlo -s nomencl.ist -o main.nls / pdflatex main.tex But I got the same error OP had. – Julio Cesar Aug 08 '23 at 17:55
  • 1
    @JulioCesar For very mysterious reasons, nomencl.ist now has % as the quote character. See edited answer. – egreg Aug 08 '23 at 19:09