-
Notifications
You must be signed in to change notification settings - Fork 8
/
affils.sty
86 lines (78 loc) · 3.02 KB
/
affils.sty
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
% affils.sty -- automatically number affiliations
% Copyright 2016-2018 Peter Williams <[email protected]>
% Licensed under the MIT License.
%
% NOTE: AASTeX versions 6.2 and later provide similar functionality
% automatically; see its documentation
% (https://journals.aas.org/authors/aastex/aasguide.html) for information on
% the new `\affiliation` command.
%
% To use:
%
% 1. Save this file next to your .tex file and add \usepackage{affils} at its top.
%
% 2. Before your author list, write:
%
% \DeclareAffil{nickname}{Full text to appear.}
%
% for each affiliation that might be used. Order doesn't matter. For example,
%
% \DeclareAffil{cfa}{Harvard-Smithsonian Center for Astrophysics,
% 60 Garden Street, Cambridge, Massachusetts 02138, USA}
% \DeclareAffil{nice}{All-Around Nice Fellow}
%
% 3. Instead of the \author command, use a new modified version like so:
%
% \affilauthorlist{
% P.~K.~G. Williams\affils{cfa,nice},
% Your Name Here\affils{nice},
% }
%
% 4. Enjoy! Affiliations will automatically be numbered and be listed in the order
% used in the author list.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{affils}[2016/03/11 v0.1 affils (PKGW)]
\RequirePackage{kvsetkeys}
\newcounter{pkgwaffil@nextnum}
\setcounter{pkgwaffil@nextnum}{1}
\newtoks\pkgwaffil@texts
\pkgwaffil@texts={}
\newcommand\DeclareAffil[2]{\expandafter\newcommand\csname pkgwaffil@#1@text\endcsname{#2}}
\newcommand\affils@process@one[1]{%
\expandafter\ifx\csname pkgwaffil@#1@text\endcsname\relax%
\textbf{[unknown affiliation code #1!]}%
\else%
\expandafter\ifx\csname pkgwaffil@#1@num\endcsname\relax%
% No number assigned -- do so and add to the list to emit
\expandafter\xdef\csname pkgwaffil@#1@num\endcsname{\arabic{pkgwaffil@nextnum}}%
\global\pkgwaffil@texts=\expandafter{\the\pkgwaffil@texts
\altaffiltext{\csname pkgwaffil@#1@num\endcsname}{\csname pkgwaffil@#1@text\endcsname}}%
\stepcounter{pkgwaffil@nextnum}%
\fi
% Add affil's number to the current list.
\ifx\pkgwaffil@cur@numbers\relax
\edef\pkgwaffil@cur@numbers{\csname pkgwaffil@#1@num\endcsname}%
\else
\edef\pkgwaffil@cur@numbers{\pkgwaffil@cur@numbers,\csname pkgwaffil@#1@num\endcsname}%
\fi
\fi%
}
\newcommand\affils[1]{%
\let\pkgwaffil@cur@numbers\relax
\comma@parse{#1}\affils@process@one
\expandafter\altaffilmark\expandafter{\pkgwaffil@cur@numbers}%
}
% The trickiest part is that \author{} is not evaluated right off the bat, so
% \affils@process@one isn't actually called until the first piece of body text
% is encountered, which is too late for us to run the \altaffiltext commands.
% Therefore, we're gross and expand the author text into \@tempboxa, where we
% can evaluate the macros but not actually generate any text.
%
% We could just overwrite the \author command here, but I'm more comfortable
% explicitly giving it a new name.
\newcommand\affilauthorlist[1]{%
\setbox\@tempboxa\vbox{#1}%
\author{#1}%
\edef\pkgwaffil@temp{\the\pkgwaffil@texts}%
\pkgwaffil@temp
}