Can't use bars | | in nomenclature package

Here's a weird error that I'm running into using the nomenclature package nomencl

The following code :

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{nomencl}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\makenomenclature

\begin{document}
\mbox{}

\nomenclature{$S^n$}{The $n$-sphere defined by $S^n = \{x \in \mathbb{R}^{n+1} \ | \ |x| = 1 \}$}
\nomenclature{$\mathbb{Z}$}{The integers}

\printnomenclature
\end{document}


gives the following output

However if in the above I change

$S^n = \{x \in \mathbb{R}^{n+1} : \text{norm of } x = 1 \}$


to

$S^n = \{x \in \mathbb{R}^{n+1} \ | \ |x| = 1 \}$


so that I have the following (desired) code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{nomencl}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\makenomenclature

\begin{document}
\mbox{}

\nomenclature{$S^n$}{The $n$-sphere defined by $S^n = \{x \in \mathbb{R}^{n+1} \ | \ |x| = 1 \}$}
\nomenclature{$\mathbb{Z}$}{The integers}

\printnomenclature
\end{document}


then the part about the n-sphere doesn't show up anymore

I'm not sure if I'm using the nomenclature package outside of its scope, but it seems to be that the character

|


doesn't work in math mode when used in the second input of \nomenclature{}{}. How can I get the desired code to compile/render correctly?

For what it's worth I am using pdfLatex to render the output.

• @c.p. I just tried it and it doesn't work either. – Perturbative Oct 7 '19 at 6:36
• Isn't nomenclature using makeindex behind the scenes? There | is a special char. Use \vert instead. Btw | is not the correct symbol for absolute value or norm, try taking the norm of -1 and you'll notice the spacing on the minus is wrong. I generally recommend using a \abs macro etc, see the examples in the mathtools manual – daleif Oct 7 '19 at 6:36
• A recommended way for sets is \{x\in X \mid <conditions>\}; using “space,bar,space” is wrong. – egreg Oct 7 '19 at 8:34

The character | is special for MakeIndex, so entries with it are rejected. You could quote it, but nomencl.ist defines the quoting character as %, so the effect is that no quoting character is available at all.

On the other hand, the correct syntax for your set notation and the absolute value is

\{x \in \mathbb{R}^{n+1} \mid \lvert x\rvert = 1 \}


which poses no problem to nomencl.

This is how I'd code the example.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{nomencl}

% shorthands
\newcommand{\numberset}[1]{\mathbb{#1}}% generic command
\newcommand{\nR}{\numberset{R}}
\newcommand{\nZ}{\numberset{Z}}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

% setup

\makenomenclature

\begin{document}

\mbox{}

\nomenclature[Sn]{$S^n$}{The $n$-sphere defined by $S^n = \{x \in \nR^{n+1} \mid \abs{x} = 1 \}$}
\nomenclature[Z]{$\nZ$}{The integers}

\printnomenclature
\end{document}


Using the prefix for \nomenclature helps in sorting. The shorthands help in keying and reading the source.