summaryrefslogtreecommitdiff
path: root/biblio/bibtex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-01-13 03:01:12 +0000
committerNorbert Preining <norbert@preining.info>2024-01-13 03:01:12 +0000
commit65fecaf48c4ed6505cb45447a2d7cf1b9d933e3a (patch)
treec56b603d6058668578165093bb5ff98e735e0fe8 /biblio/bibtex
parent1748d1e662c9618cc16f80d5e67669e9e9d6d4be (diff)
CTAN sync 202401130301
Diffstat (limited to 'biblio/bibtex')
-rw-r--r--biblio/bibtex/utils/bibcop/bibcop.12
-rw-r--r--biblio/bibtex/utils/bibcop/bibcop.dtx2
-rw-r--r--biblio/bibtex/utils/bibcop/bibcop.pdfbin348056 -> 348056 bytes
-rwxr-xr-xbiblio/bibtex/utils/bibcop/bibcop.pl98
4 files changed, 62 insertions, 40 deletions
diff --git a/biblio/bibtex/utils/bibcop/bibcop.1 b/biblio/bibtex/utils/bibcop/bibcop.1
index 64b5bd3b69..744ca010c2 100644
--- a/biblio/bibtex/utils/bibcop/bibcop.1
+++ b/biblio/bibtex/utils/bibcop/bibcop.1
@@ -1,4 +1,4 @@
-.TH bibcop 1 "2024-01-11"
+.TH bibcop 1 "2024-01-12"
.SH NAME
bibcop \- Style Checker and Fixer of BibTeX Files (.bib)
.SH SYNOPSIS
diff --git a/biblio/bibtex/utils/bibcop/bibcop.dtx b/biblio/bibtex/utils/bibcop/bibcop.dtx
index 0e078c298a..191279353d 100644
--- a/biblio/bibtex/utils/bibcop/bibcop.dtx
+++ b/biblio/bibtex/utils/bibcop/bibcop.dtx
@@ -50,7 +50,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{bibcop}
%<*package>
-[2024-01-11 0.0.16 Style Checker of Bibliography Files]
+[2024-01-12 0.0.17 Style Checker of Bibliography Files]
%</package>
%<*driver>
\documentclass{ltxdoc}
diff --git a/biblio/bibtex/utils/bibcop/bibcop.pdf b/biblio/bibtex/utils/bibcop/bibcop.pdf
index c81908a5b0..1ea78dc701 100644
--- a/biblio/bibtex/utils/bibcop/bibcop.pdf
+++ b/biblio/bibtex/utils/bibcop/bibcop.pdf
Binary files differ
diff --git a/biblio/bibtex/utils/bibcop/bibcop.pl b/biblio/bibtex/utils/bibcop/bibcop.pl
index 081ac6bbdf..2b44f2d571 100755
--- a/biblio/bibtex/utils/bibcop/bibcop.pl
+++ b/biblio/bibtex/utils/bibcop/bibcop.pl
@@ -21,11 +21,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-# 2024-01-11 0.0.16
+# 2024-01-12 0.0.17
package bibcop;
use warnings;
use strict;
+use File::Basename;
# Hash of incoming command line arguments.
my %args = map { $_ => 1 } @ARGV;
@@ -301,7 +302,7 @@ sub check_typography {
}
}
foreach my $s (@space_before) {
- if ($value =~ /^.*[^\{\s]\Q$s\E.*$/) {
+ if ($value =~ /^.*[^\{\s\\]\Q$s\E.*$/) {
return "In the '$tag', put a space before the $symbols{$s}"
}
}
@@ -513,6 +514,52 @@ sub process_entry {
return @errors;
}
+# Fix one entry.
+sub entry_fix {
+ my (%entry) = @_;
+ if (not exists $entry{':type'}) {
+ error("I don't know what to do with an entry without a type");
+ }
+ my $type = $entry{':type'};
+ if (not exists $blessed{$type}) {
+ error("I don't know what to do with \@$type type of BibTeX entry");
+ }
+ if (not exists $entry{':name'}) {
+ error("I don't know what to do with an entry without a name");
+ }
+ my $tags = $blessed{$type};
+ my %allowed = map { $_ => 1 } @$tags;
+ my @lines;
+ foreach my $tag (keys %entry) {
+ if ($tag =~ /^:/) {
+ 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}) {
+ no strict 'refs';
+ $value = $fixer->($value);
+ }
+ if ($tag =~ /title|booktitle|journal/) {
+ $value = '{' . $value . '}';
+ }
+ if (not $value eq '') {
+ push(@lines, " $tag = {$value},");
+ }
+ }
+ my $fixed = "\@$type\{$entry{':name'},\n";
+ my @sorted = sort @lines;
+ foreach my $line (@sorted) {
+ $fixed = $fixed . $line . "\n";
+ }
+ $fixed = $fixed . "}\n\n";
+ return $fixed;
+}
+
sub fix_author {
my ($value) = @_;
my @authors = split(/\s+and\s+/, $value);
@@ -566,10 +613,15 @@ sub fix_pages {
if ($value =~ /^[1-9][0-9]*$/) {
return $value;
}
+ if ($value eq '') {
+ return $value;
+ }
my ($left, $right) = split(/---|--|-|–|—|\s/, $value);
+ $left //= $right;
if ($left eq '') {
$left = $right;
}
+ $right //= $left;
if ($right eq '') {
$right = $left;
}
@@ -841,6 +893,10 @@ sub fail {
}
}
+if (not basename($0) eq 'bibcop.pl') {
+ return 1;
+}
+
if (@ARGV+0 eq 0 or exists $args{'--help'} or exists $args{'-?'}) {
info("Bibcop is a Style Checker of BibTeX Files\n\n" .
"Usage:\n" .
@@ -861,7 +917,7 @@ if (@ARGV+0 eq 0 or exists $args{'--help'} or exists $args{'-?'}) {
" --latex Report errors in LaTeX format using \\PackageWarningNoLine command\n\n" .
"If any issues, report to GitHub: https://github.com/yegor256/bibcop");
} elsif (exists $args{'--version'} or exists $args{'-v'}) {
- info('0.0.16 2024-01-11');
+ info('0.0.17 2024-01-12');
} else {
my ($file) = grep { not($_ =~ /^-.*$/) } @ARGV;
if (not $file) {
@@ -874,41 +930,7 @@ if (@ARGV+0 eq 0 or exists $args{'--help'} or exists $args{'-?'}) {
my $fixed = '';
for my $i (0..(@entries+0 - 1)) {
my %entry = %{ $entries[$i] };
- my $type = $entry{':type'};
- if (not exists $blessed{$type}) {
- error("I don't know what to do with \@$type type of BibTeX entry");
- }
- if (not exists $entry{':name'}) {
- error("I don't know what to do with an entry without a name");
- }
- my $tags = $blessed{$entry{':type'}};
- my %allowed = map { $_ => 1 } @$tags;
- my @lines;
- foreach my $tag (keys %entry) {
- if ($tag =~ /^:/) {
- 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}) {
- no strict 'refs';
- $value = $fixer->($value);
- }
- if ($tag =~ /title|booktitle|journal/) {
- $value = '{' . $value . '}';
- }
- push(@lines, " $tag = {$value},");
- }
- $fixed = $fixed . "\@$type\{$entry{':name'},\n";
- my @sorted = sort @lines;
- foreach my $line (@sorted) {
- $fixed = $fixed . $line . "\n";
- }
- $fixed = $fixed . "}\n\n";
+ $fixed = $fixed . entry_fix(%entry);
}
if (exists $args{'-i'} or exists $args{'--in-place'}) {
open(my $out, '>', $file) or error('Cannot open file for writing: ' . $file);