summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2020-01-05 08:06:00 +0000
committerKatolaZ <katolaz@freaknet.org>2020-01-05 08:06:00 +0000
commit818d316adec9390a35231b44c827a493352a2cdc (patch)
treea6acc98a66c5de58b8a5c9784815c48188088952
parentca63cfbc7cfdc2938d0467150d75b18d02597411 (diff)
add getarxiv to create bibtex entries from arxiv IDs
-rwxr-xr-xgetarxiv48
1 files changed, 48 insertions, 0 deletions
diff --git a/getarxiv b/getarxiv
new file mode 100755
index 0000000..f1c7808
--- /dev/null
+++ b/getarxiv
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# (c) 2020 Vincenzo "KatolaZ" Nicosia <katolaz@freaknet.org>
+#
+# 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 <<EOF
+@misc{${first_auth}$year,
+ title={$title},
+ author={$authors},
+ year={$year},
+ eprint={$doi},
+ primaryClass={$primary},
+ additionalClass={$categories},
+}
+EOF
+
+exit 0