BT_FORMAT_NAMES(1)
π BT_FORMAT_NAMES(1) β a btparse serve π
okay so this is the bt_format_names page from btparse, and it's literally about putting BibTeX names back together so the output stays consistent. iykyk. π
πΈ NAME πΈ
bt_format_names β formatting BibTeX names for consistent output. That's the whole vibe, bestie: split a BibTeX name up, then reassemble it in a way that doesn't look a mess. periodt. β¨
π¦ SYNOPSIS π¦
Here's the function lineup, no cap:
bt_name_format * bt_create_name_format (char * parts,
boolean abbrev_first);
void bt_free_name_format (bt_name_format * format);
void bt_set_format_text (bt_name_format * format,
bt_namepart part,
char * pre_part,
char * post_part,
char * pre_token,
char * post_token);
void bt_set_format_options (bt_name_format * format,
bt_namepart part,
boolean abbrev,
bt_joinmethod join_tokens,
bt_joinmethod join_part);
char * bt_format_name (bt_name * name, bt_name_format * format);
π DESCRIPTION π
After you split a name into its component parts (represented as a bt_name structure), you often want to put it back together again as a single string in a consistent way. btparse provides a very flexible way to do this, generally in two stages: first, you create a "name format" which describes how to put the tokens and parts of any name back together, and then you apply the format to a particular name. π
The "name format" is encapsulated in a bt_name_format structure, which is created with bt_create_name_format(). This function includes some clever trickery that means you can usually get away with calling it alone, and not need to do any customization of the format. If you do need to customize the format, though, bt_set_format_text() and bt_set_format_options() provide that capability. π«Ά
The format controls the following:
- which name parts are printed, and in what order (e.g.
first von last jr, orvon last jr first) - the text that precedes and follows each part (e.g. if the first name follows the last name, you probably want a comma before the
firstpart:Smith, Johnrather thanSmith John) - the text that precedes and follows each token (e.g. if the first name is abbreviated, you may want a period after each token:
J. R. Smithrather thanJ R Smith) - the method used to join the tokens of each part together
- the method used to join each part to the following part
All of these except the list of parts to format are kept in arrays indexed by name part: for example, the structure has a field
char * post_token[BT_MAX_NAMEPARTS]
and post_token[BTN_FIRST] (BTN_FIRST is from the bt_namepart enum) is the string to be added after each token in the first name---for example, "." if the first name is to be abbreviated in the conventional way. π
Yet another enum, bt_joinmethod, describes the available methods for joining tokens together. Note that there are two sets of join methods in a name format: between tokens within a single part, and between the tokens of two different parts. The first allows you, for example, to change J R Smith (first name abbreviated with no post-token text but tokens joined by a space) to JR Smith (the same, but first-name tokens jammed together). The second is mainly used to ensure that von and last name-parts may be joined with a tie: de~Roche rather than de Roche. π
The token join methods are:
BTJ_MAYTIEβ Insert a "discretionary tie" between tokens. That is, either a space or a "tie" is inserted, depending on context. (A "tie," otherwise known as unbreakable space, is currently hard-coded as"~"---from TeX.)BTJ_SPACEβ Always insert a space between tokens.BTJ_FORCETIEβ Always insert a "tie" ("~") between tokens.BTJ_NOTHINGβ Insert nothing between tokens---just jam them together.
The format is then applied to a particular name by bt_format_name(), which returns a new string. π
Tokens are joined together, and thus the choice of whether to insert a "discretionary tie" is made, at two places: within a part and between two parts. Naturally, this only applies when BTJ_MAYTIE was supplied as the token-join method; BTJ_SPACE and BTJ_FORCETIE always insert either a space or tie, and BTJ_NOTHING always adds nothing between tokens. Within a part, ties are added after the first token if it is less than three characters long, and before the last token. Between parts, a tie is added only if the preceding part consisted of single token that was less than three characters long. In all other cases, spaces are inserted.
(This implementation slavishly follows BibTeX.) π§
β¨ FUNCTIONS β¨
π bt_create_name_format()
bt_name_format * bt_create_name_format (char * parts,
boolean abbrev_first)
Okay so this is the icon of the whole page π β it builds you a name format for a given set of parts, plus little variations for the most common customizations: the order of the parts and whether to abbreviate the first name.
The parts parameter says which parts go into a formatted name and the order to format them in. parts has to be a string of four or fewer characters, each one standing for one of the four name parts β so for example "vljf" means format all four parts in "von last jr first" order π₯. No characters outside the set "fvlj" are allowed, and no character may be repeated. And abbrev_first controls whether the first part gets abbreviated (i.e. only the first letter from each token will be printed).
On top of just setting the part list and the "abbreviate" flag for the first name, bt_create_name_format() initializes the entire format structure so you barely have to customize anything else π«Ά:
- The "token join method" β what gets inserted between tokens of the same part β is set to
BTJ_MAYTIE(discretionary tie) for all parts. - The "part join method" β what gets inserted after the final token of a particular part, assuming there are more parts to come β is set to
BTJ_SPACEfor thefirst,last, andjrparts. If thevonpart is present and immediately precedes thelastpart (which is almost always the case),BTJ_MAYTIEis used to joinvontolast; otherwise,vonalso getsBTJ_SPACEfor the inter-part join method. - The abbreviation flag is set to
FALSEfor thevon,last, andjrparts; forfirst, the abbreviation flag is set to whatever you pass in asabbrev_first. - Initially, all "surrounding text" (pre-part, post-part, pre-token, and post-token) for all parts is set to the empty string. Then a few tweaks get done, depending on the
abbrev_firstflag and the order of tokens. First, ifabbrev_firstisTRUE, the post-token text for first name is set to"."β this changes"J R Smith"to"J. R. Smith", which is usually the desired form. (If you don't want the periods, you'll have to set the post-token text yourself withbt_set_format_text().)
Then, if jr is present and immediately after last (almost always the case), the pre-part text for jr is set to ", ", and the inter-part join method for last is set to BTJ_NOTHING. This changes "John Smith Jr" (where the space following "Smith" comes from formatting the last name with a BTJ_SPACE inter-part join method) to "John Smith, Jr" (where the ", " is now associated with "Jr" β that way, if there is no jr part, the ", " will not be printed).
Finally, if first is present and immediately follows either jr or last (which will usually be the case in "last-name first" formats), the same sort of trickery is applied: the pre-part text for first is set to ", ", and the part join method for the preceding part (either jr or last) is set to BTJ_NOTHING.
Ngl, all these rules are pretty complicated π but the whole point is that you're usually freed from having to do any customization of the name format. For sure this is the case if you only need "fvlj" and "vljf" part orders, only want to abbreviate the first name, want periods after abbreviated tokens, non-breaking spaces in the "right" places, and commas in the conventional places β¨
But if you want something out of the ordinary β say, abbreviated tokens jammed together with no punctuation, or abbreviated last names β you'll need to customize the name format a bit with bt_set_format_text() and bt_set_format_options().
π¦ bt_free_name_format()
void bt_free_name_format (bt_name_format * format)
Frees a name format created by bt_create_name_format(). That's it, that's the whole vibe π
πΈ bt_set_format_text()
void bt_set_format_text (bt_name_format * format,
bt_namepart part,
char * pre_part,
char * post_part,
char * pre_token,
char * post_token)
This one lets you customize some or all of the surrounding text for a single name part π Pass NULL for any chunk of text you don't want to change.
So, like, say you want a name format that abbreviates first names but with no punctuation after the abbreviated tokens. You'd create and customize the format like this:
format = bt_create_name_format ("fvlj", TRUE);
bt_set_format_text (format,
BTN_FIRST, /* name-part to customize */
NULL, NULL, /* pre- and post- part text */
NULL, ""); /* empty string for post-token */
Without the bt_set_format_text() call, format would give you names formatted like "J. R. Smith". After setting the post-token text for first names to "", that name becomes "J R Smith" β slay β¨
π bt_set_format_options()
void bt_set_format_options (bt_name_format * format,
bt_namepart part,
boolean abbrev,
bt_joinmethod join_tokens,
bt_joinmethod join_part)
More customization for a name format: you can set the abbreviation flag and the two token-join methods. Alas π there's no mechanism for leaving a value unchanged β you have to set everything with bt_set_format_options().
For example, let's say just dropping periods from abbreviated tokens in the first name isn't enough and you really want to save space by jamming the abbreviated tokens together: "JR Smith" instead of "J R Smith". Assuming the two calls from the example above have been done, the following finishes the job:
bt_set_format_options (format, BTN_FIRST,
TRUE, /* 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 π that's just how it is, bestie.
π₯ bt_format_name()
char * bt_format_name (bt_name * name, bt_name_format * format)
Once a name format has been created and customized to your heart's content, you can use it to format any number of names that have been split with bt_split_name (see bt_split_names). Just pass the name structure and the name format structure, and a newly-allocated string containing the formatted name comes right back to you π«Ά It is your responsibility to free() this string β don't forget, no cap.
π SEE ALSO
btparse, bt_split_names
π AUTHOR
Greg Ward <gward@python.net>
And that's the whole page, bestie β main character energy from start to finish π This was btparse, version 0.91, dated 2025-09-04. Go format some names, you're gonna ate π
β¨
π¦ where this page comes from
- alpine 3.24: perl-text-bibtex-doc 0.91-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms