Latest news 2020-07-03: SmashWords sale (ends 31st July 2020): 50% off crime/SF novel The Private Enemy and 100% off (free!) I’ve Heard the Mermaid Sing.

# Bug Tracker

ID: 51 🔗 Closed (Not a Bug) glossaries 4.01 Ola Olsson 2013-12-28 07:40:19 Acronym disables glsentryfmt...

## Report

Adding the line makes the custom formatting go away...
\newacronym{apa}{apa}{Apa per Apa}

see the repro code.

### MWE

\documentclass{article}
\usepackage{glossaries}

\makeglossaries

\renewcommand*{\glsentryfmt}{%
\glsgenentryfmt
\ifglsused{\glslabel}{}{\space (\glsentrysymbol{\glslabel})}%
}

\newglossaryentry{distance}{name=distance,
description={The length between two points},
symbol={km}}

\newacronym{apa}{apa}{Apa per Apa}

\begin{document}

First use: \gls{distance}. Next use: \gls{distance}.

\end{document}


## Evaluation

This isn't a bug but is a feature of having a mixture of acronyms and regular entries in the same glossary. There are two issues:
1. As per section Acronym Options in the user manual, you can use the package option acronymlists to identify a glossary that contains acronyms. This sets up the display format for the given glossaries via \defglsentryfmt.

If \newacronym is used in a glossary that hasn't been identified in this way, then \newacronym will automatically add that glossary to the list of acronyms and will use \defglsentryfmt to setup the display style for that glossary. So to prevent \newacronym from overriding the display style for a particular glossary you need to have already identified that glossary as a list of acronyms using the acronymlists package option (or the equivalent \DeclareAcronymList command).

\usepackage[acronymlists=main]{glossaries}

or
\DeclareAcronymList{main}

2. Redefining \glsentryfmt only has an effect on glossaries that haven't had their display style changed via \defglsentryfmt. Since using all acronyms set their display style using \defglsentryfmt, the only way to change their style is to use \defglsentryfmt rather than redefining \glsentryfmt. So you would need to do:
\defglsentryfmt{%
\glsgenentryfmt
\ifglsused{\glslabel}{}{\space (\glsentrysymbol{\glslabel})}%
}

However, this will interfere with the way the acronyms are displayed so \gls{apa} will produce "Apa per Apa (apa) ()" which has an unwanted set of parentheses. Instead you need to modify the argument of \defglsentryfmt so that it checks if the entry is an acronym:
\defglsentryfmt{%
\glsgenentryfmt
\ifglshaslong{\glslabel}%
{}% this entry is an acronym so do nothing
{\ifglsused{\glslabel}{}{\space (\glsentrysymbol{\glslabel})}}%
}

The complete document is now:
\documentclass{article}
\usepackage[acronymlists=main]{glossaries}

\makeglossaries

\defglsentryfmt{%
\glsgenentryfmt
\ifglshaslong{\glslabel}%
{}% this entry is an acronym so do nothing
{\ifglsused{\glslabel}{}{\space (\glsentrysymbol{\glslabel})}}%
}

\newglossaryentry{distance}{name=distance,
description={The length between two points},
symbol={km}}

\newacronym{apa}{apa}{Apa per Apa}

\begin{document}

First use: \gls{distance}. Next use: \gls{distance}.

Acronym first use: \gls{apa}. Next use: \gls{apa}.
\end{document}

If you choose to upgrade to version 4.02, there's another approach:
\documentclass{article}
\usepackage[acronymlists=main]{glossaries}

\makeglossaries

\newacronymstyle
{my-custom-style}% style name
{% display
\ifglshaslong{\glslabel}%
{\glsgenacfmt}% acronym
{% not an acronym
\glsgenentryfmt
\ifglsused{\glslabel}{}{\space (\glsentrysymbol{\glslabel})}%
}%
}%
{% style definitions
\GlsUseAcrStyleDefs{long-short}% use the same style as 'long-short'
}

% switch to this new style:
\setacronymstyle{my-custom-style}

\newglossaryentry{distance}{name=distance,
description={The length between two points},
symbol={km}}

\newacronym{apa}{apa}{Apa per Apa}

\begin{document}

First use: \gls{distance}. Next use: \gls{distance}.

Acronym: \gls{apa}. \gls{apa}.
\end{document}


## Watch This Report

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

Name: (Optional.)