4

I use the package \usepackage[acronym,toc]{glossaries}

In the text I write my acronyms usually via \gls{Acr}, \acrshort{Acr} or \acrlong{Acr}

This displays my acronyms like:

Acronymdescription (Acr)

Acr

Acronymdescription

Now my question: How can I get the description in brackets?

Acr (Acronymdescription)

I used in a makeshift manner \acrshort{Acr} (\acrlong{Acr})

Is there a better solution?

Minimal example:

\documentclass{scrreprt}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp} % special chars
\usepackage{lmodern} % better fonts
\usepackage{relsize} % font size relative
\usepackage{xcolor} 

\definecolor{navy}{RGB}{0,0,128}

\usepackage[
    bookmarks,
    bookmarksopen=true,
    bookmarksnumbered,
    colorlinks=true,
    linkcolor=navy, % link colors
    anchorcolor=black,% anchor link color
    citecolor=navy, % referral to bibliography items in the text
    filecolor=navy, % links to local files
    menucolor=black, % Acrobat-menuecolor
    urlcolor=navy, 
    backref,
    plainpages=false, % needed for correct creation of bookmarks
    pdfpagelabels=true, % needed for correct creation of bookmarks
    hypertexnames=true, % needed for correct creation of bookmarks
    linktocpage % page number linked to text in toc
]{hyperref}

\usepackage[acronym]{glossaries}
\makeglossaries

\newacronym{DIN}{DIN}{Deutsches Institut für Normung}

\begin{document}

Often I need the standard form: \gls{DIN}.

But sometimes I need it like this: \acrshort{DIN} (\acrlong{DIN}).

Better would be an single command that includes the bracket in the link.

\newpage
\printglossary

\end{document}
  • It's easier if you provide a minimal working example (MWE) but it looks like you want something like display the short form followed by the long form – Nicola Talbot Feb 4 '14 at 11:18
  • I added as requested the MWE. It looks promising but I dont want to change the style for all acronyms. I just need a single command... – kitingChris Feb 4 '14 at 12:32
  • 1
    Then I think \newcommand\myacr[1]{\acrshort{#1} (\acrlong{#1})} in the preamble will be enough. You'll use it \myacr{DIN} in your document. – Gonzalo Medina Feb 4 '14 at 12:45
  • Yea thought on that too but then the brackets are not included... but maybe a better solution than now. – kitingChris Feb 4 '14 at 13:40
  • 2
    Perhaps \newcommand*\myacr[2][]{\glslink[#1]{#2}{\glsentryshort{#2} (\glsentrylong{#2})}} – Nicola Talbot Feb 4 '14 at 16:10
4

(Transferring my comment to an answer.)

You can use \glslink to provide a link to a glossary entry with your own custom text. The commands \glsentrylong and \glsentryshort just display the long or short form without doing anything else (such as creating a link) so you can combine them to define your custom command:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[acronym]{glossaries}
\makeglossaries

\newacronym{DIN}{DIN}{Deutsches Institut für Normung}

\newcommand*\myacr[2][]{\glslink[#1]{#2}{\glsentryshort{#2} (\glsentrylong{#2})}}

\begin{document}

Standard form: \gls{DIN}.

Other way round: \myacr{DIN}.

\printglossaries

\end{document}

This produces:

Image of resulting document

Note that \glslink doesn't change the first use flag, so if I change the ordering in the above to:

Other way round: \myacr{DIN}.

Standard form: \gls{DIN}.

Then \gls{DIN} still gets fully expanded. If you want to change the first use flag then use \glsdisp instead of \glslink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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