# Glossary per chapter or section

I'm looking for a way of creating glossaries, with the help of glossaries package, per chapter or section.

In a particular glossary for section should be only the terms used in this section. If term is used in multiple section - appear in correspondent glossaries.

Example (done with the help of description environment, just for an example):

How can I achieve this?

-
Shall the glossary of a section (say) only contain items that are defined first in this section, or all items used in this section? (If the former, the glossaries are disjoint...) – mafp Jan 3 '13 at 22:03
I'm seeking for a way to include only the items which is used in the particular section. – m0nhawk Jan 3 '13 at 22:05
But a glossary item can be used in several sections, so shall it appear in all corresponding glossaries, or only in the first of them? – mafp Jan 3 '13 at 22:08
@mafp: if it used - yes, it all corresponding. – m0nhawk Jan 4 '13 at 8:04

Since you don't seem interested in the location list, you could change the location counter to section and define a glossary style that checks if the current section is in the location list. You'll probably want to neaten the glossary, but here's an example:

\documentclass{article}

\usepackage{datatool-base}
\usepackage[counter=section,xindy]{glossaries}

\GlsSetXdyMinRangeLength{0}

\makeglossaries

\newglossaryentry{E}{name={\ensuremath{E}},
description={energy}}

\newglossaryentry{m}{name={\ensuremath{m}},
description={mass}}

\newglossaryentry{c}{name={\ensuremath{c}},
description={speed of light}}

\newglossaryentry{v}{name={\ensuremath{v}},
description=velocity}

\newglossarystyle{mystyle}%
{%
\glossarystyle{list}%
\renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
\renewcommand*{\glsXsectionXglsnumberformat}[2]{##2}%
\renewcommand*{\delimR}{,}%
\renewcommand*{\glossaryentryfield}[5]{%
\edef\doifinlocation{\noexpand\ifinlocation{\thesection}{##5}}%
\doifinlocation
{%
\item ##2 ##3%
}%
}%
}

% \ifinlocation{number}{location list}{body}

\newcommand{\ifinlocation}[3]{%
\DTLifinlist{#1}{#2}{#3}{}%
}

\def\striprelax\relax#1\endstriprelax{#1}

\glossarystyle{mystyle}

\begin{document}

\section{Sample Section}

\printglossary

$$\gls{E} = \gls{m}\cdot \gls{c}^2$$

\section{Another Section}

\printglossary

$$\gls{E} = \frac{\gls{m}\gls{v}^2}{2}$$

\end{document}


Note that this uses xindy rather than makeindex to suppress the range formation, which makes it easier to test if the current section is in the list.

The result looks like:

-