bibtex(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay so bestie, bibtex β€” it parses bibtex files. that's it, that's the whole job, and it does it flawlessly. πŸ’…


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require bibtex ?0.8?

::bibtex::parse ?options? ?text?

::bibtex::parse text

::bibtex::parse ?-command cmd? -channel chan

::bibtex::parse ?-recordcommand recordcmd? ?-preamblecommand preamblecmd? ?-stringcommand stringcmd? ?-commentcommand commentcmd? ?-progresscommand progresscmd? ?-casesensitivestrings bool? (text | -channel chan)

::bibtex::wait token

::bibtex::destroy token

::bibtex::addStrings token stringdict

🌸 DESCRIPTION 🌸

so this package hands you the commands you need to parse bibliographies in BibTeX format. no cap. let's get into each one 🫢

::bibtex::parse ?options? ?text?

this is the general form of the parse command, the main character of the whole page. depending on which options you hit it with, it either gives you back a token for the parser, or the parsed entries of the input bibliography. and if you don't want an immediate parse into some predefined format, it can also slide into an event-based parsing style where every relevant entry in the input gets reported through callback commands β€” very SAX-core, iykyk.

::bibtex::parse text

in this form the command just assumes the text you handed it is a bibliography in BibTeX format, parses it, and returns a list with one element per record found in the bibliography. πŸ“š

⚠️ heads up: comments, string definitions, preambles, etc. will not show up in the result. they're simply not invited to the party.

each element is itself a list containing, in this exact order: record type, bibliography key, and record data. and the record data is a dictionary β€” its keys are the keys of the record, with the associated values. iconic.

::bibtex::parse ?-command cmd? -channel chan

in this form the command reads the bibliography from the Tcl channel chan you specified, and then returns the same data structure as described above. πŸ’«

but πŸ‘€ β€” if the -command option is specified, the result is a handle for the parser instead, and all processing becomes incremental and happens in the background. when the input has been exhausted, the callback cmd gets invoked with the result of the parse. the exact definition for the callback is:

  • cmd token parseresult β€” the parse result will have the structure explained above, for the simpler forms of the parser.
πŸ“Œ note that the parser will not close the channel after it has exhausted it. that is still the responsibility of the user of the parser. bestie, you gotta close your own channels. 😀

::bibtex::parse ?-recordcommand recordcmd? ?-preamblecommand preamblecmd? ?-stringcommand stringcmd? ?-commentcommand commentcmd? ?-progresscommand progresscmd? ?-casesensitivestrings bool? (text | -channel chan)

this right here is the most low-level form of the parser. the returned result is a handle for the parser, and during processing it invokes the callback commands you specified for each type of data found in the bibliography. πŸ”₯

the processing is incremental and happens in the background if, and only if a Tcl channel chan is specified. for a text, the processing happens immediately and all callbacks get invoked before the command itself returns.

the callbacks β€” i.e. *cmd β€” are all command prefixes</> and get invoked with additional arguments appended to them. what those arguments mean depends on the callback, and it's all explained below. one thing that's always true tho: the first argument is always the handle of the parser that's invoking the callback. periodt.

  • -casesensitivestrings β€” this option takes a boolean value. when set, string macro processing becomes case-sensitive. the default is case-insensitive string macro processing.

then the callbacks themselves:

  • recordcmd token type key recorddict β€” this callback fires whenever the parser detects a bibliography record in the input. its arguments are the record type, the bibliography key for the record, and a dictionary containing the keys and values describing the record. any string macros known to the parser have already been expanded. πŸŽ€
  • preamblecmd token preambletext β€” this callback fires whenever the parser detects an @preamble block in the input. the only additional argument is the text found in the preamble block. by default such entries are ignored.
  • stringcmd token stringdict β€” this callback fires whenever the parser detects an @string-based macro definition in the input. the argument is a dictionary with the macro names as keys and their replacement strings as values. by default such definitions are added to the parser state for use in future bibliography records.
  • commentcmd token commenttext β€” this callback fires whenever the parser detects a comment in the input. the only additional argument is the comment text. by default such entries are ignored.
  • progresscmd token percent β€” this callback fires during processing to tell you about the progress that's been made. its argument is the percentage of data processed, as an integer number between 0 and 100. in the case of incremental processing the percentage will always be -1, because the total number of entries isn't known beforehand. 😭

::bibtex::wait token

this command waits for the parser represented by the token to complete, and then returns. the returned result is the empty string. chill. it just vibes until it's done.

::bibtex::destroy token

this command cleans up all internal state associated with the parser represented by the handle token, effectively destroying it. πŸ’€

🫢 fun fact: this one can be called from within the parser callbacks to terminate processing. sneaky. powerful. iconic.

::bibtex::addStrings token stringdict

this command adds the macro definitions stored in the dictionary stringdict to the parser represented by the handle token.

the dictionary keys are the macro names and the values are their replacement strings. and bestie, this command has the correct signature for use as a -stringcommand callback in an invocation of the command ::bibtex::parse. designed for it. πŸ’…


πŸ™ˆ BUGS, IDEAS, FEEDBACK πŸ™ˆ

ngl, this document β€” and the package it describes β€” will undoubtedly contain bugs and other problems. it's giving humble. so please report them in the category bibtex of the Tcllib Trackers: http://core.tcl.tk/tcllib/reportlist. and while you're there, also report any ideas for enhancements you may have for either the package and/or the documentation. we're listening. πŸ‘‘

when proposing code changes, please provide unified diffs, i.e. the output of diff -u.

also note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. yep, that specific button. go get it. 🎯


⭐ KEYWORDS ⭐

bibliography, bibtex, parsing, text processing


πŸ‘‘ CATEGORY πŸ‘‘

Text processing


Copyright (c) 2005 for documentation, Andreas Kupries <andreas_kupries@users.sourceforge.net>


and that's the whole page, bestie πŸ¦‹ this was bibtex(3tcl) from tcllib, version 0.8 β€” thanks for reading, mwah, bye πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from