BT_MACROS(1)
π
BT_MACROS(1) π
β bestieβs guide to the btparse macro table
Okay so this is the BT_MACROS(1) page from the btparse manual, and weβre gonna make the macro table make sense, fr fr. π«Ά
πΈ NAME πΈ
bt_macros β accessing and manipulating the btparse macro table. Thatβs the whole vibe. π
π¦ SYNOPSIS π¦
void bt_add_macro_value (AST * assignment,
btshort options);
void bt_add_macro_text (char * macro,
char * text,
char * filename,
int line);
void bt_delete_macro (char * macro);
void bt_delete_all_macros (void);
int bt_macro_length (char *macro);
char * bt_macro_text (char * macro,
char * filename,
int line);
π DESCRIPTION π
So btparse keeps one single table of all the macros (a.k.a. abbreviations) it runs into while parsing BibTeX entries. It updates this table every time it encounters a βmacro definitionβ (@string) entry, and it checks this table whenever a macro shows up in an entry and needs to be expanded. π
Quick note, bestie: macros are not necessarily expanded on input, even though thatβs the default. See bt_postprocess for that whole situation. π
Macro definitions are only cleared when btparseβs global cleanup function, bt_cleanup(), is called. So unless you explicitly call bt_delete_macro() or bt_delete_all_macros(), macro definitions persist for as long as you use the library β usually, the lifetime of your process. Periodt. π
π FUNCTIONS π
You can use these functions to add macros, delete them, and query their values β thus interfering with btparseβs normal operation on the fly. We love a little controlled chaos. π
π«Ά bt_add_macro_text() π«Ά
void bt_add_macro_text (char * macro,
char * text,
char * filename,
int line);
Defines a new macro, or redefines an old one. macro is the name of the macro, and text is the text it should expand to. filename and line are just used to generate any warnings about the macro definition; if they donβt apply, specify NULL for filename and 0 for line. β¨
The only such warning happens when you redefine an old macro: its value is overridden, and bt_add_macro_text() issues a warning saying so. So yeah, itβs giving βwe see you, but that old value is gone.β π
For instance, when parsing this macro definition entry:
@string{fubar = "Fouled Up Beyond All Recognition"}
the library (in particular, the post-processing code called after an entry is successfully parsed) will ultimately do this:
bt_add_macro_text ("fubar", "Fouled Up Beyond All Recognition",
filename, line);
This in turn will cause the macro fubar to be expanded appropriately whenever the post-processing code sees it in any future entries. Iconic behavior, no cap. π₯
π§ bt_add_macro_value() π§
void bt_add_macro_value (AST * assignment,
btshort options);
This function is mainly for internal use by the library, but itβs available to you if you ever find yourself with a little bit of AST representing a macro definition, and you want to set the macro yourself (rather than letting the libraryβs post-processing code take care of it for you). Main character energy. π
assignment must be an AST node as returned by bt_next_field(). Unlike most other btparse functions that take an options argument, options here tells how the value in assignment was post-processed. This is needed because macro values have to be processed in a special way to be valid in future expansions; if this one wasnβt processed like that, bt_add_macro_value() will do it for you. If you donβt know how the value was post-processed, just supply 0 for options β thatβs guaranteed to describe something different from βthe right wayβ for macros, so the post-processing will be done correctly. π¦
The processing done to macro values is mainly to ensure that we can get away with storing just a string in the macro table: macros invoked by the macro are themselves expanded, and all sub-strings are concatenated. For instance, if btparse parses these entries:
@string{and = " and "}
@string{jim_n_bob = "James Smith" # and # "Bob Jones"}
then the value stored for jim_n_bob should obviously be the string "James Smith and Bob Jones". To ensure this, btparse has to process the value of and differently from most BibTeX strings: in particular, whitespace is not collapsed before the string is stored. That way, the correct value, " and ", is interpolated into the value of jim_n_bob. Thus, all macro values have sub-macros expanded and strings concatenated before they are stored, but whitespace is not collapsed until the macro is used in a regular entry. Big brain moves only. π§ π
This function calls bt_add_macro_text(), so the same proviso about redefining old macros applies β a warning will be issued, and the old value lost. So, yeah, handle with care. π«Ά
π bt_delete_macro() π
void bt_delete_macro (char * macro);
Deletes a macro from the macro table. If macro isnβt defined, takes no action. Silent, unbothered, moisturized. π§΄
β bt_delete_all_macros() β
void bt_delete_all_macros (void);
Deletes all macros from the macro table. Clean slate, bestie. β¨
π bt_macro_length() π
int bt_macro_length (char *macro);
Returns the length of a macroβs expansion text. If the macro is undefined, returns 0; no warning is issued. Chill. No drama. π
π bt_macro_text() π
char * bt_macro_text (char * macro,
char * filename,
int line);
Returns the expansion text of a macro. If the macro is not defined, issues a warning and returns NULL. filename and line are used for generating this warning; if they donβt apply (i.e. youβre not expanding the macro as a result of finding it in some file), supply NULL for filename and 0 for line. π
π SEE ALSO π
btparse β the whole ecosystem, iykyk. π
πΈ AUTHOR πΈ
Greg Ward <gward@python.net> β author icon. π
This page is from btparse, version 0.91, dated 2025-09-04, and itβs literally called BT_MACROS(1). Stay iconic, bestie. π
πβ¨
π¦ 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