4

As in Glossary per chapter or section, I'm trying to use the glossaries package to create acronym lists but only by chapter, not by section.
I've tried to adapt the answer, but I don't manage to do it.
Here's a minimal example :

\documentclass{report}
\usepackage{datatool-base}
\usepackage[counter=chapter,xindy,section=section]{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}%
{%
  \setglossarystyle{list}%
  \renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
  \renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimR}{,}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##5}}%
    \doifinlocation
    {%
      \item ##2 ##3%
    }%
  }%
}
\newcommand{\ifinlocation}[3]{%
 \DTLifinlist{#1}{#2}{#3}{}%
}
\def\striprelax\relax#1\endstriprelax{#1}
\setglossarystyle{mystyle}

\begin{document}
\chapter{Sample Chapter}
\printglossary
\begin{equation}
\gls{E} = \gls{m}\cdot \gls{c}^2
\end{equation}
\glsresetall 
\chapter{Another Chapter}
\printglossary
\begin{equation}
\gls{E} = \frac{\gls{m}\gls{v}^2}{2}
\end{equation}
\end{document}

The result looks like : Output page 1 : Sample chapter Output page 2 : Another chapter
How can I remove the glossary entry about velocity in the first chapter and the one about speed of light in the second chapter ?
Thanks in advance

4

The problem here is that you're mixing old and new commands. My original answer that you linked to is several years old and uses commands that are now deprecated, such as \glossarystyle and \glossaryentryfield. Your MWE has changed the deprecated \glossarystyle to \setglossarystyle but hasn't changed the deprecated \glossaryentryfield. By using the new \setglossarystyle, the backward-compatibility is removed and \glossaryentryfield isn't used.

To fix it, just replace \glossaryentryfield with the newer \glossentry:

  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation
    {%
      \item \glossentryname{##1} \glossentrydesc{##1}%
    }%
  }%

Complete MWE:

\documentclass{report}
\usepackage{datatool-base}
\usepackage[counter=chapter,xindy,section=section]{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}%
{%
  \setglossarystyle{list}%
  \renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
  \renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimR}{,}%
  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation
    {%
      \item \glossentryname{##1} \glossentrydesc{##1}%
    }%
  }%
}
\newcommand{\ifinlocation}[3]{%
 \DTLifinlist{#1}{#2}{#3}{}%
}
\def\striprelax\relax#1\endstriprelax{#1}
\setglossarystyle{mystyle}

\begin{document}
\chapter{Sample Chapter}
\printglossary
\begin{equation}
\gls{E} = \gls{m}\cdot \gls{c}^2
\end{equation}
\glsresetall 
\chapter{Another Chapter}
\printglossary
\begin{equation}
\gls{E} = \frac{\gls{m}\gls{v}^2}{2}
\end{equation}
\end{document}

First chapter:

image of chapter 1

Second chapter:

image of second chapter

  • the above solution of glossary, acronym per chapter not working for me. Its printing in the first chapter, but from 2nd chapter onwards the only the unqiue glossaries that are not used in ch-1 are printed and same for chapter-3, means only unique glossaries, acronym, symbols and any custom type are only printed per chapter. I am unable to rectify it. Is there a solution to this issue. – Deb bijan Aug 13 '18 at 18:31
  • @Debbijan The MWE uses \glsresetall, which will affect acronyms but shouldn't affect the glossary per chapter. I recommend that you post a follow-up question with a MWE that reproduces the problem. – Nicola Talbot Aug 13 '18 at 18:45
  • as u mentioned I removed the \glsresetall for all chapter as a trial, and found that glossaries now printed for all chapter. But sometimes in compiling its don't prints and sometimes it does. Is there any particular compiling order sequence in which I should compile for creating glossaries and index. Here my index is not printed. – Deb bijan Aug 14 '18 at 2:29
  • I am not able to align the description in a separate column left aligned so that all description are nicely aligned vertically. The spacing between glossary terms to be adjusted to maximum width so that all description auto starts from same vertical position. Can it be done for above formating style. – Deb bijan Aug 15 '18 at 6:13
  • @Debbijan I suggest you post a follow-up question. You can link back to this one. – Nicola Talbot Aug 16 '18 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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