summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/glossaries/samples/sample-storage-abbr.tex
blob: 7ea6faadd161425968b48b9de5cecba6ad986a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
% This file is public domain
% If you want to use arara, you need the following directives:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\glsaddstoragekey
 {abbrtype}% key/field name
 {word}% default value if not explicitly set
 {\abbrtype}% custom command to access the value if required

\newacronymstyle
 {mystyle}% style name
 {% Use the generic display
   \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
 }
 {% Put the long form in the description
   \renewcommand*{\GenericAcronymFields}{description={\the\glslongtok}}%
   % For the full format, test the value of the "abbrtype" key.
   % If it's set to "word" put the short form first with
   % the long form in brackets.
   \renewcommand*{\genacrfullformat}[2]{%
    \ifglsfieldeq{##1}{abbrtype}{word}
    {% is a proper acronym
      \protect\firstacronymfont{\glsentryshort{##1}}##2\space
       (\glsentrylong{##1})%
    }
    {% is another form of abbreviation
     \glsentrylong{##1}##2\space
      (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
  }%
  % first letter upper case version:
   \renewcommand*{\Genacrfullformat}[2]{%
    \ifglsfieldeq{##1}{abbrtype}{word}
    {% is a proper acronym
      \protect\firstacronymfont{\Glsentryshort{##1}}##2\space
       (\glsentrylong{##1})%
    }
    {% is another form of abbreviation
     \Glsentrylong{##1}##2\space
      (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
  }%
  % plural
   \renewcommand*{\genplacrfullformat}[2]{%
    \ifglsfieldeq{##1}{abbrtype}{word}
    {% is a proper acronym
      \protect\firstacronymfont{\glsentryshortpl{##1}}##2\space
       (\glsentrylong{##1})%
    }
    {% is another form of abbreviation
     \glsentrylongpl{##1}##2\space
      (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
  }%
  % plural and first letter upper case
  \renewcommand*{\Genplacrfullformat}[2]{%
    \ifglsfieldeq{##1}{abbrtype}{word}
    {% is a proper acronym
      \protect\firstacronymfont{\Glsentryshortpl{##1}}##2\space
       (\glsentrylong{##1})%
    }
    {% is another form of abbreviation
     \Glsentrylongpl{##1}##2\space
      (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
  }%
  % Just use the short form as the name part in the glossary:
  \renewcommand*{\acronymentry}[1]{\acronymfont{\glsentryshort{##1}}}%
  % Sort by the short form:
  \renewcommand*{\acronymsort}[2]{##1}%
  % Just use the surrounding font for the short form:
  \renewcommand*{\acronymfont}[1]{##1}%
  % Same for first use:
  \renewcommand*{\firstacronymfont}[1]{\acronymfont{##1}}%
  % Default plural suffix if the plural isn't explicitly set
  \renewcommand*{\acrpluralsuffix}{\glspluralsuffix}%
 }

\setacronymstyle{mystyle}

% The default for "abbrtype" is "acronym" so we don't need
% this new key for acronyms:
\newacronym{radar}{radar}{radio detecting and ranging}
\newacronym{laser}{laser}{light amplification by stimulated
emission of radiation}
\newacronym{scuba}{scuba}{self-contained underwater breathing
apparatus}

\newcommand*{\newinitialism}[4][]{%
  \newacronym[abbrtype=initialism,#1]{#2}{#3}{#4}%
}

\newinitialism{dsp}{DSP}{digital signal processing}
\newinitialism{atm}{ATM}{automated teller machine}

\begin{document}

First use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
\gls{atm}.

Next use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
\gls{atm}.

\printglossaries
\end{document}