Skip to content

Commit

Permalink
#73 introduce howpublished
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 15, 2024
1 parent afec75b commit f4e4f98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions bibcop.pl
Expand Up @@ -27,6 +27,7 @@ package bibcop;
use warnings;
use strict;
use File::Basename;
use Time::Piece;

# Hash of incoming command line arguments.
my %args = map { $_ => 1 } @ARGV;
Expand All @@ -39,7 +40,7 @@ package bibcop;
'article' => ['doi', 'year', 'title', 'author', 'journal', 'volume', 'number', 'publisher?', 'pages?'],
'inproceedings' => ['doi', 'booktitle', 'title', 'author', 'year', 'pages?', 'organization?', 'volume?'],
'book' => ['title', 'author', 'year', 'publisher', 'doi?'],
'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'publisher?', 'organization?', 'doi?', 'url?', 'howpublished?', 'note?'],
'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'publisher?', 'organization?', 'doi?', 'howpublished?', 'note?'],
);

# See https://research.arizona.edu/faq/what-do-you-mean-when-you-say-use-title-case-proposalproject-titles
Expand Down Expand Up @@ -534,10 +535,16 @@ sub entry_fix {
if ($tag =~ /^:/) {
next;
}
my $value = clean_tex($entry{$tag});
if ($tag eq 'url') {
my $today = localtime->strftime('%d-%m-%Y');
push(@lines, " howpublished = {\\url{$value}},");
push(@lines, " note = {[Online; accessed $today]},");
next;
}
if (not exists $allowed{$tag} and not exists $allowed{$tag . '?'}) {
next;
}
my $value = clean_tex($entry{$tag});
my $fixer = "fix_$tag";
my $fixed = $value;
if (defined &{$fixer}) {
Expand Down
9 changes: 6 additions & 3 deletions perl-tests/entry_fixing.pl
Expand Up @@ -25,13 +25,16 @@ package bibcop;

use strict;
use warnings;
use Time::Piece;

require './bibcop.pl';

fixes({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n");
fixes({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n");
fixes_entry({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n");
fixes_entry({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n");
my $today = localtime->strftime('%d-%m-%Y');
fixes_entry({':name' => 'f', ':type' => 'misc', 'url' => 'http://google.com'}, "\@misc{f,\n howpublished = {\\url{http://google.com}},\n note = {[Online; accessed $today]},\n}\n\n");

sub fixes {
sub fixes_entry {
my ($hash, $expected) = @_;
my %entry = %$hash;
my $after = entry_fix(%entry);
Expand Down

0 comments on commit f4e4f98

Please sign in to comment.