[Tex/LaTex] Nomencl Reference Section Number

cross-referencingnomenclaturesectioning

I'm writing a PhD thesis that includes many similar symbols. Therefore, I'd like to list in the nomenclature the section number at which each symbol is initially using (and therefore defined in the text). I'm aware you can list the page number, but I'd prefer the section number. Is there a way to do this?

Here's a minimal example what I have at the moment to define the section number, although this requires me to manually check each reference is correct:

\documentclass{report}
\usepackage{nomencl}

\makenomenclature

\begin{document}
    \printnomenclature

    \chapter{Structural Analysis} \label{sec:Structural Analysis}
    \section{Sectional Properties} \label{sec:Sectional Properties}
    The cross-sectional area is defined as
    \begin{equation} \label{eqn:Cross-sectional area}
        A = \int_{S} \: dS
    \end{equation}
    \nomenclature{$A$}{cross-sectional area, m$^{2}$ (\ref{sec:Sectional Properties})}
    \nomenclature{$S$}{arbitrary surface (\ref{sec:Sectional Properties})}

\end{document}

I tried using \thesection as the reference but as expected this value was calculated during when creating the nomenclature, not at the position of \nomenclature.

I imagine there should be a way to do this through programming but haven't been able to find a solution.

Best Answer

You can take advantage of the fact that the section number is known at the moment you issue the \nomenclature command.

Here's a way to do it with a new command:

% arara: pdflatex
% arara: nomencl
% arara: pdflatex
% arara: pdflatex
\documentclass{report}
\usepackage{nomencl}

\makenomenclature

\newcommand{\mynomencl}[3][section]{%
  \begingroup\edef\x{\endgroup
  \unexpanded{\nomenclature{#2}}%
    {\unexpanded{#3} (\csname the#1\endcsname)}}\x}

\begin{document}
\printnomenclature

\chapter{Structural Analysis} \label{sec:Structural Analysis}
\section{Sectional Properties} \label{sec:Sectional Properties}

The cross-sectional area is defined as
\begin{equation} \label{eqn:Cross-sectional area}
  A = \int_{S} \, dS
\end{equation}
\mynomencl{$A$}{cross-sectional area, m$^{2}$}
\mynomencl{$S$}{arbitrary surface}

\chapter{Structural Analysis} \label{sec:Structural Analysis2}
\section{Sectional Properties} \label{sec:Sectional Properties2}
The cross-sectional area is defined as
\begin{equation} \label{eqn:Cross-sectional area2}
  A = \int_{S} \, dS
\end{equation}
\mynomencl[chapter]{$A2$}{cross-sectional area, m$^{2}$}
\mynomencl{$S2$}{arbitrary surface}

\end{document}

The \mynomencl command has an optional argument for specifying the sectional units the entry should refer to (default section).

How does it work? The command \mynomencl stores in \x the \nomenclature{...}{... (<number>)} command, without expanding anything except for the last part (the number). Then it executes \x (making it also disappear from memory).

The initial comments use arara for speeding up compilation, not having to remember the command line for generating the nomenclature. They are of course optional.

enter image description here