[Tex/LaTex] Why does \setacronymstyle{long-short-desc} overwrite \renewcommand*{\glsentryfmt}

glossaries

I am currently writing a paper with an extended glossary. Therefore, I use the glossaries package. I want the first appearance of a glossary entry being indicated by a symbol preceding the name of the entry. Until some recent changes to the package this could be achieved with the following code:

\defglsdisplayfirst[\glsdefaulttype]{#1}

(In above case, nothing would be changed but the content of the last brackets is responsible for the first entry's appearance, see my extended example below.)

Now, the same thing is achieved with the following code:

\renewcommand*{\glsentryfmt}{%
    \ifglsused{\glslabel}{}{}
    \glsgenentryfmt
}

(In this example, the first entry would not be changed but \ifglsused makes it possible to insert anything in the second brackets which would precede the actual entry which is inserted with \glsgenentryfmt.)

I find the new approach more difficult but it is explained in glossaries-user.pdf on page 100 at the bottom and is more flexible of course. After fiddling around with the package and doing some adjustments I found out that changing the acronym style makes \renewcommand*{\glsentryfmt} (and so on) useless as can be tested with the following code:

\documentclass{article}

\usepackage{MnSymbol}

\newcommand{\glmarker}{$\smalltriangleright$}

\usepackage{glossaries}
\makeglossaries

% overwriting the first appearance of a glossary entry
% in previous versions this was done with
%
%   \defglsdisplayfirst[\glsdefaulttype]{\glmarker\,#1}
%
% now, it is done with the following command (see glossaries-user.pdf, p. 100
% bottom)
\renewcommand*{\glsentryfmt}{%
    \ifglsused{\glslabel}{}{\glmarker\,}
    \glsgenentryfmt
}

\setglossarystyle{altlist}

% with setting the acronymstyle to 'long-short-desc' overwrites the adjustments
% for the first appearance of an gls entry (it does not matter whether
% \setacronymstyle is triggered before or after \renewcommand*{\glsentryfmt}

%\setacronymstyle{long-short-desc}

\newglossaryentry{example}{
    name={example},
    description={
        an example is an example
   }
}

\begin{document}

This is the first appearance of an entry in the glossary: \gls{example}. This
is the second appearance of an entry in the glossary: \gls{example}.

\printglossaries

\end{document}

Not setting the acronym style results in the following output (which I intended but displays acronyms not as long-short-desc):

example w/o setting new acronym style

But setting the new acronym style results in the following output without the marker I would like to add before the first appearance of the entry. And the code defining the first appearance of an entry is still active!

example w/ setting new acronym style

I also tried switching the appearance of setting the new acronym style and defining the new appearance of the first entry in the code but, unfortunately, this did not result in a working example.

Is this intended and I am doing something wrong? I did not have this problem when I used the (now) out-dated variant of defining the appearance of a first entry.

Best Answer

Since it's usual for acronyms to be displayed in a different way to general entries, \setacronymstyle uses \defglsentryfmt[type]{\GlsUseAcrEntryDispStyle{style}} where type is the name of the glossary and style is the acronym style. This is done for every glossary type that has been identified as a list of acronyms. Since your main glossary contains a mixture of acronyms and general entries, this makes the acronym style override \glsentryfmt. This means that if you want a mixed glossary, you need to adjust the acronym display style rather than redefine \glsentryfmt.

The long-short-desc acronym style is defined as follows:

\newacronymstyle{long-short-desc}%
{%
  \GlsUseAcrEntryDispStyle{long-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-short}%
  \renewcommand*{\GenericAcronymFields}{}%
  \renewcommand*{\acronymsort}[2]{##2}%
  \renewcommand*{\acronymentry}[1]{%
    \glsentrylong{##1}\space (\acronymfont{\glsentryshort{##1}})}%
}

The actual display style is the same as for long-short which sets the display style to:

  \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%

This checks if the entry is an acronym (via \ifglshaslong) and, if it is an acronym, it will do \glsgenacfmt, which is the generic acronym format, otherwise it will do \glsgenentryfmt, which is the generic non-acronym format. So for a mixed glossary, as in your case, you need to define a similar style that performs the appropriate modifications.

For example:

\newacronymstyle{marker-long-short-desc}
{%
   \ifglsused{\glslabel}{}{\glmarker\,}
   \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
}
{%
  \GlsUseAcrStyleDefs{long-short-desc}%
}

\setacronymstyle{marker-long-short-desc}

Or, if you only want the marker for non-acronym entries:

\newacronymstyle{marker-long-short-desc}
{%
   \ifglshaslong{\glslabel}%
   {\glsgenacfmt}%
   {\ifglsused{\glslabel}{}{\glmarker\,} \glsgenentryfmt}%
}
{%
  \GlsUseAcrStyleDefs{long-short-desc}%
}

\setacronymstyle{marker-long-short-desc}

Here's the full example:

\documentclass{article}

\usepackage{MnSymbol}

\newcommand{\glmarker}{$\smalltriangleright$}

\usepackage{glossaries}
\makeglossaries

\setglossarystyle{altlist}

\newacronymstyle{marker-long-short-desc}
{%
   \ifglsused{\glslabel}{}{\glmarker\,}
   \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
}
{%
  \GlsUseAcrStyleDefs{long-short-desc}%
}

\setacronymstyle{marker-long-short-desc}

\newglossaryentry{example}{
    name={example},
    description={
        an example is an example
   }
}

\begin{document}

This is the first appearance of an entry in the glossary:
\gls{example}. This
is the second appearance of an entry in the glossary: \gls{example}.

\printglossaries

\end{document}

This produces:

Image of resulting document