Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.sx! No need to add thanks and signature. Your user badge is automatically added to the post and you can show your gratitude by upvoting any good answers you may receive. We select to dothings this way to make posts more concise. –  Peter Jansson Feb 27 '13 at 11:30
add comment

1 Answer

up vote 5 down vote accepted

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

share|improve this answer
    
Great! That's exactly what I've been trying to do, thanks! –  Jonathan Allen Feb 27 '13 at 16:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.