#!/bin/sh # # (c) 2020 Vincenzo "KatolaZ" Nicosia # # Get a bibtex reference from an arxiv id given as argument # # deps: xml2tsv (https://git.katolaz.net/xml2tsv/) # # Use, modify, and redistribute under the terms of the MIT/X11 License: # # https://directory.fsf.org/wiki/License:X11 # url="http://export.arxiv.org/api/query?id_list=" if [ $# -lt 1 ]; then read -r doi else doi=$1 fi doi=${doi#ar[xX]iv:} res=$(curl -s "${url}${doi}" | xml2tsv) title=$(echo "$res" | grep -E "^/feed/entry/title" | cut -d " " -f 2 | tr '\n' ' ' | sed -r 's/[ \t]*([ \t])/\1/g;s/[ \t]$//g') authors=$(echo "$res" | grep -E "^/feed/entry/author/name" | cut -d " " -f 2 | tr '\n' '|' | sed -r 's/\|$//;s:\|: and :g' ) year=$(echo "$res" | grep -E "^/feed/entry/published" | cut -d " " -f 2 | cut -d "-" -f 1 ) primary=$(echo "$res" | grep -E "^/feed/entry/arxiv:primary_category" | tr "\t" "\n" | grep "^term=" | cut -d "=" -f 2) categories=$(echo "$res" | grep -E "^/feed/entry/category" | tr '\t' '\n' | grep "^term=" | cut -d "=" -f 2 | tr '\n' ',' | sed -r 's/,$//g') first_auth=$(echo "$authors" | sed -r 's/ and /@/' | cut -d "@" -f 1 | awk '{print $NF; }' ) ## if title is empty, the id was most probably wrong, so bail out [ -z "$title" ] && exit 1 cat <