diff --git a/bibcop.pl b/bibcop.pl index 2141a08..f04ec51 100755 --- a/bibcop.pl +++ b/bibcop.pl @@ -39,8 +39,8 @@ package bibcop; my %blessed = ( 'article' => ['doi', 'year', 'title', 'author', 'journal', 'volume', 'number', 'month?', 'publisher?', 'pages?'], 'inproceedings' => ['doi', 'booktitle', 'title', 'author', 'year', 'pages?', 'month?', 'organization?', 'volume?'], - 'incollection' => ['doi', 'booktitle', 'title', 'author', 'year', 'editor', 'pages?', 'month?', 'volume?'], - 'book' => ['title', 'author', 'year', 'publisher', 'doi?'], + 'incollection' => ['doi', 'booktitle', 'title', 'author', 'year', 'editor', 'pages?', 'month?', 'volume?', 'publisher?'], + 'book' => ['title', 'author', 'year', 'publisher', 'doi?', 'edition?'], 'phdthesis' => ['title', 'author', 'year', 'school', 'doi?'], 'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'month?', 'publisher?', 'organization?', 'doi?', 'howpublished?', 'note?'], ); @@ -138,42 +138,45 @@ sub check_capitalization { # Check that the 'author' is formatted correctly. sub check_author { my (%entry) = @_; - if (not exists $entry{'author'}) { - return; - } - if ($entry{'author'} =~ /^\{.+\}$/) { - return; - } - my $author = clean_tex($entry{'author'}); - my @authors = split(/\s+and\s+/, $author); - my $pos = 0; - for my $a (@authors) { - $pos += 1; - if ($a eq 'others') { + my @tags = qw/author editor/; + foreach my $tag (@tags) { + if (not exists $entry{$tag}) { next; } - if (index($a, ' ') != -1 and index($a, ',') == -1) { - return "The last name should go first, all other names must follow, after a comma in @{[as_position($pos)]} 'author', as in 'Knuth, Donald E.'"; + if ($entry{$tag} =~ /^\{.+\}$/) { + next; } - my $npos = 0; - for my $name (split(/[ ,]+/, $a)) { - $npos += 1; - if (index($name, '{') != -1) { - next; - } - if ($name =~ /^[A-Z]\.$/) { + my $author = clean_tex($entry{$tag}); + my @authors = split(/\s+and\s+/, $author); + my $pos = 0; + for my $a (@authors) { + $pos += 1; + if ($a eq 'others') { next; } - if ($name =~ /^[A-Z][^.]+$/) { - next - } - if ($name =~ /^(van|de|der|dos)$/) { - next + if (index($a, ' ') != -1 and index($a, ',') == -1) { + return "The last name should go first, all other names must follow, after a comma in @{[as_position($pos)]} '$tag', as in 'Knuth, Donald E.'"; } - if ($name =~ /^[A-Z]$/) { - return "A shortened name must have a tailing dot in @{[as_position($pos)]} 'author', as in 'Knuth, Donald E.'"; + my $npos = 0; + for my $name (split(/[ ,]+/, $a)) { + $npos += 1; + if (index($name, '{') != -1) { + next; + } + if ($name =~ /^[A-Z]\.$/) { + next; + } + if ($name =~ /^[A-Z][^.]+$/) { + next + } + if ($name =~ /^(van|de|der|dos)$/) { + next + } + if ($name =~ /^[A-Z]$/) { + return "A shortened name must have a tailing dot in @{[as_position($pos)]} '$tag', as in 'Knuth, Donald E.'"; + } + return "In @{[as_position($pos)]} '$tag' @{[as_position($npos)]} name looks suspicious ($name), use something like 'Knuth, Donald E. and Duane, Bibby'"; } - return "In @{[as_position($pos)]} 'author' @{[as_position($npos)]} name looks suspicious ($name), use something like 'Knuth, Donald E. and Duane, Bibby'"; } } } @@ -275,6 +278,7 @@ sub check_org_in_booktitle { sub check_typography { my (%entry) = @_; my %symbols = ( + '...' => 'ellipses', '.' => 'dot', ',' => 'comma', ';' => 'semi-colon', @@ -289,12 +293,12 @@ sub check_typography { '[' => 'opening square bracket', ']' => 'closing square bracket', ); - my @spaces_around = ( '---' ); + my @need_spaces_around = ( '---', '...' ); my @no_spaces_around = ( '--', '-' ); my @no_space_before = ( '.', ',', ';', ':', '?', '!', ')', ']' ); my @no_space_after = ( '(', '[' ); - my @space_before = ( '(', '[' ); - my @space_after = ( ')', ']' ); + my @need_space_before = ( '(', '[' ); + my @need_space_after = ( ')', ']', ',' ); my @good_tails = ( 'Inc.', 'Ltd.' ); my @bad_tails = ( '.', ',', ';', ':', '-' ); foreach my $tag (keys %entry) { @@ -306,7 +310,7 @@ sub check_typography { } my $value = $entry{$tag}; foreach my $s (@bad_tails) { - if ($s eq '.' and $tag eq 'author') { + if ($s eq '.' and ($tag eq 'author' or $tag eq 'editor')) { next; } my $good = 0; @@ -322,7 +326,7 @@ sub check_typography { } } foreach my $s (@no_space_before) { - if ($value =~ /^.*\s\Q$s\E.*$/) { + if ($value =~ /^.*\s\Q$s\E(?!\Q$s\E).*$/) { return "In the '$tag', do not put a space before the $symbols{$s}" } } @@ -331,18 +335,18 @@ sub check_typography { return "In the '$tag', do not put a space after the $symbols{$s}" } } - foreach my $s (@space_before) { + foreach my $s (@need_space_before) { if ($value =~ /^.*[^\{\s\\]\Q$s\E.*$/) { return "In the '$tag', put a space before the $symbols{$s}" } } - foreach my $s (@space_after) { + foreach my $s (@need_space_after) { my $p = join('', @no_space_before); if ($value =~ /^.*[^\\]\Q$s\E[^\}\s\Q$p\E].*$/) { return "In the '$tag', put a space after the $symbols{$s}" } } - foreach my $s (@spaces_around) { + foreach my $s (@need_spaces_around) { if ($value =~ /^.*[^\s]\Q$s\E.*$/ or $value =~ /^.*\Q$s\E[^\s].*$/) { return "In the '$tag', put spaces around the $symbols{$s}" } diff --git a/perl-tests/checking.pl b/perl-tests/checking.pl index f14dbd3..4be14cb 100755 --- a/perl-tests/checking.pl +++ b/perl-tests/checking.pl @@ -62,6 +62,7 @@ package bibcop; 'author' => "Knuth, Donald E. \n and Duane, Bibby", 'title' => '{The TeX Book}', 'year' => '1984', + 'edition' => '1', 'doi' => '10.5555/1102013', 'publisher' => 'Addison-Wesley Professional' )); diff --git a/perl-tests/checks.pl b/perl-tests/checks.pl index f77d546..9cc110c 100755 --- a/perl-tests/checks.pl +++ b/perl-tests/checks.pl @@ -46,10 +46,13 @@ package bibcop; check_fails($f, ('title' => 'A missed space before the bracket(hello)')); check_fails($f, ('title' => 'A missed space after the bracket [hello]you!')); check_fails($f, ('title' => 'A missed space after the bracket (hello)you!')); +check_fails($f, ('title' => 'A missing space after,the comma')); check_fails($f, ('title' => 'No spaces around the---triple dash')); check_fails($f, ('title' => 'Not enough spaces around the--- triple dash')); check_fails($f, ('title' => 'Not enough spaces around the ---triple dash')); check_fails($f, ('title' => 'Spaces around the double -- dash are not allowed')); +check_fails($f, ('title' => 'Either You Love Me, or... Not')); +check_fails($f, ('title' => 'Either You Love Me, or ...Not')); check_passes($f, ('title' => 'Proper space before the {(bracket)}')); check_passes($f, ('title' => '{No spaces after the last in the text closing (bracket)}')); check_passes($f, ('title' => 'No spaces after the last in the text closing (bracket)')); @@ -69,6 +72,7 @@ package bibcop; check_passes($f, ('title' => 'Proper formatting of (brackets); with no space after it')); check_passes($f, ('title' => 'Proper spaces in \(\phi\) and in $\phi$')); check_passes($f, ('publisher' => 'Elsevier Science Inc.')); +check_passes($f, ('title' => 'Either You Love Me, or ... Not')); $f = 'check_wrapping'; check_fails($f, ('title' => 'The title is not surrounded by curled brackets'));