Skip to content

Commit

Permalink
#28 auto-fix author letters
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 16, 2023
1 parent fb4fd4d commit 85be2eb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 40 deletions.
8 changes: 7 additions & 1 deletion bibcop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,12 @@ sub process_entry {

sub fix_author {
my ($value) = @_;
return $value;
my @authors = split(/\s?and\s?/, $value);
foreach my $author (@authors) {
$author =~ s/^\s+|\s+$//g;
$author =~ s/ ([A-Z])($| )/ \1.\2/g;
}
return join(' and ', @authors);
}

# Parse the incoming .bib file and return an array
Expand Down Expand Up @@ -678,6 +683,7 @@ sub warning {
my $fixer = "fix_$tag";
my $fixed = $value;
if (defined &{$fixer}) {
no strict 'refs';
$value = $fixer->($value);
}
push(@lines, " $tag = {$value},");
Expand Down
4 changes: 4 additions & 0 deletions perl-tests/fixing.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ package bibcop;
use warnings;

fixes('author', 'Knuth, Donald E', 'Knuth, Donald E.');
fixes('author', 'Knuth, Donald E and Duane, Bibby', 'Knuth, Donald E. and Duane, Bibby');
fixes('author', ' Knuth, Donald E and others ', 'Knuth, Donald E. and others');
fixes('author', 'Knuth, Donald E.', 'Knuth, Donald E.');
fixes('author', 'Jerome, K Jerome', 'Jerome, K. Jerome');

sub fixes {
my ($tag, $before, $expected) = @_;
Expand Down
3 changes: 0 additions & 3 deletions testfiles/biblatex.luatex.tlg
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
3 changes: 0 additions & 3 deletions testfiles/biblatex.tlg
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
3 changes: 0 additions & 3 deletions testfiles/biblatex.xetex.tlg
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
14 changes: 4 additions & 10 deletions testfiles/bibtex.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line ....
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
) iexec: The content of 'iexec.tmp' was included into the document
runsystem(rm iexec.tmp)...executed
runsystem(rm iexec.ret)...executed
bibcop: style checking finished
(bibtex.bbl)
(iexec.tmp
! Undefined control sequence.
l. ...\1
better written as $1 at ./bibcop.pl line 443.
14 changes: 4 additions & 10 deletions testfiles/bibtex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line ....
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed.
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
) iexec: The content of 'iexec.tmp' was included into the document
runsystem(rm iexec.tmp)...executed.
runsystem(rm iexec.ret)...executed.
bibcop: style checking finished
(bibtex.bbl)
(iexec.tmp
! Undefined control sequence.
l. ...\1
better written as $1 at ./bibcop.pl line 443.
14 changes: 4 additions & 10 deletions testfiles/bibtex.xetex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line ....
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed.
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
) iexec: The content of 'iexec.tmp' was included into the document
runsystem(rm iexec.tmp)...executed.
runsystem(rm iexec.ret)...executed.
bibcop: style checking finished
(bibtex.bbl)
(iexec.tmp
! Undefined control sequence.
l. ...\1
better written as $1 at ./bibcop.pl line 443.

0 comments on commit 85be2eb

Please sign in to comment.