Surveying the Universe
Generating LaTeX authors lists for MNRAS and A&A
Okay, a bit boring, but as promised, here are some Python functions to generate LaTeX source for long authors lists for MNRAS and A&A.
First, a small utility:
def getSortedInstituteCodes(authorList, authorInstituteCodes): """Return a list of institute codes, in the correct order for authorList. authorList = ["J.~Bloggs", "A.N.~Other"] authorInstituteCodes = {"J.~Bloggs":1, "A.N.~Other":[1,"Sussex"]} """ instituteCodes = [] for author in authorList: codes = authorInstituteCodes[author] if not hasattr(codes, '__iter__'): codes = [codes] for code in codes: if not code in instituteCodes: instituteCodes.append(code) return instituteCodes
then the function for MNRAS:
def getAuthorsStringMNRAS(authorList, authorInstituteCodes, institutesTex, authorEmails): """Return a string containing LaTeX for MNRAS authors list. authorList = ["J.~Bloggs", "A.N.~Other"] authorInstituteCodes = {"J.~Bloggs":1, "A.N.~Other":[1,"Sussex"]} institutesTex = {1:"Somewhere, Earth", "Sussex":"University of Sussex"} authorEmails = {"J.~Bloggs": "j.bloggs@no.where"} """ instituteCodes = getSortedInstituteCodes(authorList, authorInstituteCodes) # Make a list of strings: # "Author Name$^{1,2}$\thanks{E-mail: \texttt{j.bloggs@no.where}}" authorInstituteList = [] for author in authorList: try: codes = authorInstituteCodes[author] if not hasattr(codes, '__iter__'): codes = [codes] # Only one institute code for this author authorInstituteList.append( author + ',$^{' + ','.join([str(instituteCodes.index(code) + 1) for code in codes]) + '}$') except KeyError: authorInstituteList.append(author + ',') try: email = authorEmails[author] authorInstituteList[-1] += '\\thanks{E-mail: \\texttt{' authorInstituteList[-1] += email + '}}' except KeyError: pass # No email address for this author # Sort out the punctuation (won't work if the penultimate or ultimate # author has no institute) authorInstituteList[-2] = authorInstituteList[-2].replace(',$', '$') authorInstituteList[-2] += ' and' authorInstituteList[-1] = authorInstituteList[-1].replace(',$', '$') # Put it all together authorsString = '\\author[' + authorList[0] + ' et al.]' authorsString += '\n{\\parbox{\\textwidth}{' authorsString += '\n'.join(authorInstituteList) authorsString += '}\\vspace{0.4cm}\\\\\n' authorsString += '\\parbox{\\textwidth}{' authorsString += '\\\\\n'.join(['$^{' + str(iInst + 1) + '}$' + institutesTex[instituteCodes[iInst]] for iInst in range(len(instituteCodes))]) authorsString += '}}\n' return authorsString
and the function for A&A:
def getAuthorsStringAA(authorList, authorInstituteCodes, institutesTex, authorEmails): """Return a string containing LaTeX for A&A authors list. authorList = ["J.~Bloggs", "A.N.~Other"] authorInstituteCodes = {"J.~Bloggs":1, "A.N.~Other":[1,"Sussex"]} institutesTex = {1:"Somewhere, Earth", "Sussex":"University of Sussex"} authorEmails = {"J.~Bloggs": "j.bloggs@no.where"} """ instituteCodes = getSortedInstituteCodes(authorList, authorInstituteCodes) # Associate institute numbers with authors and emails with institutes authorInstituteList = [] # A list of "Author Name\inst{1,2}" strings instituteEmails = {} # A dictionary of email addresses for each institute for author in authorList: try: codes = authorInstituteCodes[author] if not hasattr(codes, '__iter__'): codes = [codes] # Only one institute code for this author authorInstituteList.append( author + '\inst{' + ','.join([str(instituteCodes.index(code) + 1) for code in codes]) + '}') try: email = authorEmails[author] try: instituteEmails[codes[0]].append(email) except KeyError: # First email address for this institute instituteEmails[codes[0]] = [email] except KeyError: pass # No email address associated with author except KeyError: authorInstituteList.append(author) # Create a list of "Institute Name, Address\\ # \email{j.bloggs@no.where}" strings instituteEmailList = [] for instituteCode in instituteCodes: try: emails = instituteEmails[instituteCode] instituteEmailList.append( institutesTex[instituteCode] + ''.join(['\\\\\n\email{' + email + '}' for email in emails])) except KeyError: instituteEmailList.append(institutesTex[instituteCode]) # Put it all together authorsString = '\\author{' authorsString += '\n\\and '.join(authorInstituteList) authorsString += '}\n' authorsString += '\\institute{' authorsString += '\n\\and '.join(instituteEmailList) authorsString += '}\n' return authorsString
Anyone still reading?
| Print article | This entry was posted by Anthony on 3 Jun 2010 at 10.38 am, and is filed under Computing. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
I live in York and I'm a research fellow in
about 1 year ago
Anyone still reading?
Yes! I'm. Thanks for the scripts. Very useful.
about 1 year ago
Splendid - thanks!
about 1 year ago
fancy!:-)
you should get in touch with the editors, although they may not be willing to host this on the journal's web sites. other large collaborations such as hatlas and higal (and planck, of course) may be more appreciative...
ps ; now you need to hack apj and a&a and u r almost done!;-)
about 1 year ago
It's fairly easy to adapt the script to other formats. Not sure it's quite user-friendly enough for the journal websites, as you first need to generate the variables in the correct format (I have another script that does that using a spreadsheet of HerMES authors).
about 1 year ago
Don't you just do it roughly and then get your graduate student to carefully check and adjust each one.
about 1 year ago
Depends - the alternative is to ask your postdoc to take care of it for the whole consortium