2

I am using the following code

\documentclass{article}
\usepackage{nomencl}
\makenomenclature
\renewcommand{\nomname}{List of Abbreviations}

\begin{document}

\addcontentsline{toc}{section}{List of Abbreviations}

\nomenclature{(\mathbb N_r)}{Set of all positive integers greater than or equal to $r!$}

\printnomenclature

\end{document}

But for some reason I cannot make the factorial above work. The "!" is pushing the sentence to the next line. Any suggestion to remedy this issue is appreciated. Thank you!

egreg
  • 1,121,712
  • Hi there! I can't get your document to compile, even after adding a document class and \begin and \end{document} and removing the extra backslashes, so I can't reproduce your error. Could you please edit your question to include a minimal working example? That is, it should be possible to copy-paste your code and see the issue without needing further alteration. – gz839918 Mar 27 '24 at 01:55
  • @gz839918 Can you try now? It is working in overleaf for me, except of course the issue that I mentioned. – ShyamalSayak Mar 27 '24 at 03:04
  • Right now, I can't reproduce your issue with only the code in the question. That's because you're missing a \documentclass, a \begin{document}, and an \end{document}. The link in my comment has more details about what you should include in your question. There may also be other packages that are affecting your code. Could you please edit your question to include these details? Thanks! – gz839918 Mar 27 '24 at 03:23
  • Okay. I edited it. – ShyamalSayak Mar 27 '24 at 03:32
  • Hey Shyamal, perhaps you may not be understanding what I'm asking. When you copy-paste your own code from this question, are you able to recreate this issue? When I use your code from this question, I get an error. When I remove the extra backslashes on lines 2-3, your code no longer has errors, but it simply doesn't result in a document. What code should I run so that I can see your issue in my own document? I'd suggest revisiting the link about how to create a minimal working example and edit your question based on the link. – gz839918 Mar 27 '24 at 04:51

2 Answers2

5

Heyo!

First of all your MWE doesn't compile, because \mathbb requires the amssymb package.

Now to your actual question, the problem is: nomencl package doesn't allow exclamation marks in keys

Workaround #1:

As suggested in the linked question, you can fix this by escaping the exclamation mark:

\nomenclature{\(\mathbb{N}\)}{Set of all positive integers greater than or equal to \(r%!\)}

However, this breaks the syntax highlighting in Overleaf and throws errors there (even though it compiles just fine).

Workaround #2

Add the following to the preamble:

\newcommand{\bang}{\mathrm{!}}

and then

\nomenclature{\(\mathbb{N}\)}{Set of all positive integers greater than or equal to \(r\bang\)}

This does not break the syntax highlighting in Overleaf. See What's the difference between \mathrm and \operatorname? for an explanation of \mathrm.

lvatt
  • 66
  • 1
    Welcome! Sorry, but if it throws errors then it doesn't 'compile fine'. Anything produced after an error is useful for diagnostics and debugging only. It is never reliable as output. The fact that Overleaf tends to obscure this doesn't change it. – cfr Mar 27 '24 at 07:06
  • 1
    Thank you!

    Sorry for the misunderstanding, when I say "it compiles just fine" I mean that it does not throw any compiler errors (i.e. compiling it on the command line with latexmk does not throw any errors or warnings, thus the resulting document is valid). The errors I mentioned are merely related to Overleafs' own Syntax checker.

    – lvatt Mar 27 '24 at 07:26
  • Thanks. Your second suggestion worked. – ShyamalSayak Mar 27 '24 at 14:31
  • Thanks for clarifying. – cfr Mar 27 '24 at 15:33
2

The package nomencl relies on makeindex for sorting and massaging the nomenclature entries.

For makeindex the character ! is special so it should be quoted in material passed to it. What's “quoting” in makeindex?

The makeindex style file, in this case nomencl.ist, may contain a line such as

quote "%"

If no quote line is present in the style file, the default for makeindex is " and you could type in your entry as

\nomenclature{\(\mathbb{N}_{r}\)}{Set of all positive integers greater than or equal to $r"!$}

This happened to annoy German users, because babel makes " into a shorthand character, so starting from nomencl version 2.5 the nomencl.ist file contains

quote '%'

(double or single quotes can be used there for isolating the string). Thus you can input your entry as

\nomenclature{\(\mathbb{N}_{r}\)}{Set of all positive integers greater than or equal to $r%!$}

but, of course, this breaks the syntax coloring/checking of editors (in particular the one in Overleaf that tries to check syntax on the fly). The LaTeX run would be good even if the point is marked “wrong”.

What we could do is to replace the special characters in the arguments before passing them to \nomenclature. You can judge if this is worth the pain. In the code [\!\@] stands for the list of special characters we want to quote with a %.

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

\documentclass{article} \usepackage[intoc]{nomencl} \usepackage{amssymb}

\makenomenclature \renewcommand{\nomname}{List of Abbreviations}

\ExplSyntaxOn

\NewCommandCopy{\originalnomenclature}{\nomenclature} \RenewDocumentCommand{\nomenclature}{O{}mm} { \shaya_nomencl:nnn { #1 } { #2 } { #3 } }

\tl_new:N \l_shaya_nomencl_one_tl \tl_new:N \l_shaya_nomencl_two_tl

\cs_new_protected:Nn \shaya_nomencl:nnn { \tl_set:Nn \l_shaya_nomencl_one_tl { #2 } \tl_set:Nn \l_shaya_nomencl_two_tl { #3 } \regex_replace_all:nnN { [!@] } { \cO%\0 } \l_shaya_nomencl_one_tl \regex_replace_all:nnN { [!@] } { \cO%\0 } \l_shaya_nomencl_two_tl __shaya_nomencl:nVV { #1 } \l_shaya_nomencl_one_tl \l_shaya_nomencl_two_tl } \cs_new_protected:Nn __shaya_nomencl:nnn { \originalnomenclature[#1]{#2}{#3} } \cs_generate_variant:Nn __shaya_nomencl:nnn { nVV }

\ExplSyntaxOff

\begin{document}

\tableofcontents

\section{Introduction}

Some text

\nomenclature{(\mathbb{N}_{r})}{Set of all positive integers greater than or equal to $r!$}

\printnomenclature

\end{document}

Please, note that \mathbb N is not the best way to input the symbol and it should be \mathbb{N}. Also, if you want to insert the nomenclature in the table of contents, use the intoc option, rather than doing it manually.

enter image description here

egreg
  • 1,121,712