summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/bibtexperllibs
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-12-11 22:25:02 +0000
committerKarl Berry <karl@freefriends.org>2017-12-11 22:25:02 +0000
commitadac48cfc4efd9fdcdec5c8780fcd8a8fbcaa504 (patch)
treed842b3ef9bf86b120462a78cbce0a3c7b8928a21 /Master/texmf-dist/scripts/bibtexperllibs
parent918bc7fc37eb2f4bd0900ec334625ed8f1b1752b (diff)
bibtexperllibs (10dec17)
git-svn-id: svn://tug.org/texlive/trunk@46044 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/bibtexperllibs')
-rw-r--r--Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser.pm14
-rw-r--r--Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm4
-rw-r--r--Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Entry.pm75
3 files changed, 79 insertions, 14 deletions
diff --git a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser.pm b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser.pm
index 3439d274139..27cb9145829 100644
--- a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser.pm
+++ b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser.pm
@@ -1,6 +1,6 @@
package BibTeX::Parser;
{
- $BibTeX::Parser::VERSION = '1.00';
+ $BibTeX::Parser::VERSION = '1.01';
}
# ABSTRACT: A pure perl BibTeX parser
use warnings;
@@ -73,6 +73,14 @@ sub _parse_next {
pos($_) = $position;
}
+ # Remember text before the entry
+ my $pre = substr($_, 0, $start_pos-1);
+ if ($start_pos == 0) {
+ $pre = '';
+ }
+ $current_entry->pre($pre);
+
+
# Remember raw bibtex code
my $raw = substr($_, $start_pos);
$raw =~ s/^\s+//;
@@ -141,7 +149,7 @@ sub next {
return $self->_parse_next;
}
-# slurp everything till the next closing brace. Handels
+# slurp everything till the next closing brace. Handles
# nested brackets
sub _slurp_close_bracket {
my $bracelevel = 0;
@@ -337,7 +345,7 @@ L<BibTeX::Parser::Author>
=head1 VERSION
-version 1.00
+version 1.01
=head1 AUTHOR
diff --git a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm
index 181de2ed775..a0ffb455be4 100644
--- a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm
+++ b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm
@@ -1,6 +1,6 @@
package BibTeX::Parser::Author;
{
- $BibTeX::Parser::Author::VERSION = '1.00';
+ $BibTeX::Parser::Author::VERSION = '1.01';
}
use warnings;
@@ -393,7 +393,7 @@ the following token is not: C<{von}>
=head1 VERSION
-version 1.00
+version 1.01
=head1 AUTHOR
diff --git a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Entry.pm b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Entry.pm
index af3d32f5e5a..6d3b0ec81a8 100644
--- a/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Entry.pm
+++ b/Master/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Entry.pm
@@ -1,6 +1,6 @@
package BibTeX::Parser::Entry;
{
- $BibTeX::Parser::Entry::VERSION = '1.00';
+ $BibTeX::Parser::Entry::VERSION = '1.01';
}
use warnings;
@@ -216,17 +216,39 @@ sub raw_bibtex {
return $self->{_raw};
}
+sub pre {
+ my $self = shift;
+ if (@_) {
+ $self->{_pre} = shift;
+ }
+ return $self->{_pre};
+}
+
+
sub to_string {
my $self = shift;
my %options=@_;
if (!exists($options{canonize_names})) {
$options{canonize_names}=1;
}
- my @fields = grep {!/^_/} keys %$self;
+ my @fields = grep {!/^_/} keys %$self;
@fields = sort {
$self->{_fieldnums}->{$a} <=>
$self->{_fieldnums}->{$b}} @fields;
- my $result = '@'.$self->type."{".$self->key.",\n";
+ my $result = '';
+ if ($options{print_pre}) {
+ $result .= $self->pre()."\n";
+ }
+ my $type = $self->type;
+ if (exists($options{type_capitalization})) {
+ if ($options{type_capitalization} eq 'Lowercase') {
+ $type = lc $type;
+ }
+ if ($options{type_capitalization} eq 'Titlecase') {
+ $type = ucfirst lc $type;
+ }
+ }
+ $result .= '@'.$type."{".$self->key.",\n";
foreach my $field (@fields) {
my $value = $self->field($field);
if ($field eq 'author' && $options{canonize_names}) {
@@ -237,7 +259,15 @@ sub to_string {
my @names = ($self->editor);
$value = join(' and ', @names);
}
- $result .= " $field = {"."$value"."},\n";
+ if (exists($options{field_capitalization})) {
+ if ($options{field_capitalization} eq 'Uppercase') {
+ $field = uc $field;
+ }
+ if ($options{field_capitalization} eq 'Titlecase') {
+ $field = ucfirst $field;
+ }
+ }
+ $result .= " $field = {"."$value"."},\n";
}
$result .= "}";
return $result;
@@ -343,22 +373,49 @@ Returns a list of all the fields used in this entry.
Returns a true value if this entry has a value for $fieldname.
+=head2 pre ()
+
+Return the text in BibTeX file before the entry
+
=head2 raw_bibtex ()
Return raw BibTeX entry (if available).
=head2 to_string ([options])
-Returns a text of the BibTeX entry in BibTeX format. Options is
-a hash. Currently only the option C<canonize_names>
-is supported. If true (the default), authors' and editors'
+Returns a text of the BibTeX entry in BibTeX format. Options are
+a hash.
+
+=over 4
+
+=item C<canonize_names>
+
+If true (the default), authors' and editors'
names are translated into canonical bibtex form. The command
C<$entry-E<gt>to_string(canonize_names=E<gt>0)> overrides this behavior.
-=head1 VERSION
+=item C<field_capitalization>
+
+Capitalization of the field names.
+Can take values 'Uppercase', 'Lowercase' (the default) or 'Titlecase'
+
+=item C<print_pre>
-version 1.00
+False by default. If true, the text in the Bib file before the
+entry is printed. Note that at present we assume the text
+before the entry NEVER has the @ symbol inside
+
+=item C<type_capitalization>
+
+Capitalization of the type names.
+Can take values 'Uppercase' (the default), 'Lowercase' or 'Titlecase'
+
+
+=back
+
+=head1 VERSION
+version 1.01
=head1 AUTHOR