# Situation

I'm using nomencl with a custom *.ist file. I found the required code snippets in various posts, I combined them to fit my needs, but unfortunately I never really understood properly what I was doing, especially for the 'style'-code between \makeatletter and \makeatother.

MikTex 2.9
TeXnicCenter 2.02

# Problem Description

Now the output is almost what I would like, but each nomgroup has the same subheader, Symbol - Description - Unit (see example screenshot below). Where the Unit is mandatory for the Constants group, it is undesired for Acronyms or Superscripts groups. Therefore I would like to have a different subheader per group.

A manual workaround that helped so far is

1. compiling several times until everything is ok
2. open the *.nls file, searching the Unit and manually removing/changing it
3. run the final compilation with the tweaked *.nls

Obviously this manual intervention needs to be repeated everytime I compile the document, since the *.nls is regenerated everytime.

# My question(s)

1. How/if I can use a boolean variable to trigger the appearance of Unit?
or
2. How/if I can use a variable (maybe in the nomgroup definition?) that is placed at the position of Unit in the subheader?

My secondary question

I found so many MWEs for nomencl, requiring no additional packages but none does work for me neither on mine nor on my colleagues computer. The packages called in my MWE are required to enable use of nomencl for me (even for supersimple MWEs), especially \longtable, \nomentbl, \booktabs, of course \etoolbox is only required for more advanced modifications.

# MWE

\documentclass{article}
\usepackage{nomencl}
\usepackage{longtable}
\usepackage{nomentbl}
\usepackage{booktabs}
\usepackage{etoolbox}

% define and format nomenclature groups
\renewcommand\nomgroup[1]{%
\Large\sffamily\bfseries
\ifstrequal{#1}{A}{Acronyms}{%
\ifstrequal{#1}{L}{Latin Symbols}{%
\ifstrequal{#1}{G}{Greek Symbols}{%
\ifstrequal{#1}{S}{Superscripts}{%
\ifstrequal{#1}{U}{Subscripts}{%
\ifstrequal{#1}{C}{Constants}{}}}}}}
}

% nomenclature style
\makeatletter
\def\@@@nomenclature[#1]#2#3#4#5{%
\def\@tempa{#2}\def\@tempb{#3}%
\protected@write\@nomenclaturefile{}%
{\string\nomenclatureentry{%
#1\nom@verb\@tempa @{\nom@verb\@tempa}&%
\begingroup\nom@verb\@tempb\endgroup &\begingroup#4\endgroup&%
\begingroup#5\endgroup&\begingroup\protect\nomeqref{\theequation}%
|nompageref}{\thepage}}%
\endgroup
\@esphack}
\renewcommand\nomenclature[4][]{\@nomenclature[#1]{#2}{#3}{}{#4}}
\makeatother

\makenomenclature

\begin{document}
\mbox{}

\nomenclature[l]{$l$}{Length No 1}{m}
\nomenclature[L]{$m$}{Mass}{kg}
\nomenclature[l]{$l$}{Length No 2}{m}
\nomenclature[A]{$a$}{a test}{}
\nomenclature[G]{$\eta$}{Efficiency}{1}
\nomenclature[S]{0}{Standard State}{}
\nomenclature[U]{th}{thermal}{}
\nomenclature[C]{$F$}{Faraday Constant}{96485\,As\,mol\textsuperscript{-1}}

\printnomenclature
\end{document}

# The *.ist file

actual '@'
quote '%'
delim_0   ""
delim_1   ""
delim_2   ""
item_0    ""
delim_t   " \\\\\n"
line_max  1000
\\multicolumn{1}{l}{\\bfseries Symbol} & \\multicolumn{1}{l}{\\bfseries Description} & & %
\\multicolumn{1}{l}{\\bfseries Unit} \\\\ \\toprule \n\\nopagebreak"
group_skip        "\\\\*"
preamble "\n\\begin{thenomenclature}\n%
\\begin{longtable}[l]{lp{\\textwidth*\\real{0.5}}c!{\\extracolsep{\\fill}}ll}\n%
\\bfseries Symbol & \\bfseries Description & & \\bfseries%
postamble "\n\\end{longtable}\n\n\\end{thenomenclature}\n"
keyword "\\nomenclatureentry"

The final output (without manual tweaks of *.nls file) looks like:

• Your secondary question: You need nomentbl and longtable because you want your nomenclature in tabular form instead of a list form. And that probably is because you want to include the unit. The nomencl package has other solutions for these but these may be a little bit more complicated. And you have booktabs because you want a nice layout in the table. – Piet van Oostrum Dec 16 '16 at 20:48

In your .ist file, replace Unit with \\Unit.

In your .tex file, replace the \nomgroup definition with

% define and format nomenclature groups
\newcommand{\Unit}{Unit}
\newcommand{\noUnit}{\gdef\Unit{}}
\renewcommand\nomgroup[1]{%
\gdef\Unit{Unit}%
\Large\sffamily\bfseries
\ifstrequal{#1}{A}{Acronyms\noUnit}{%
\ifstrequal{#1}{L}{Latin Symbols}{%
\ifstrequal{#1}{G}{Greek Symbols}{%
\ifstrequal{#1}{S}{Superscripts\noUnit}{%
\ifstrequal{#1}{U}{Subscripts\noUnit}{%
\ifstrequal{#1}{C}{Constants}{}}}}}}
}

Then run makeindex and (pdf)latex again.