summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-11-27 22:40:18 +0000
committerKarl Berry <karl@freefriends.org>2017-11-27 22:40:18 +0000
commit413f04d6aa934ae22b495949cbc2aa487737abde (patch)
tree847e895ad110ec3fd3d0ff4ba1689b8a4f75e8f6 /Build
parent68269883bdbfd89d17c6e696df91405a5f799cb5 (diff)
crossrefware (27nov17)
git-svn-id: svn://tug.org/texlive/trunk@45927 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/texlive/linked_scripts/Makefile.am1
-rw-r--r--Build/source/texk/texlive/linked_scripts/Makefile.in1
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/crossrefware/bbl2bib.pl45
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/crossrefware/bibdoiadd.pl27
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/crossrefware/biburl2doi.pl136
-rw-r--r--Build/source/texk/texlive/linked_scripts/scripts.lst1
6 files changed, 200 insertions, 11 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am
index 535a94a2021..1d206759013 100644
--- a/Build/source/texk/texlive/linked_scripts/Makefile.am
+++ b/Build/source/texk/texlive/linked_scripts/Makefile.am
@@ -103,6 +103,7 @@ texmf_other_scripts = \
crossrefware/bbl2bib.pl \
crossrefware/bibdoiadd.pl \
crossrefware/bibmradd.pl \
+ crossrefware/biburl2doi.pl \
crossrefware/bibzbladd.pl \
crossrefware/ltx2crossrefxml.pl \
ctan-o-mat/ctan-o-mat.pl \
diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in
index f54f0939482..de51dc23940 100644
--- a/Build/source/texk/texlive/linked_scripts/Makefile.in
+++ b/Build/source/texk/texlive/linked_scripts/Makefile.in
@@ -317,6 +317,7 @@ texmf_other_scripts = \
crossrefware/bbl2bib.pl \
crossrefware/bibdoiadd.pl \
crossrefware/bibmradd.pl \
+ crossrefware/biburl2doi.pl \
crossrefware/bibzbladd.pl \
crossrefware/ltx2crossrefxml.pl \
ctan-o-mat/ctan-o-mat.pl \
diff --git a/Build/source/texk/texlive/linked_scripts/crossrefware/bbl2bib.pl b/Build/source/texk/texlive/linked_scripts/crossrefware/bbl2bib.pl
index 477412d140e..3f66a6f061b 100755
--- a/Build/source/texk/texlive/linked_scripts/crossrefware/bbl2bib.pl
+++ b/Build/source/texk/texlive/linked_scripts/crossrefware/bbl2bib.pl
@@ -8,7 +8,7 @@ bbl2bib.pl - convert thebibliography environment to a bib file
=head1 SYNOPSIS
-bbl2bib.pl [-d] [B<-o> I<output>] I<file>
+bbl2bib.pl [-d] [-u] [B<-o> I<output>] I<file>
=head1 OPTIONS
@@ -24,6 +24,15 @@ Output file. If this option is not used, the name for the
output file is formed by changing the extension to C<.bib>
+=item B<-u>
+
+Do not clean URL fields.
+
+Normally C<bbl2bib> recognizes URL fields of the kind
+C<http://dx.doi.org> and their variants and converts them to DOI
+fields (see also L<biburl2doi(1)> script). The switch B<-u>
+suppresses this cleanup.
+
=back
=head1 DESCRIPTION
@@ -38,6 +47,7 @@ The script reads a TeX or Bbl file and extracts from it the
C<thebibliography> environment. For each bibitem it creates a plain
text bibliography entry, and then tries to match it in
the database.
+
=head1 INPUT FILE
We assume some structure of the input file:
@@ -104,9 +114,9 @@ use LWP::Simple;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
-my $USAGE="USAGE: $0 [-o output] file\n";
+my $USAGE="USAGE: $0 [-d] [-u] [-o output] file\n";
my $VERSION = <<END;
-bbl2bib v2.2
+bbl2bib v2.3
This is free software. You may redistribute copies of it under the
terms of the GNU General Public License
http://www.gnu.org/licenses/gpl.html. There is NO WARRANTY, to the
@@ -114,7 +124,7 @@ extent permitted by law.
$USAGE
END
our %opts;
-getopts('do:hV',\%opts) or die $USAGE;
+getopts('do:huV',\%opts) or die $USAGE;
if ($opts{h} || $opts{V}){
print $VERSION;
@@ -140,6 +150,10 @@ if ($opts{d}) {
$debug=1;
}
+my $cleanUrls = 1;
+if ($opts{u}) {
+ $cleanUrls = 0;
+}
my $input= IO::File->new($inputfile) or
die "Cannot find Bbl or TeX file $inputfile\n$USAGE\n";
@@ -228,6 +242,11 @@ sub ProcessBibitem {
}
$bibitem->{bib} = SearchMref($bibitem);
+
+ if ($cleanUrls) {
+ $bibitem->{bib} = CleanUrl ($bibitem->{bib});
+ }
+
PrintBibitem($bibitem);
return;
}
@@ -258,7 +277,25 @@ sub SearchMref {
}
}
+sub CleanUrl {
+ my $entry = shift;
+ if (!ref($entry)) {
+ return $entry;
+ }
+ if ($entry->has('doi')) {
+ return $entry;
+ }
+ if (!$entry->has('url')) {
+ return $entry;
+ }
+ if ($entry->field('url') =~ m|^http(?:s)?://(?:dx\.)?doi\.org/(.*)$|) {
+ $entry->field('doi', $1);
+ delete $entry->{'url'};
+ }
+ return $entry;
+
+}
sub PrintBibitem {
diff --git a/Build/source/texk/texlive/linked_scripts/crossrefware/bibdoiadd.pl b/Build/source/texk/texlive/linked_scripts/crossrefware/bibdoiadd.pl
index 52eba925283..219896bf404 100755
--- a/Build/source/texk/texlive/linked_scripts/crossrefware/bibdoiadd.pl
+++ b/Build/source/texk/texlive/linked_scripts/crossrefware/bibdoiadd.pl
@@ -8,7 +8,7 @@ bibdoiadd.pl - add DOI numbers to papers in a given bib file
=head1 SYNOPSIS
-bibdoiadd [B<-c> I<config_file>] [B<-e> 1|0] [B<-f>] [B<-o> I<output>] I<bib_file>
+bibdoiadd [B<-c> I<config_file>] [B<-C> 1|0] [B<-e> 1|0] [B<-f>] [B<-o> I<output>] I<bib_file>
=head1 OPTIONS
@@ -19,6 +19,10 @@ bibdoiadd [B<-c> I<config_file>] [B<-e> 1|0] [B<-f>] [B<-o> I<output>] I<bib_fil
Configuration file. If this file is absent, some defaults are used.
See below for its format.
+=item B<-C> 1|0
+
+Whether to canonize names in the output (1) or not (0). By default, 1.
+
=item B<-e>
If 1 (default), add empty doi if a doi cannot be found. This prevents
@@ -39,9 +43,9 @@ output file is formed by adding C<_doi> to the input file
=head1 DESCRIPTION
The script reads a BibTeX file. It checks whether the entries have
-DOIs. If now, tries to contact http://www.crossref.org to get the
+DOIs. If not, it tries to contact http://www.crossref.org to get the
corresponding DOI. The result is a BibTeX file with the fields
-C<doi=...> added.
+C<doi=...> added.
The name of the output file is either set by the B<-o> option or
is derived by adding the suffix C<_doi> to the output file.
@@ -107,7 +111,7 @@ use LWP::Simple;
# Sometimes AMS forgets to update certificates
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
-my $USAGE="USAGE: $0 [-c config] [-e 1|0] [-f] [-o output] file\n";
+my $USAGE="USAGE: $0 [-c config] [-C 1|0] [-e 1|0] [-f] [-o output] file\n";
my $VERSION = <<END;
bibdoiadd v2.2
This is free software. You may redistribute copies of it under the
@@ -117,7 +121,7 @@ extent permitted by law.
$USAGE
END
our %opts;
-getopts('fe:c:o:hV',\%opts) or die $USAGE;
+getopts('fe:c:C:o:hV',\%opts) or die $USAGE;
if ($opts{h} || $opts{V}){
print $VERSION;
@@ -144,6 +148,11 @@ if (exists $opts{e}) {
$forceEmpty = $opts{e};
}
+my $canonizeNames = 1;
+if (exists $opts{C}) {
+ $canonizeNames = $opts{C};
+}
+
our $mode='free';
our $email;
our $username;
@@ -195,7 +204,8 @@ while (my $entry = $parser->next) {
next;
}
- if (!($entry->type() eq 'ARTICLE')) {
+ if (!($entry->type() eq 'ARTICLE') && !($entry->type() eq 'BOOK')
+ && !($entry->type() eq 'INCOLLECTION')) {
print $output $entry->raw_bibtex(), "\n\n";
next;
}
@@ -210,7 +220,10 @@ while (my $entry = $parser->next) {
if (length($doi) || $forceEmpty) {
$entry->field('doi',$doi);
}
- print $output $entry->to_string(), "\n\n";
+
+ print $output
+ $entry->to_string(canonize_names=>$canonizeNames),
+ "\n\n";
}
diff --git a/Build/source/texk/texlive/linked_scripts/crossrefware/biburl2doi.pl b/Build/source/texk/texlive/linked_scripts/crossrefware/biburl2doi.pl
new file mode 100755
index 00000000000..76d1842bf92
--- /dev/null
+++ b/Build/source/texk/texlive/linked_scripts/crossrefware/biburl2doi.pl
@@ -0,0 +1,136 @@
+#!/usr/bin/env perl
+
+=pod
+
+=head1 NAME
+
+biburl2doi.pl - convert URLs pointing to doi.org to DOIs
+
+=head1 SYNOPSIS
+
+biburl2doi [B<-D>] [B<-o> I<output>] I<bib_file>
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-D>
+
+Do not delete URLs converted to DOIs
+
+
+=item B<-o> I<output>
+
+Output file. If this option is not used, the name for the
+output file is formed by adding C<_cleaned> to the input file
+
+=back
+
+=head1 DESCRIPTION
+
+The script recognizes URL fields of the kind
+C<http://dx.doi.org> and their variants and converts them to DOI
+fields.
+
+
+=head1 AUTHOR
+
+Boris Veytsman
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2017 Boris Veytsman
+
+This is free software. You may redistribute copies of it under the
+terms of the GNU General Public License
+L<http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the
+extent permitted by law.
+
+=cut
+
+use strict;
+BEGIN {
+ # find files relative to our installed location within TeX Live
+ chomp(my $TLMaster = `kpsewhich -var-value=SELFAUTOPARENT`); # TL root
+ if (length($TLMaster)) {
+ unshift @INC, "$TLMaster/texmf-dist/scripts/bibtexperllibs";
+ }
+}
+use IO::File;
+use BibTeX::Parser;
+use LaTeX::ToUnicode qw (convert);
+use Getopt::Std;
+
+my $USAGE="USAGE: $0 [-D] [-o output] file\n";
+my $VERSION = <<END;
+biburl2doi 1.0
+This is free software. You may redistribute copies of it under the
+terms of the GNU General Public License
+http://www.gnu.org/licenses/gpl.html. There is NO WARRANTY, to the
+extent permitted by law.
+$USAGE
+END
+our %opts;
+getopts('Do:hV',\%opts) or die $USAGE;
+
+if ($opts{h} || $opts{V}){
+ print $VERSION;
+ exit 0;
+}
+
+################################################################
+# Defaults and parameters
+################################################################
+
+my $inputfile = shift;
+
+my $outputfile = $inputfile;
+
+$outputfile =~ s/\.([^\.]*)$/_cleaned.$1/;
+
+if (exists $opts{o}) {
+ $outputfile = $opts{o};
+}
+
+my $deleteUrl = 1;
+if (exists $opts{D}) {
+ $deleteUrl = 0;
+}
+
+
+my $input= IO::File->new($inputfile) or
+ die "Cannot find BibTeX file $inputfile\n$USAGE\n";
+my $output = IO::File->new("> $outputfile") or
+ die "Cannot write to $outputfile\n$USAGE\n";
+
+my $parser=new BibTeX::Parser($input);
+
+
+
+# Processing the input
+while (my $entry = $parser->next) {
+ if (!$entry->parse_ok()) {
+ print STDERR "Cannot understand entry: ";
+ $entry->print(*STDERR);
+ print STDERR "Skipping this entry\n";
+ next;
+ }
+
+ if ($entry->has('doi') || !$entry->has('url')) {
+ print $output $entry->raw_bibtex(), "\n\n";
+ next;
+ }
+
+ if ($entry->field('url') =~ m|^http(?:s)?://(?:dx\.)?doi\.org/(.*)$|) {
+ $entry->field('doi', $1);
+ if ($deleteUrl) {
+ delete $entry->{'url'};
+ }
+ print $output $entry->to_string(), "\n\n";
+ } else {
+ print $output $entry->raw_bibtex(), "\n\n";
+ }
+}
+
+
+
diff --git a/Build/source/texk/texlive/linked_scripts/scripts.lst b/Build/source/texk/texlive/linked_scripts/scripts.lst
index f500c48d4c1..bf1af0f21e8 100644
--- a/Build/source/texk/texlive/linked_scripts/scripts.lst
+++ b/Build/source/texk/texlive/linked_scripts/scripts.lst
@@ -47,6 +47,7 @@ convbkmk/convbkmk.rb
crossrefware/bbl2bib.pl
crossrefware/bibdoiadd.pl
crossrefware/bibmradd.pl
+crossrefware/biburl2doi.pl
crossrefware/bibzbladd.pl
crossrefware/ltx2crossrefxml.pl
ctan-o-mat/ctan-o-mat.pl