use Text::BibTeX::NameFormat;
$format = Text::BibTeX::NameFormat->($parts, $abbrev_first);
$format->set_text ($part,
$pre_part, $post_part,
$pre_token, $post_token);
$format->set_options ($part, $abbrev, $join_tokens, $join_part
## Uses the encoding/binmode and normalization form stored in $name
$formatted_name = $format->apply ($name);
The ``name format'' is encapsulated in a "Text::BibTeX::NameFormat" object. The constructor ("new") includes some clever behind-the-scenes trickery that means you can usually get away with calling it alone, and not need to do any customization of the format object. If you do need to customize the format, though, the "set_text()" and "set_options()" methods provide that capability.
Note that "Text::BibTeX::NameFormat" is a fairly direct translation of the name-formatting C interface in the btparse library. This manual page is meant to provide enough information to use the Perl class, but for more details and examples, consult bt_format_names.
use Text::BibTeX qw(:nameparts :joinmethods); use Text::BibTeX::Name; use Text::BibTeX::NameFormat;
The ``name part'' constants are used to specify surrounding text or formatting options on a per-part basis: for instance, you can supply the ``pre-token'' text, or the ``abbreviate'' flag, for a single part without affecting other parts. The ``join methods'' are two of the three formatting options that you can set for a part: you can control how to join the individual tokens of a name ("JR Smith", or "J R Smith", or "J~R Smith", and you can control how the final token of one part is joined to the next part ("la Roche" versus "la~Roche").
$format->set_text ('first', undef, undef, undef, '');
would set the post-token text to the empty string, resulting in names like "J R Smith". (Normally, abbreviated first names will have a period after each token: "J. R. Smith".) Note that supplying "undef" for the other three values leaves them unchanged.
See bt_format_names for full information on formatting names.
For example, let's say that just dropping periods from abbreviated tokens in the first name isn't enough; you really want to save space by jamming the abbreviated tokens together: "JR Smith" rather than "J R Smith" Assuming the two calls in the above example have been done, the following will finish the job:
$format->set_options (BTN_FIRST,
1, # keep same value for abbrev flag
BTJ_NOTHING, # jam tokens together
BTJ_SPACE); # space after final token of part
Note that we unfortunately had to know (and supply) the current values for the abbreviation flag and post-part join method, even though we were only setting the intra-part join method.
The first step is covered in Text::BibTeX::Name; here's a brief example:
$orig_name = 'Charles Louis Xavier Joseph de la Vall{\'e}e Poussin';
$name = Text::BibTeX::Name->new($orig_name);
The various parts of the name can now be accessed through "Text::BibTeX::Name" methods; for instance "$name->part('von')" returns the list "("de","la")".
Creating the name format is equally simple:
$format = Text::BibTeX::NameFormat->new('vljf', 1);
creates a format that will print the name in ``von last jr first'' order, with the first name abbreviated. And for no extra charge, you get the right punctuation at the right place: a comma before any `jr' or `first' tokens, and periods after each `first' token.
For instance, we can perform no further customization on this format, and apply it immediately to $name. There are in fact two ways to do this, depending on whether you prefer to think of it in terms of ``Applying the format to a name'' or ``formatting a name''. The first is done with "Text::BibTeX::NameFormat"'s "apply" method:
$formatted_name = $format->apply ($name);
while the second uses "Text::BibTeX::Name"'s "format" method:
$formatted_name = $name->format ($format);
which is just a wrapper around "Text::BibTeX::NameFormat::apply". In either case, the result with the example name and format shown is
de~la Vall{\'e}e~Poussin, C.~L. X.~J.
Note the strategic insertion of TeX ``ties'' (non-breakable spaces) at sensitive spots in the name. (The exact rules for insertion of discretionary ties are given in bt_format_names.)