# Glossaries: Print first occurence by using ACRONYM (DESC)

Is there a way to change the way how the acronyms in glossaries package are printed on the first occurence when defining them via \newacronym{cd}{CD}{compact disk}. Currently I'm using the following to achieve it:

\newglossaryentry{BLAS}{%
type=\acronymtype,
name={BLAS},
description={Basic Linear Algebra Subprograms},
first={\glstext*{BLAS} (\glsdesc*{BLAS})}%
}


which works, but is somehow to quite optimal yet since I need to particularly set the first-item. Any other ideas?

-

You can use \defglsdisplayfirst to change the format applied to an acronym when it is referenced the first time:

\documentclass{article}

\usepackage{glossaries}[2011/04/12]

\AtBeginDocument{%
\defglsdisplayfirst[\acronymtype]{%
\glsentryshort{\glslabel} (\glsentrylong{\glslabel})#4%
}%
}

\newacronym{BLAS}{BLAS}{Basic Linear Algebra Subprograms}

\makeglossaries

\begin{document}

\printglossary

\noindent
The \gls{BLAS} are \ldots

\end{document}


The resulting output is:

-
Please note that glsdisplayfirst has been deprecated. See page 105 in the documentation for reference. – Frederik Aalund Jan 3 '15 at 21:16

If you look into section 13.3 Defining A Custom Acronym Style of the glossaries documentation, you will find what you need.

An example of this code can be found in: http://archive.cs.uu.nl/mirror/CTAN/macros/latex/contrib/glossaries/samples/sample-custom-acronym.tex.

-

I encountered some problems with glsdisplayfirst (extra spaces after acronyms). Here is my solution using newacronymstyle (based on glossaries official sample code sam­ple-cus­tom-acronym.tex):

\documentclass[hidelinks]{report}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}

%define new style:
\newacronymstyle{custom-fn}% new style name
{% Check for long form in case of a mixed glossary
\ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
}%
{% Style definitions:
\glshyperfirstfalse
% Redefine the commands used by \glsgenacfmt on first use:
\renewcommand*{\genacrfullformat}[2]{%
\glsentryshort{##1} (\glsentrylong{##1})##2%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\Glsentryshort{##1} (\Glsentrylong{##1})##2%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\glsentryshortpl{##1} (\glsentrylongpl{##1})##2%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\Glsentryshortpl{##1} (\Glsentrylongpl{##1})##2%
}%
}

% Now set the new acronym style (to override the default style)
\setacronymstyle{custom-fn}

% Set an appropriate glossary style:
\setglossarystyle{altlist}

% Now define the acronyms (must be done after setting the custom
% style)
\newacronym{blas}{BLAS}{Basic Linear Algebra Subprograms}
\makeglossaries

\begin{document}
%\printglossaries

\noindent
First occurence of \gls{blas}.

\noindent
And second occurence of \gls{blas}.

\end{document}

-