[Tex/LaTex] How to define a custom glossary style

glossaries

How can one define his/her own glossary style.

I am looking for a set of commands (for instance):

\printitem{name}{description}{...}
\printoffsetcharacter{character}

That one can redefine and thus typeset the glossary him/herself.


MWE:

Say I have a glossary:

\documentclass{article}
\usepackage{glossaries}
\newglossaryentry{computer}{
    name=computer,
    description={is a programmable machine that receives input, stores and manipulates data, and provides output in a useful format}
}
\begin{document}
\glsaddall
\printglossaries
\end{document}

Will print something like:

Computer is a programmable machine that receives input, stores and manipulates data, and provides output in a useful format, 1.

Say I want to modify this such that the name is in italic, there should be a command like:

\renewcommand{\printitem}[2]{\emph{#1}: #2}

When some kind of group-style is used, another command should be redefined that prints the first character:

\renewcommand{\printoffsetcharacter}[1]{\textbf{#1}}

resulting in:

C

Computer: is a programmable machine that receives input, stores and manipulates data, and provides output in a useful format

Best Answer

Changing the glossary style is described in the Defining your own glossary style section of the user manual. You can define a new style that's based on an existing style and use that. For example:

\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\newglossaryentry{computer}{
    name=computer,
    description={is a programmable machine that receives input,
stores and manipulates data, and provides output in a useful format}
}

\newglossarystyle{mystyle}{%
 \setglossarystyle{treegroup}%
 \renewcommand*{\glossentry}[2]{%
   \glsentryitem{##1}\textit{\glstarget{##1}{\glossentryname{##1}}}%
   :\space \glossentrydesc{##1}\par
 }%
}

\setglossarystyle{mystyle}

\begin{document}

\glsaddall
\printglossaries

\end{document}

This produces:

Image of resulting glossary

Related Question