summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gloss/gloss.sty
blob: b9687767c0202d4febc9d51e8a0f0ceaa7d910ac (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
% +--------------------------------------------------+
% | Typeset gloss.tex to get the documentation.      |
% +--------------------------------------------------+
%
% (c) 1998 Jose Luis Diaz, 1999-2002 Jose Luis Diaz and Javier Bezos.
% All Rights Reserved.
%
% This file is part of the gloss distribution release 1.5.2
% -----------------------------------------------------------
%
% This file can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.

\def\fileversion{1.5.2}
\def\filedate{2002/07/26}

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{gloss}[\filedate\space\fileversion\space Gloss package]

\edef\gls@a{\catcode`\string:=\the\catcode`:\relax}
\catcode`:=12

\providecommand\glossname{Glossary}
\newcommand\glosspage[1]{, p.\nobreakspace#1.}
\newcommand\xglosspage{\glosspage}

\DeclareOption{refpages}{%
  \def\endglossitem{%
    \@ifundefined{gls@thispage}%
      {.}%
      {\glosspage\gls@thispage}%
    \par}%
  \@namedef{endglossitem*}{%
    \@ifundefined{gls@thispage}%
      {}%
      {\xglosspage\gls@thispage}%
    \par}}

% Declaring new glossaries
% ~~~~~~~~~~~~~~~~~~~~~~~~

% 1:label 2:ext 3:title 4:bibstyle

\newcommand\newgloss[4]{%
  \if@filesw
    \expandafter\newwrite\csname glsf@#1\endcsname
    \immediate\openout\csname glsf@#1\endcsname\jobname#2.aux %
    \PackageInfo{gloss}{Writing gloss file \jobname#2.aux}%
    \immediate\write\csname glsf@#1\endcsname{\string\bibstyle{#4}}%
  \fi
  \@namedef{glst@#1}{\def\gls@title{#3}}%
  \@namedef{glso@#1}{\edef\gls@base{\jobname#2}\edef\gls@name{#1}}}

\newcommand\makegloss{%
  \newgloss{default}{.gls}{\glossname}{glsplain}}

\def\glso@default{\PackageError{gloss}{Missing default glossary}%
  {You missed either \string\makegloss or a \string\newgloss
   with a `default' label}}

% Two .aux related commands
% ~~~~~~~~~~~~~~~~~~~~~~~~
% In both of them, #1 includes (already expanded) \gls@name ::

\def\gls@cite{%
  \begingroup
    \catcode`:=12
    \gls@cite@i}
\def\gls@cite@i#1#2#3#4{%
  \endgroup
  \global\@namedef{gls@#1}{{#2}{#3}{#4}}}

\def\gls@page{%
  \begingroup
    \catcode`:=12
    \gls@page@i}
\def\gls@page@i#1#2{%
  \endgroup
  \global\@namedef{glsp@#1}{#2}}

% The \gloss command
% ~~~~~~~~~~~~~~~~~~
% The command:

\newcommand\gloss{\protect\gls@gloss@i}

\def\gls@gloss@i{%
  \@bsphack
  \begingroup
    \catcode`\ =9
    \@ifnextchar[{\gls@gloss@ii}{\gls@gloss@ii[]}}

\def\gls@gloss@ii[#1]{%
    \endgroup
  \gls@gloss@iii{#1}}

\def\gls@gloss@iii#1#2{%
  \begingroup
    \def\gls@a{\def\gls@a{,\penalty\@m\ }}%
    \glso@default
    \glso@word
    \@for\gls@b:=#1\do{%
      \@ifundefined{glso@\gls@b}%
         {\PackageError{gloss}{Unknown option}%
            {You have used an unknown option in \string\gloss}}%
         {\csname glso@\gls@b\endcsname}}%
    \@for\gls@b:=#2\do
      {\gls@a %%% 2001/08/29 Missing
       \edef\gls@b{\expandafter\@firstofone\gls@b\@empty}%
       \ifgls@cite  %%% 2001/12/20 a few lines rewritten
         \@ifundefined{glspp@\gls@name::\gls@b}{\gls@refpagetrue}{}%
       \fi
       \ifgls@refpage
         \protected@write\@auxout{}%
           {\string\gls@page{\gls@name::\gls@b}{\noexpand\thepage}}%
         \global\@namedef{glspp@\gls@name::\gls@b}{}%
       \fi
       \if@filesw
         \immediate\write\csname glsf@\gls@name\endcsname
            {\string\citation{\gls@b}}%
       \fi
       \@ifundefined{gls@\gls@name::\gls@b}%
         {\ifgls@cite
            {\reset@font\bfseries[\gls@unlabel{#2}??]}%
          \fi
          \G@refundefinedtrue
          \PackageWarning{gloss}%
            {Term `\gls@b' on page \thepage\space 
                not defined in glossary `\gls@name'}}%
         {\ifgls@cite
          {\edef\@pdfborder{\glosslinkborder}%
           \edef\@linkcolor{\glosslinkcolor}%
           \edef\@linkbordercolor{\glosslinkbordercolor}%
           \gls@hyperlink{\gls@name::\gls@b}{%
             \expandafter\expandafter\expandafter
               \gls@printtext\csname gls@\gls@name::\gls@b\endcsname}}%
          \fi}}%
  \expandafter
  \endgroup  %2002/07/25 wrong tempswa replaced by gls@cite
  \ifgls@cite\else\expandafter\@esphack\fi}

\def\gls@unlabel#1{%
  \expandafter\expandafter\expandafter
  \@gobble\expandafter\string\csname #1\endcsname}

\AtBeginDocument{%
  \@ifpackageloaded{hyperref}%
    {\let\gls@hyperlink\hyperlink
     \let\gls@raisedlink\Hy@raisedlink}%
    {\let\gls@hyperlink\@secondoftwo
     \let\gls@raisedlink\@gobble
     \let\glosslinkborder\relax
     \let\glosslinkcolor\relax
     \let\glosslinkbordercolor\relax}}

\def\glosslinkborder{\@pdfborder}%
\def\glosslinkcolor{\@linkcolor}%
\def\glosslinkbordercolor{\@linkbordercolor}

% Options:

\newif\ifgls@cite
\gls@citetrue
\def\glso@nocite{%
  \gls@citefalse
  \let\gls@a\@empty}

\newif\ifgls@refpage % false by default
\def\glso@refpage{\gls@refpagetrue}

\newcommand\setglosstext[2]{%
  \@namedef{gls@prtext@#1}##1##2##3{{\def\gls@short{##3}#2}}%
  \@namedef{glso@#1}{%
    \def\gls@printtext{\csname gls@prtext@#1\endcsname}}}

\setglosstext{short}{\ifglossshort*{#3}{}}
\setglosstext{word}{#1}
\setglosstext{Word}{#2}
\setglosstext{long}{#1\ifglossshort*{ (#3)}{}}
\setglosstext{Long}{#2\ifglossshort*{ (#3)}{}}

\def\ifglossshort{%
  \@ifstar
    {\ifx\gls@short\@empty
       \PackageError{gloss}{Empty short}%
          {You cannot print a short form of a term lacking it}%
       {\reset@font\bfseries[??]}%
       \expandafter\@secondoftwo
     \else
       \expandafter\@firstoftwo
     \fi}%
    {\ifx\gls@short\@empty
       \expandafter\@secondoftwo
     \else
       \expandafter\@firstoftwo
     \fi}}

% \newcommand\maingloss[2][word]{\textit{\gloss[refpage,#1]{#2}}}

\newcommand\Gloss[1]{\gloss[Word]{#1}}
\newcommand\onlygloss[1]{\gloss[nocite]{#1}}

% Printing the gloss
% ~~~~~~~~~~~~~~~~~~
% The whole list:

\@ifundefined{chapter}
  {\def\gls@section{%
     \section*{\gls@title}%
     \@mkboth{\MakeUppercase\gls@title}{\MakeUppercase\gls@title}%
     \addcontentsline{toc}{section}{\gls@title}}}%
  {\def\gls@section{%
     \chapter*{\gls@title}%
     \@mkboth{\MakeUppercase\gls@title}{\MakeUppercase\gls@title}%
     \addcontentsline{toc}{chapter}{\gls@title}}}

\newcommand\printgloss[2][default]{%
  \if@filesw
    \csname glso@#1\endcsname
    \immediate\write\csname glsf@\gls@name\endcsname
       {\string\bibdata{#2}}%
  \fi
  \csname glst@#1\endcsname
  \InputIfFileExists{\gls@base.bbl}%
    {}%
    {\typeout{No file \gls@base.bbl}}}

\newenvironment{thegloss}
  {\gls@section
   \def\+##1+{}%
   \@beginparpenalty\@M}%  
  {\stopglosslist}

% Headings:

\newcommand\setglossgroup[1]{\@namedef{gls@group@#1}}
\newcommand\glossgroup[1]{%
  \expandafter\glossheading\csname gls@group@#1\endcsname}

\newcommand\glossheading[1]{%
  \stopglosslist
  \subsection*{#1}}

% The list itself:

\newlength{\glosshang}
\setlength{\glosshang}{2cm}

\newenvironment{glosslist}
  {\begin{list}{\relax}{%
        \def\makelabel##1{##1\hfil}%
        \setlength{\labelsep}{1em}%
        \setlength{\labelwidth}{\glosshang}%
        \addtolength{\labelwidth}{-\labelsep}%
        \setlength{\itemindent}{0em}%
        \setlength{\leftmargin}{\glosshang}}}
  {\end{list}}

% The gloss items:

% 1:key  2:term  3:text  4:shorthand 

\newcommand\stopglosslist{}

\newif\ifgls@list

\newenvironment{glossitem}[4]%
  {\ifgls@list
     \expandafter\let\expandafter\gls@thispage  % relax if undefined
             \csname glsp@\gls@name::#1\endcsname
     \item[%
       \gls@raisedlink{\hyper@anchorstart{\gls@name::#1}\hyper@anchorend}%
       \gls@label{#2}{#3}{#4}]%
     \begingroup
       \let\protect\noexpand
       \immediate\write\@auxout{%
         \string\gls@cite{\gls@name::#1}{#2}{#3}{#4}}%
     \endgroup
   \else
     \xdef\gls@a{\noexpand\begin{\@currenvir}}%
     \endgroup
     \begin{glosslist}%
     \gls@listtrue
     \def\stopglosslist{\end{glosslist}}%
     \gls@a{#1}{#2}{#3}{#4}%
   \fi
   \ignorespaces}
  {.\@@par}

\expandafter\let\csname glossitem*\endcsname\glossitem
\expandafter\let\csname endglossitem*\endcsname\@@par

\newcommand\setglosslabel[1]{%
   \def\gls@label##1##2##3{\def\gls@short{##3}#1}}

\setglosslabel{\sffamily\bfseries#1\ifglossshort{ (#3)}{}}

% Language support

\DeclareOption{basque}{%
  \def\glossname{Glosategi}%
  \def\glosspage#1{, orri \nobreakspace#1.}}%*********
\DeclareOption{brazilian}{%
  \def\glossname{Gloss\'ario}%
  \def\glosspage#1{, p\'ag.\nobreakspace#1.}}
\DeclareOption{catalan}{%
  \def\glossname{Glossari}%
  \def\glosspage#1{, p\`ag.\nobreakspace#1.}}
\DeclareOption{danish}{%
  \def\glossname{Ordliste}%
  \def\glosspage#1{, s.\nobreakspace#1.}}
\DeclareOption{dutch}{%
  \def\glossname{Verklarende woordenlijst}%
  \def\glosspage#1{, p.\nobreakspace#1.}}
\DeclareOption{french}{%
  \def\glossname{Glossaire}%
  \def\glosspage#1{, p.\nobreakspace#1.}}
\DeclareOption{german}{%
  \def\glossname{Glossar}%
  \def\glosspage#1{, S.\nobreakspace#1.}}
\DeclareOption{italian}{%
  \def\glossname{Glossario}%
  \def\glosspage#1{, pag.\nobreakspace#1.}}
\DeclareOption{polish}{%
  \def\glossname{S\l owniczek}%
  \def\glosspage#1{, str.\nobreakspace#1.}}%
\DeclareOption{portuguese}{%
  \def\glossname{Gloss\'ario}%
  \def\glosspage#1{, p\'ag.\nobreakspace#1.}}
\DeclareOption{russian}{%
  \def\glossname{%
     {\cyr\CYRG\cyrl\cyro\cyrs\cyrs\cyra\cyrr\cyri\cyrishrt}}%
  \def\glosspage#1{, {\cyr\cyrs.}\nobreakspace#1.}}
\DeclareOption{spanish}{%
  \def\glossname{Glosario}%
  \def\glosspage#1{, p\'ag.\nobreakspace#1.}}
\DeclareOption{swedish}{%
  \def\glossname{Ordlista}%
  \def\glosspage#1{, s.\nobreakspace#1.}}%*******

\ProcessOptions*

\gls@a  % restores the colon catcode

\endinput