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

Bug Tracker RSS feed

I’m currently working on a major new version of the datatool package. This may take a while. Please be patient. (Experimental version available for testing.)

ID 51🔗
Date: 2013-12-28 07:40:19
Status Closed (Not a Bug)
Category glossaries
Version 4.01
Summary Acronym disables glsentryfmt...

Sign in to subscribe to notifications about this report.

Description

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

MWE

Download (408B)

\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}

Comments

0 comments.


Add Comment

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:


You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.

Page permalink: https://www.dickimaw-books.com/bugtracker.php?key=51