Skip to content

Instantly share code, notes, and snippets.

@tacke758
Created February 3, 2012 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacke758/1728343 to your computer and use it in GitHub Desktop.
Save tacke758/1728343 to your computer and use it in GitHub Desktop.
Generate thesis reference bibitem line
<?php
$line = 'design Design of Evolvable Computer Languages 2002 IEEE TRANSACTIONS ON EVOLUTIONARY COMPUTATION 6 4 420-424 Charles Ofria Christoph Adami Travis C. Collier'; // delimiter is tabstop
print thesis_reference_line($line);
// for each line of file
function thesis_reference_line($line)
{
// split with tab
$datas = explode("\t", $line);
// init variables (or this function'f feature)
$item = $datas[0];
$thesis = $datas[1];
$year = $datas[2];
$magazine = $datas[3];
$vol = $datas[4];
$num = $datas[5];
$page = $datas[6];
$authors = array_slice($datas, 7);
$ref = "";
// add bibitem control
$ref .= '\\bibitem{' . $item . '} ';
// add authors
$authors_except_last = array_slice($authors, 0, count($authors) - 1);
$author_last = $authors[count($authors) - 1];
$ref .= implode(', ', $authors_except_last) . ' and ' . $author_last;
$ref .= ', ';
// add thesis title
$ref .= '``' . $thesis . ',"'; // use tex quote syntax
$ref .= ', ';
// add magazine
$ref .= '\emph{' . $magazine . '}'; // tex italic
// add volume
if ($vol !== "")
{
$ref .= 'Vol. ' . $vol;
$ref .= ', ';
}
// add number
if ($num !== "")
{
$ref .= 'No. ' . $num;
$ref .= ', ';
}
// add page number
if ($page !== "")
{
$ref .= 'pp. ' . $page;
$ref .= ', ';
}
if ($year !== "")
{
$ref .= '(' . $year . ')';
}
$ref .= '.';
$ref .= "\n";
return $ref;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment