After pulling out the guts of nomencl
and replacing them with metal parts, it seems to be alive!
Usage:
Different from the usual approach, of redefining the \nomgroup
macro to add an \ifstrequal
to select the header of the items, the modified form introduces a command:
\newsymbolclass[<ncols>]{<id>}{<title>}
which defines a "Symbol Class" called <title>
and is printed in the Nomenclature with <ncols>
columns.
Then each nomenclature entry is added with:
\addsymbol{<id>}[<sort-order>]{<symbol>}{<description>}
which has basically the same syntax as the old \nomenclature
:
\nomenclature[<class><sort-order>]{<symbol>}{<description>}
except that the <class>
is implicitly set according to the <id>
.
One nice thing (in my opinion) is that this scheme does is that the order of appearance of the "lists-of" depends on the order of declaration of the symbol classes so, for example, the picture above was generated with:
\newsymbolclass[2]{unit}{Units}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass {acro}{Acronyms}
but if we wanted, say, to make them in alphabetical order, we would need to use:
\newsymbolclass {acro}{Acronyms}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass[2]{unit}{Units}
Each entry in the class is still sorted alphabetically by MakeIndex
which obeys the given <sort-order>
.
How it works:
First we load the multicol
package for the columns, etoolbox
for a few shorthands like \csedef
, and enumitem
because I still don't understand how LaTeX's "primitive" \list
works :P
Then we define a couple of registers we're going to use. \@symsep
is the blank space between the symbol and its description and \@symind
is the indentation of the symbol.
The \nomenclheader
macro is responsible for creating the header of each symbol class. Here I used a \subsubsection*
for this.
The \thenomenclature
environment is basically the same, except that the standard \list
is removed. Later on the \nomgroup
macro will start the list using \begin{enumerate}
.
The \nomenclature
macro is made inaccessible because it will not follow the rules of the new scheme. The error message tells the user to use the higher level \addsymbol
instead. Of course, the macro still exists and is called \@nomenclature
for the stubborn.
Now we start to build things. We first define the \newsymbolclass
macro. This macro just does a bunch of definitions. Say, for example, we call:
\newsymbolclass[3]{pref}{Prefixes}
then we'll have:
\def\symb@pref{}% Just a dummy empty macro
\def\symb@pref@ord{A}% This replaces the old \ifstrequal{A}{Prefixes} syntax. This will be B for the next class and so on...
\def\symb@pref@wd{0pt}% This will be the width of the widest symbol
\def\symb@pref@nc{3}% The number of columns (#1)
with the definitions above we have almost all the settings we need. The problem is that the argument of \nomgroup
is not the <id>
(pref
in this example), but the first letter of the alphabetical ordering argument (A
in the example above). Basically, we know that pref
means A
, but \nomgroup
doesn't know that A
means pref
, so we define:
\def\symb@A@name{pref}% A backreference
\def\symb@A@title{Prefixes}% The title, for convenience
Now we define the \addsymbol
macro. This is just a fancy wrapper for the former \nomenclature
macro. It will check if the given class exists, then it will measure the symbol and store the maximum with of the symbol in that symbol class. Finally, it calls the usual \nomenclature
.
Now the actual typesetting macro is defined. The \nomgroup
macro first checks if another \nomgroup
is open and closes it, if needed (I admit, this is lazy programming :P). Then a \nomenclheader
is issued with \symb@#1@title
. We then check if the number of columns is larger than one and start a multicols
if that's the case. Finally we fetch the width of the widest symbol, add the \@symsep
, and pass everything as argument to the \begin{enumerate}
.
That's it :)
I think that this version is much easier to customize, as the parameters can be changed in the optional argument to \begin{enumerate}
and, modesty aside, I think that it is less messy than the other version.
% arara: pdflatex
% arara: nomencl
% arara: pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[acronym]{glossaries}
\usepackage[utf8]{inputenc}
\usepackage[norefpage]{nomencl}
\usepackage{newmencl}
\begin{document}
Some text to compile.
\newsymbolclass[2]{unit}{Units}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass{acro}{Acronyms}
%Add units
\newcommand{\nomunit}[1]{%
\renewcommand{\nomentryend}{\hspace*{\fill}\makebox[1cm][l]{#1}}%
}
%Label width
\nomlabelwidth=10mm
%Units
\addsymbol{unit}{Bq}{Becquerel \nomunit{1 des/s}}
\addsymbol{unit}{Ci}{Curie \nomunit{$3.7 \times 10^{10} Bq$}}
\addsymbol{unit}{N}{Newton \nomunit{$kg m/s^2$}}
\addsymbol{unit}{A}{Ampere \nomunit{c/s}}
%Prefixes
\addsymbol{pref}[01]{f}{femto \nomunit{$10^{-15}$}}
\addsymbol{pref}[02]{p}{pico \nomunit{$10^{-12}$}}
\addsymbol{pref}[03]{n}{nano \nomunit{$10^{-9}$}}
\addsymbol{pref}[04]{$\mu$}{micro \nomunit{$10^{-6}$}}
\addsymbol{pref}[05]{m}{mili \nomunit{$10^{-3}$}}
\addsymbol{pref}[06]{k}{kilo \nomunit{$10^{3}$}}
\addsymbol{pref}[07]{M}{mega \nomunit{$10^{6}$}}
\addsymbol{pref}[08]{G}{giga \nomunit{$10^{9}$}}
%Acronyms
\addsymbol{acro}{ABC}{Text for ABC}
\addsymbol{acro}{DEF long long long}{Very long long long long long long long long long long long long long long text for DEF}
\addsymbol{acro}{GHI}{Text for GHI}
\printnomenclature
\end{document}
And the newmencl
(proto)-package is:
\ProvidesPackage{newmencl}
\RequirePackage{enumitem}
\RequirePackage{multicol}
\RequirePackage{etoolbox}
\RequirePackage{nomencl}
\newlist{nomencl}{enumerate}{1}
\setlist[nomencl]{%
topsep=\z@,
itemsep=\z@,
labelindent=\@symind,
labelwidth=\wd\tempbox@b,
labelsep*=\@symsep,
align=left,
leftmargin=!,
}
\def\setnomencl#1{\setlist*[nomencl]{#1}}
\newbox\tempbox@b
\def\nomentryend{.}
\def\symbnodot{\let\nomentryend\relax}
\def\nomenclheader#1{\subsubsection*{#1}}
\newif\ifmustclose\mustclosefalse
\def\thenomenclature{%
\@ifundefined{chapter}%
{\section*{\nomname}%
\if@intoc\addcontentsline{toc}{section}{\nomname}\fi}%
{\chapter*{\nomname}%
\if@intoc\addcontentsline{toc}{chapter}{\nomname}\fi}%
\par\nompreamble}%
\def\endthenomenclature{%
\end{nomencl}%
\ifinmulticol
\end{multicols}%
\inmulticolfalse
\fi
\nompostamble}
\let\@@nomenclature\nomenclature
\def\nomenclature{%
\PackageError{}{Don't use the \string\nomenclature\space command.%
\MessageBreak Use the appropriate \string\addsymbol\space instead}%
{}}
\newdimen\@symsep\@symsep=1em
\newdimen\@symind\@symind=1em
\newif\ifinmulticol
\def\nomgroup#1{%
\edef\tempa{\@nameuse{symb@#1@nc}}
\ifmustclose
\end{nomencl}
\ifinmulticol
\end{multicols}%
\inmulticolfalse
\fi
\fi\mustclosetrue
\vskip\parskip
\itemsep\z@
\nomenclheader{\@nameuse{symb@#1@title}}%
\setbox\tempbox@b\hbox{\@nameuse{symb@#1@widest}}%
\expandafter\ifnum\csname symb@\@nameuse{symb@#1@name}@nc\endcsname>\@ne
\inmulticoltrue
\begin{multicols}{\@nameuse{symb@\@nameuse{symb@#1@name}@nc}}%
\fi
\begin{nomencl}}
\def\addsymbol#1{\@ifnextchar[%]
{\@addsymbol{#1}}{\@symbolnoopt{#1}}}%
\def\@symbolnoopt#1#2{%
\@addsymbol#1[{#2}]{#2}}
\def\@addsymbol#1[#2]#3#4{%
\expandafter\ifx\csname symb@#1\endcsname\@empty\else
\PackageError{}{%
Class #1 undefined. Use \string\newsymbolclass{#1}}{}
\fi
\setbox\@tempboxa\hbox{#3}%
\setbox\tempbox@b\hbox{\@nameuse{symb@#1@widest}}%
\ifdim\wd\tempbox@b<\wd\@tempboxa
\csgdef{symb@#1@widest}{#3}%
\fi
\@nomenclature[\@nameuse{symb@#1@ord}#2]{#3}{#4}%
\ignorespaces}
\newcount\@nsymbcls
\def\newsymbolclass{\@ifnextchar[%]
\@newsymbolclass{\@newsymbolclass[1]}}
\def\@newsymbolclass[#1]#2#3{%
\expandafter\ifx\csname symb@#2\endcsname\@empty
\PackageError{}{Symbol Class #2 already defined}{}
\fi
\global\advance\@nsymbcls\@ne
\csgdef{symb@#2}{}%
\csxdef{symb@#2@ord}{\@Alph\@nsymbcls}%
\csgdef{symb@#2@widest}{}%
\csxdef{symb@#2@nc}{#1}% Save number of columns
\csxdef{symb@\@nameuse{symb@#2@ord}@name}{#2}% For backreference
\protected@csxdef{symb@\@nameuse{symb@#2@ord}@title}{#3}}
\AtEndDocument{%
\count@\z@
\@whilenum\count@<\@nsymbcls\do{%
\advance\count@\@ne
\edef\@tempa{\@nameuse{symb@\@Alph\count@ @name}}%
\toks@\expandafter\expandafter\expandafter
{\csname symb@\@tempa @widest\endcsname}%
\immediate\write\@auxout{%
\gdef\expandonce{\csname symb@\@Alph\count@ @widest\endcsname}%
{\the\toks@}}}}%
\makenomenclature
\endinput
You can change the appearance of the list using the \setnomencl
, which is a wrapper around \setlist*[nomencl]
.
Best Answer
You can have as many entries as you want with the same symbol.
I have streamlined the
\nomgroup
command, but your definition works as well.