TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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:

share|improve this answer
    
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.

share|improve this answer

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):

Latex output

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.