diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index a7cc24b..65c38c3 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -500,7 +500,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Foo Bar", $authors[2]); - $this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team and Foo Bar", $entry->getFormattedAuthorsString()); // test with formatting (first name before) bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', true); @@ -509,7 +509,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Team, Advanced Air and Ground Research", $authors[1]); $this->assertEquals("Bar, Foo", $authors[2]); - $this->assertEquals("Meyer, Heribert; Team, Advanced Air and Ground Research; and Bar, Foo", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer, Heribert; Team, Advanced Air and Ground Research and Bar, Foo", $entry->getFormattedAuthorsString()); // test with formatting (with initials) formatAuthorInitials bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); @@ -519,7 +519,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer H", $authors[0]); $this->assertEquals("Team AAand GR", $authors[1]); $this->assertEquals("Bar F", $authors[2]); - $this->assertEquals("Meyer H, Team AAand GR, and Bar F", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer H, Team AAand GR and Bar F", $entry->getFormattedAuthorsString()); // test with first_name last_name formatAuthorCanonical bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); @@ -530,12 +530,14 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Heribert Meyer", $authors[0]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Foo Bar", $authors[2]); - $this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); + $this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team and Foo Bar", $entry->getFormattedAuthorsString()); - // test there is no Oxford comma for only two authors with default options + // test Oxford comma with default options bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); bibtexbrowser_configure('USE_INITIALS_FOR_NAMES', false); bibtexbrowser_configure('USE_FIRST_THEN_LAST', false); + bibtexbrowser_configure('USE_OXFORD_COMMA', true); + $this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); $entry = $db->getEntryByKey('bKey61'); $this->assertEquals("Meyer, Heribert and Foo Bar", $entry->getFormattedAuthorsString()); } diff --git a/bibtexbrowser.php b/bibtexbrowser.php index f5933a4..aacbf76 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -170,7 +170,8 @@ if (defined('ENCODING')) { @define('USE_INITIALS_FOR_NAMES',false); // use only initials for all first names? @define('USE_FIRST_THEN_LAST',false); // put first names before last names? @define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT -@define('LAST_AUTHOR_SEPARATOR',' and '); // if there are more than 2 names, an Oxford comma will be used +@define('LAST_AUTHOR_SEPARATOR',' and '); +@define('USE_OXFORD_COMMA',false); // adds an additional separator in addition to LAST_AUTHOR_SEPARATOR if there are more than two authors @define('TYPES_SIZE',10); // number of entry types per table @define('YEAR_SIZE',20); // number of years per table @@ -1572,9 +1573,9 @@ class BibEntry { } $lastAuthorSeperator = bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'); // add Oxford comma if there are more than 2 authors - if (count($authors)>2) { + if (bibtexbrowser_configuration('USE_OXFORD_COMMA') && count($authors)>2) { $lastAuthorSeperator = $sep.$lastAuthorSeperator; - $lastAuthorSeperator = preg_replace("/ {2,}/", " ", $lastAuthorSeperator); + $lastAuthorSeperator = preg_replace("/ {2,}/", " ", $lastAuthorSeperator); // get rid of double spaces } $result .= $authors[count($authors)-2].$lastAuthorSeperator.$authors[count($authors)-1]; return $result;