maketex.py (8488B)
1 #!/usr/bin/python3 2 # arguments: maketex.py LANGUAGE [FORMAT [PUBLICATION [FOLDER]]] 3 # LANGUAGE is "en" (default) or "fr" 4 # FORMAT is "tex" (default) or "bib" 5 # PUBLICATION is the id of the publication to compile, or: 6 # - "all" for all publications 7 # - "all_formal" for all publications with formal details 8 # - "cv" for all CV publications: all publications that are main, reviewed, not 9 # hidden (default) 10 # FOLDER is where to find "publis" "venues" "authors", default is script dir 11 12 from parserec import parse, getvenue, isurlrel, absurl, getyear, endswithpunct, authorname, stz 13 import os 14 import sys 15 16 SITEURL="https://a3nm.net" 17 LOCALURL=SITEURL+"/publications/" 18 19 # add full acronyms, page numbers 20 formal_mode = False 21 22 if len(sys.argv) > 5: 23 print("too many arguments", file=sys.stderr) 24 sys.exit(1) 25 26 lang = "en" 27 try: 28 lang = sys.argv[1] 29 except IndexError: 30 pass 31 32 fmt = 'tex' 33 try: 34 fmt = sys.argv[2] 35 except IndexError: 36 pass 37 38 thepubli = None 39 try: 40 thepubli = sys.argv[3] 41 except IndexError: 42 pass 43 44 # http://stackoverflow.com/a/1432949 45 abspath = os.path.abspath(__file__) 46 dname = os.path.dirname(abspath) 47 48 folder = dname 49 try: 50 folder = sys.argv[4] 51 except IndexError: 52 pass 53 os.chdir(dname) 54 55 authorsz = dict((x['id'], x) for x in parse('authors')) 56 venuesz = dict((x['id'], x) for x in parse('venues')) 57 58 def mklinktex(text, url, sep=""): 59 global SITEURL, LOCALURL 60 if not url or url.lower() == "none": 61 return (text) 62 url = url.replace("_", "\\_").replace("%", "\%") # naive escaping 63 return ('\\href{%s}%s{%s}' % (absurl(url, SITEURL, LOCALURL), sep, text)) 64 65 def authortotex(author, withurl=False, sepnames=False): 66 if withurl: 67 return mklinktex(authorname(author, sepnames=sepnames), author['url']) 68 else: 69 return authorname(author, sepnames=sepnames) 70 71 def venuetotex(venue, url, issue, dropyear=False): 72 if dropyear and "'" in venue: 73 # cut conf'1942, but beware of ' in titles 74 venue_s = venue.split("'") 75 if len(venue_s) == 2: 76 if venue_s[1].isdigit(): 77 venue = venue_s[0] 78 try: 79 if dropyear and venue[-4:].isdigit() and venue[-5] == ' ': 80 venue = venue[:-5] 81 except IndexError: 82 pass 83 if issue and not dropyear: 84 venue += ', %s' % issue 85 l = mklinktex(venue, url) 86 if ' ' not in venue: 87 return '\\mbox{%s}' % l 88 return l 89 90 def publitotex(publi, lang, venuesz, authorsz): 91 name, fullname, typ, url, issue, oa, keywords = getvenue(publi, lang, venuesz, True) 92 authors = ', '.join(authortotex(authorsz[author], withurl=True) 93 for author in publi['authors'].split(' ')) 94 return("\\cvitem{\\bfseries %s}{%s.\\newline\\emph{%s}%s%s}" % (venuetotex(name, url, 95 issue), authors, mklinktex(publi['title'], publi['url']), "" if 96 endswithpunct(publi) else ".", "\\newline " 97 + (publi['awardtex'] if 'awardtex' in publi.keys() else publi['award']) if 'award' in publi.keys() else '')) 98 99 typetobibtype = { 100 'journal': 'article', 101 'newsletter': 'article', 102 'conference': 'inproceedings', 103 'patent': 'misc', 104 'draft': 'unpublished', 105 'phdthesis': 'phdthesis', 106 'habilitationthesis': 'phdthesis', 107 'mscthesis': 'mastersthesis', 108 'demo': 'inproceedings', 109 'spotlight': 'inproceedings', 110 'posterpaper': 'inproceedings', 111 'shortpaper': 'inproceedings', 112 'note': 'unpublished', 113 'submitted': 'unpublished', 114 } 115 typetoobjtype = { 116 'journal': 'journal', 117 'newsletter': 'journal', 118 'conference': 'booktitle', 119 'demo': 'booktitle', 120 'spotlight': 'booktitle', 121 'posterpaper': 'booktitle', 122 'shortpaper': 'booktitle', 123 'patent': 'howpublished', 124 'draft': 'howpublished', 125 'note': 'howpublished', 126 'submitted': 'note', 127 } 128 legaltypes = ['phdthesis', 'habilitationthesis', 'patent', 'mscthesis', 'journal', 'conference', 129 'note', 'demo', 'posterpaper', 'shortpaper', 'spotlight', 'book', 130 'newsletter', 'draft', 'submitted'] 131 informaltypes = ['phdthesis', 'habilitationthesis', 'mscthesis', 'note', 'book', 'newsletter'] 132 133 def publitobib(publi, lang, venuesz, authorsz): 134 global typetobibtype, typetoobjtype, legaltypes, SITEURL, LOCALURL 135 global informaltypes 136 global stz 137 name, fullname, typ2, url, issue, oa, keywords = getvenue(publi, lang, venuesz) 138 s = "" 139 typ = publi.get('type', None) 140 if typ == None or len(typ) == 0: 141 if typ2 == None or len(typ2) == 0: 142 typ = 'conference' 143 else: 144 typ = typ2 145 assert(typ in legaltypes) 146 if publi.get('status', None) == 'draft': 147 typ = "draft" 148 if publi.get('status', None) == 'submitted': 149 typ = "submitted" 150 knowntype = False 151 for k in keywords: 152 if k.startswith("TYPE"): 153 knowntype = True 154 if k[5:] in informaltypes: 155 keywords.add("informal") 156 if not knowntype: 157 keywords.add("TYPE" + typ) 158 if typ in informaltypes: 159 keywords.add("informal") 160 if 'reviewed' in publi.keys() and publi['reviewed'] == 'yes': 161 keywords.add('peer') 162 if 'status' in publi.keys() and publi['status'] == 'submitted': 163 keywords.add('underreview') 164 if 'venue' in publi.keys(): 165 keywords.add('published') 166 s += '@%s{%s,\n' % (typetobibtype[typ], publi['id']) 167 authors = ' and '.join(authortotex(authorsz[author], sepnames=True) for author in 168 publi['authors'].split(' ')) 169 s += ' author = {%s},\n' % authors 170 s += ' title = {%s},\n' % mklinktex(publi['title'], 171 publi['url'], sep="\n ") 172 s += ' year = {%s},\n' % str(getyear(publi)) 173 did_note = False 174 if typ == "draft": 175 assert (not did_note) 176 did_note = True 177 s += ' note = {Preprint: \\url{%s}},\n' % (absurl(publi['url'], SITEURL, LOCALURL)) 178 elif typ in ["phdthesis", "mscthesis", "habilitationthesis"]: 179 s += ' school = {%s},\n' % (mklinktex(publi['school'], 180 publi['schoolurl'])) 181 else: 182 s += ' %s = {%s},\n' % (typetoobjtype[typ], venuetotex(fullname if formal_mode else name, url, issue, 183 True)) 184 if typ in ["demo", "posterpaper", "shortpaper", "spotlight", "habilitationthesis"]: 185 assert (not did_note) 186 did_note = True 187 s += ' note = {%s},\n' % (stz[typ][lang]) 188 #if 'issue' in publi.keys(): 189 # s += ' number = {%s},\n' % publi['issue'] 190 if formal_mode: 191 for related in ['journalversion', 'conferenceversion']: 192 if related in publi.keys(): 193 assert (not did_note) 194 did_note = True 195 s += (' note = {%s~\cite{%s}},\n' % 196 (stz[related+"_explain"][lang], publi[related])) 197 if 'doi' in publi.keys() and publi['doi'].lower() != 'none': 198 s += ' doi = {%s},\n' % publi['doi'] 199 s += ' keywords = {' + ','.join(sorted(keywords)) + '},\n' 200 if formal_mode: 201 if 'extra' in publi.keys(): 202 s += publi['extra'] 203 s += '}\n\n' 204 return s 205 206 fmtdict = { 207 'tex': publitotex, 208 'bib': publitobib, 209 } 210 211 if thepubli == 'all_formal': 212 formal_mode = True 213 214 if __name__ == '__main__': 215 for publi in parse('publis'): 216 if thepubli not in ["all", "all_formal"]: 217 if thepubli == "cv" or not thepubli: 218 if publi.get('reviewed', "no") == "no": 219 # only reviewed publis 220 continue 221 if publi.get('main', "no") == "no" and not publi.get('addcv', "no") == "yes": 222 # only main publis 223 continue 224 if publi.get('hidecv', "no") == "yes" or publi.get('oldcv', 225 "no") == "yes": 226 # hide some publis: hidecv are the ones I don't want, oldcv 227 # are the ones I'd want except they are too old 228 continue 229 else: 230 # just one publi 231 if thepubli and publi['id'] != thepubli: 232 continue 233 name, fullname, typ2, url, issue, oa, keywords = getvenue(publi, lang, venuesz) 234 if fmt == 'tex' and typ2 == 'journal' and publi.get('issue', "none").lower() == "none": 235 # in latex, no journal articles without an issue number yet 236 continue 237 print(fmtdict[fmt](publi, lang, venuesz, authorsz)) 238 239