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 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):

enter image description here

How can I achieve this?

share|improve this question
    
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
add comment

1 Answer

up vote 11 down vote accepted

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

\begin{equation}
\gls{E} = \gls{m}\cdot \gls{c}^2
\end{equation}

\section{Another Section}

\printglossary

\begin{equation}
\gls{E} = \frac{\gls{m}\gls{v}^2}{2}
\end{equation}

\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:

image of document

share|improve this answer
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.