Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

glossaries package FAQ

How do I define my own custom acronym style? 🔗

As from version 4.02, you can define your own acronym style using \newacronymstyle. For example, suppose you want the long form to appear in the margin on first use. You could define the style from scratch, but you might find it easier to base the new style on an existing style. For example, let’s define a new style called “margin” that’s based on the short-long style:

\newacronymstyle{margin}
{%
  \GlsUseAcrEntryDispStyle{short-long}%
}%
{%
  \GlsUseAcrStyleDefs{short-long}%  
  \renewcommand*{\genacrfullformat}[2]{%
   \protect\firstacronymfont{\glsentryshort{##1}}##2%
   \protect\marginpar{\glsentrylong{##1}}%
  }%
  \renewcommand*{\Genacrfullformat}[2]{%
   \firstacronymfont{\Glsentryshort{##1}}##2%
   \protect\marginpar{\glsentrylong{##1}}%
  }%
  \renewcommand*{\genplacrfullformat}[2]{%
   \protect\firstacronymfont{\glsentryshortpl{##1}}##2%
   \protect\marginpar{\glsentrylongpl{##1}}%
  }%
  \renewcommand*{\Genplacrfullformat}[2]{%
   \protect\firstacronymfont{\Glsentryshortpl{##1}}##2%
   \protect\marginpar{\glsentrylongpl{##1}}%
  }%
}
Now you can set the style:
\setacronymstyle{margin}

Note that if you are using glossaries-extra, it uses a completely different abbreviation mechanism. The above is only for cases where the base glossaries package is being used without the glossaries-extra extension package.

Pre glossaries version 4.02:

A new style can be set by redefining \CustomAcronymFields and using \SetCustomStyle.

\DeclareRobustCommand{\MARGINPAR}[1]{\marginpar{#1}}

\renewcommand*{\CustomAcronymFields}{%
  name={\the\glsshorttok},% name is abbreviated form
  description={\the\glslongtok},% description is long form
  first={\the\glsshorttok\MARGINPAR{\the\glslongtok}},%
  firstplural={\the\glsshorttok\noexpand\acrpluralsuffix\MARGINPAR{\the\glslongtok}},%
  text={\the\glsshorttok},%
  plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}

\SetCustomStyle % Switch to custom style
Note that this method gets more complicated if the plural forms can’t be derived by appending the singular form with the plural suffix (“s” by default). If you find this a problem, then upgrade to the latest version and use \newacronymstyle as described above.

2020-06-27 16:13:08


Permalink: https://www.dickimaw-books.com/faq.php?id=55
Alternative link: https://www.dickimaw-books.com/faq.php?itemlabel=customacronym

Category: glossaries package
Topic: Referencing Terms