Repository navigation
Expand file tree
/
Copy pathmake-authorlist.py
More file actions
executable file
·380 lines (329 loc) · 10.9 KB
/
Copy pathmake-authorlist.py
File metadata and controls
executable file
·380 lines (329 loc) · 10.9 KB
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/python3
#
# Makes the XENON Latex authorlist for different journal styles
#
# Patrick Decowski, decowski@nikhef.nl
#
from datetime import datetime
import re
import sys
def print_header():
'''Print the default header at the beginning of the Latex output'''
print('% Autogenerated on ' + datetime.now().strftime("%d %b, %Y at %H:%M:%S"))
print('% Generated with make-authorlist.py')
def format_prl(authorlist, institutes):
'''Format for PRL/PRC/PRD etc. '''
print_header()
print(r'''
% -> SNIP
\documentclass[prl,aps,twocolumn,superscriptaddress,showpacs,showkeys,amsmath,amssymb,floatfix]{revtex4}
\usepackage[colorlinks=true,citecolor=blue,filecolor=blue,linkcolor=blue,urlcolor=blue,pdftex]{hyperref}
\usepackage{currfile} % To be able to list current file name in title
% <- SNIP
''')
for institute in institutes:
inst = '\\newcommand{\\' + institute + r'}{\affiliation{' + institutes[institute] + '}}'
print(inst)
print(r'''
\begin{document}
% CHANGE TO TITLE
\title{XENON Authors \currfilename}
''')
for author in authorlist:
auth = r'\author{' + author['name'] + '}'
if author['alsoat']:
auth = auth + r'\altaffiliation[Also at ]{' + institutes[author['alsoat']] + '}'
for inst in author['institute']:
auth = auth + '\\' + inst
print(auth)
print(r'''
\collaboration{XENON Collaboration}
\email[]{xenon@lngs.infn.it}
\noaffiliation
\date{\today}
% CHANGE
\begin{abstract}
\end{abstract}
\keywords{Dark Matter, Direct Detection, Xenon}
% <--- SNIP
\maketitle
\end{document}
''')
def format_epjc(authorlist, institutes):
'''Format for EPJC'''
print_header()
print("% NOTE!!! For proper formatting you need epjc3upd.clo !")
print(r'''
% -> SNIP
\documentclass[epjc3upd,twocolumn]{svjour3}
\usepackage{currfile} % To be able to list current file name in title
% <- SNIP
\journalname{Eur. Phys. J. C}
\begin{document}
% CHANGE TO TITLE
\title{XENON Authors \currfilename}
''')
addr_label = {}
# for EPJC we need an extra level of indirection for addr labels
for indx, institute in enumerate(institutes):
addr_label[institute] = 'addr' + str(indx)
alsoat = []
sorted_inst = []
first = True
for author in authorlist:
addr = ""
auth = ""
if first:
auth = r'\author{'
first = False
else:
print(r'\and')
for inst in author['institute']:
if addr != "":
addr = addr + "," + addr_label[inst]
else:
addr = addr_label[inst]
if not inst in sorted_inst:
sorted_inst.append(inst)
if author['alsoat']: # We need to build the list of alsoat institutes
addr = addr + "," + addr_label[author['alsoat']]
alsoat.append(author['alsoat'])
auth = auth + author['name'] + r'\thanksref{' + addr + '}'
print(auth)
print(r'(XENON Collaboration\thanksref{email1}). }')
for institute in institutes:
inst = '\\newcommand{\\' + institute + '}{' + institutes[institute] + '}'
print(inst)
print(r'\authorrunning{XENON Collaboration}')
for inst in alsoat:
txt = r'\thankstext{' + addr_label[inst] + '}{Also at \\' + inst + '}'
print(txt)
print(r'''
% ADD Corresponding Author Email here:
\thankstext{email1}{\texttt{xenon@lngs.infn.it}}''')
first = True
alsoat_dict = dict.fromkeys(alsoat, True)
for institute in sorted_inst:
if institute in alsoat_dict: # Skip the AlsoAt institutes
continue
inst = ""
if first:
inst = r'\institute{'
first = False
else:
print(r'\and')
inst = inst + '\\' + institute + r'\label{' + addr_label[institute] + '}'
print(inst)
print(r'''}
\maketitle
\end{document}
''')
def format_jcap(authorlist, institutes):
'''Format for JCAP journal'''
print_header()
print(r'''
% -> SNIP
\documentclass[a4paper]{article}
\usepackage{jcappub}
\usepackage{currfile} % To be able to list current file name in title
% <- SNIP
% CHANGE TO TITLE
\title{XENON Authors \\currfilename}
\author{The XENON collaboration: }''')
inst_label = {}
inst_label_ordered = []
also_label = {}
indx = 0
indx_also = 0
first_auth = True
auth = ''
post = ''
for author in authorlist:
if not first_auth:
auth = auth + ',' + post + '}'
print(auth)
auth = r'\author['
first_inst = True
for inst in author['institute']:
if not first_inst:
auth = auth + ','
if not inst in inst_label:
label = ''
for i in range(0, int(indx/26)):
label = chr(0x61 + i) # ASCII-code 'a'
inst_label[inst] = label + chr(0x61 + (indx % 26))
inst_label_ordered.append(inst) # Order according to use in list
indx = indx + 1
auth = auth + inst_label[inst]
first_inst = False
post = ''
if author['alsoat']:
if not author['alsoat'] in also_label:
also_label[author['alsoat']] = chr(0x31 + indx_also)
auth = auth + ',' + also_label[author['alsoat']]
post = '\\note{Also at: ' + institutes[author['alsoat']] + '}'
indx_also = indx_also + 1
else:
post = ''
auth = auth + r']{' + author['name']
first_auth = False
# Last author is special because list ends with a period and not comma
auth = auth + post + '.}'
print(auth)
# Make the affiliations
for inst in inst_label_ordered:
affil = r'\affiliation[' + inst_label[inst] + ']{' + institutes[inst] + '}'
print(affil)
print(r'''
\keywords{Dark matter experiments, dark matter simulations}
\begin{document}
\maketitle
\end{document}
''')
def format_ptep(authorlist, institutes):
'''Format for PTEP '''
print_header()
print(r'''
% NOTE: there is a nasty bug in the PTEP style file! You need to replace the
% newlogo.eps file with an essentially empty newlogo.png. If you don't the
% formatting of the authorlist becomes crooked.
%
% -> SNIP
\documentclass{ptephy_v1}
\usepackage{currfile} % To be able to list current file name in title
% <- SNIP
''')
print(r'''
\begin{document}
% CHANGE TO TITLE
\title{XENON Authors \currfilename}
''')
inst_label = {}
inst_label_ordered = []
also_label = {}
indx = 1
indx_also = 1
first_auth = True
auth = ''
post = ''
for author in authorlist:
if not first_auth:
auth = auth + post + '}'
print(auth)
auth = r'\author['
first_inst = True
for inst in author['institute']:
if not first_inst:
auth = auth + ','
if not inst in inst_label:
label = str(indx)
inst_label[inst] = label
inst_label_ordered.append(inst) # Order according to use in list
indx = indx + 1
auth = auth + inst_label[inst]
first_inst = False
post = ''
if author['alsoat']:
post = r'\thanks{Also at ' + institutes[author['alsoat']] + '}'
indx_also = indx_also + 1
else:
post = ''
auth = auth + r']{' + author['name']
first_auth = False
# Last author is special because list ends with a period and not comma
auth = auth + post + '}'
print(auth)
# Make the affiliations
for inst in inst_label_ordered:
affil = r'\affil[' + inst_label[inst] + ']{' + institutes[inst] + '}'
print(affil)
print(r'''
\collaborator{XENON Collaboration\email{xenon@lngs.infn.it}}
\date{\today}
% CHANGE
\begin{abstract}
\end{abstract}
% <--- SNIP
\maketitle
\end{document}
''')
def format_arxiv(authorlist, institutes):
'''Format for arXiv - during submission'''
output = ""
first = True
for author in authorlist:
auth = author['name']
auth = auth.replace('~', ' ')
if first:
output = auth
first = False
else:
output = output + ', ' + auth
print(output)
def read_authorlist(filename):
''' Read the XENON author list in the format: author: affil1, affil2 % comment'''
rx = re.compile(r'(?P<name>.*)\:\s*(?P<institute>\S*)\s*?\%?\s*(?P<comment>.*)\n')
rx_inst = re.compile(r'(?P<inst1>\w+)\,?(?P<inst2>\w*)')
rx_also = re.compile(r'.*?(?P<alsoat>alsoat\w*)')
rx_instaddr = re.compile(r'(?P<institute>.*)\s\@\s(?P<address>.*)\n')
authorlist = []
institutes = {}
with open(filename, 'r') as file:
for line in file:
if line[0] == "#":
# Skip comments
continue
match = rx.search(line)
match_institute = rx_instaddr.search(line)
if match:
author = { }
author['name'] = match.group("name")
m = rx_inst.search(match.group("institute"))
a = rx_also.search(match.group("institute"))
institute = [] # Can be multiple institutes
for inst in m.groups():
if (a and inst == a.group("alsoat")) or inst == "":
continue
institute.append(inst)
author['institute'] = institute
if a:
author['alsoat'] = a.group("alsoat")
else:
author['alsoat'] = None
authorlist.append(author)
elif match_institute:
institute = match_institute.group("institute")
address = match_institute.group("address")
institutes[institute] = address
else:
print("Failed on:", line)
sys.exit(1)
return authorlist, institutes
def check_authorlist(authorlist, institutes):
for author in authorlist:
for inst in author['institute']:
if institutes[inst] == None:
print("No institute defined for", author['name'])
if author['alsoat']:
if institutes[author['alsoat']] == None:
print("No institute defined for", author['name'])
def usage():
print("make-authorlist.py --prl | --epjc | --jcap | --ptep | --arxiv filename")
sys.exit(0)
options = { "--prl": format_prl,
"--epjc": format_epjc,
"--jcap": format_jcap,
"--ptep": format_ptep,
"--arxiv": format_arxiv,
"--help": usage }
if __name__ == "__main__":
if len(sys.argv) != 3:
usage()
option = sys.argv[1]
filename = sys.argv[2]
authorlist, institutes = read_authorlist(filename)
check_authorlist(authorlist, institutes)
try:
options[option](authorlist, institutes)
except KeyError:
usage()