5

I would like to set up a glossary using the package glossaries-extra in such a way that the acronyms would be displayed in full at the beginning of each chapters for their first appearance and then only the acronym would appear.

\documentclass{book}
\usepackage{hyperref}
\usepackage[xindy]{glossaries-extra}

\makeglossary

\newacronym{lmi}{LMI}{Linear Matrix Inequality}

\begin{document}
\printglossary

Hello world

\chapter{First}
First use: \gls{lmi}
Second use: \gls{lmi}

\chapter{Second}
First use: \gls{lmi}
Second use: \gls{lmi} 

\end{document}

Basically, in the code above, I am looking for a macro that displays: Linear Matrix Inequality (LMI) for the first appearance in a chapter and then simply LMI for the next appearances.

Thanks.

Romain.

1 Answer 1

4

I think the simplest method is to add \glsresetall to the start of each chapter with etoolbox's \preto command. (etoolbox is automatically loaded by glossaries and therefore by glossaries-extra but I've loaded it explicitly below for clarity.)

\documentclass{book}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage[xindy]{glossaries-extra}

\preto\chapter{\glsresetall}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}
\newacronym{lmi}{LMI}{Linear Matrix Inequality}

\begin{document}
\printglossary

Hello world

\chapter{First}
First use: \gls{lmi}
Second use: \gls{lmi}

\chapter{Second}
First use: \gls{lmi}
Second use: \gls{lmi}

\end{document}

First chapter:

Chapter 1 First. First use: Linear Matrix Inequality (LMI) Second use: LMI

Second chapter:

Chapter 2 Second. First use: Linear Matrix Inequality (LMI) Second use: LMI

5
  • 1
    Nowadays one doesn't need to load etoolbox and instead could use \AddToHook{cmd/chapter/pre}{\glsresetall} instead of \preto
    – Skillmon
    Commented Jan 9, 2022 at 12:11
  • 1
    @Skillmon Nowadays it would be cmd/chapter/before, wouldn't it?
    – gusbrs
    Commented Jun 7, 2022 at 22:01
  • Anyone interested in combining per chapter resetting with entry unit counting, check tex.stackexchange.com/a/646628/105447. (Nicola, if you think the use case is interesting as an example in the documentation, feel free to use it).
    – gusbrs
    Commented Jun 7, 2022 at 22:04
  • @gusbrs yes, that would be the correct name now ;)
    – Skillmon
    Commented Jun 8, 2022 at 6:15
  • @Skillmon Nowadays I shouldn't be making typo puns. :) I just left a note for the benefit of other people, as I was myself bitten by it, since I though "It's Skillmon's, it must be right", and it took me some time to figure it out. ;-)
    – gusbrs
    Commented Jun 8, 2022 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .