Last active
January 1, 2016 10:39
-
-
Save MartinThoma/8133254 to your computer and use it in GitHub Desktop.
Get BibTeX from Arxiv identifiert.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
error_reporting(E_ALL); | |
/* use the arXiv API: http://arxiv.org/help/api/index */ | |
function startsWith($haystack, $needle) { | |
return $needle === "" || strpos($haystack, $needle) === 0; | |
} | |
function getLastname($name) { | |
$tmp = explode(' ', $name); | |
return end($tmp); | |
} | |
function file_get_contents_curl($url) { | |
// http://stackoverflow.com/a/6595112/562769 | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
function printEntry($entry){ | |
$author = $entry->author->name; | |
$title = trim(preg_replace('/\s\s+/', ' ', $entry->title)); | |
$datePublished = strtotime($entry->published); | |
/* Try to find version. Assume version one in case of no hit. */ | |
$version = 1; | |
preg_match("/[0-9]{4}\.[0-9]{4}v[0-9]+/", $entry->id, $matches); | |
if (count($matches)==1) { | |
$version = substr($entry->id, strlen("http://arxiv.org/abs/1207.0016v")); | |
} | |
/* Print everything*/ | |
?> | |
<pre> | |
@Online{<?echo strtolower(getLastname($author));?>, | |
author = {<? | |
$i=0; | |
foreach($entry->{'author'} as $author ) { | |
if ($i != 0) { | |
echo " AND "; | |
} | |
echo $author->name; | |
$i++; | |
} | |
?>}, | |
title = {<?echo $title;?>}, | |
version = {<?echo $version;?>}, | |
date = {<?echo date('Y-m-d', $datePublished);?>}, | |
eprinttype = {arxiv}, | |
eprintclass = {<? | |
$i=0; | |
foreach($entry->{'category'} as $cat ) { | |
if ($i != 0) { | |
echo ", "; | |
} | |
echo($cat["term"]); | |
$i++; | |
} | |
?>}, | |
eprint = {<?echo $entry->id;?>} | |
} | |
</pre> | |
Link: <a href="<?echo $entry->id;?>"><?echo $entry->title;?></a> | |
<? | |
} | |
/******************************************************************** | |
* Main * | |
*******************************************************************/ | |
if(isset($_GET['id'])) { | |
$id = $_GET['id']; | |
preg_match("/[0-9]{4}\.[0-9]{4}/", $id, $matches); | |
if (count($matches)==1) { | |
$id = $matches[0]; | |
} | |
/* Get archive XML information about paper */ | |
$html = file_get_contents_curl("http://export.arxiv.org/api/query?search_query=".$id."&start=0&max_results=1"); | |
$xml = new SimpleXMLElement($html); | |
$entries = $xml->entry; | |
if ($entries != "") { | |
foreach ($entries as $entry) { | |
printEntry($entry); | |
} | |
} else { | |
echo "arXiv did not find '".$id."'. "; | |
} | |
} else { | |
$id = "http://arxiv.org/abs/1112.4344"; | |
} | |
?> | |
<hr/> | |
Please enter <a href="http://arxiv.org/">arXiv</a> id or full URL: | |
<form method="GET"> | |
<input type="text" name="id" id="id" value="<?echo $id;?>" style="width:80%"/> | |
<input type="submit" /> | |
</form> | |
<h2>More BibTex-Information</h2> | |
<ul> | |
<li><a href="http://texblog.org/2007/08/09/how-to-use-a-bibtex-file/">How to use Bibtex as a reference library for Latex</a></li> | |
<li><a href="http://www.bibtex.org/Using/de/">Wie benutzt man BibTeX mit LaTeX</a></li> | |
<li><a href="http://manas.tungare.name/software/isbn-to-bibtex/">ISBN to BibTeX</a></li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment