On Querying Bibliography

Written by Dominik Pantůček on 2026-03-12

racketlatex

Sometimes you are working on a research and you need to manage BibTeX bibliography. However as the number of entries grows it becomes harder to manage. There has to be a better way.


If a language-oriented programmer encounters a problem, they immediately think - I will design a language to solve that problem. And turning a bibliography file into a readline-based program to query the bibliography in question in a SQL-like language sounds like a good way to do exactly that.

We should look at the usage of the final product first:

$ racket bibliography.bib
> (select id title #:where (and (like abstract "crypt") (< year 1990)))
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃Id       ┃Title                                                                        ┃
┣━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃dh76     │New directions in cryptography                                               ┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃merkle88 │A Digital Signature Based on a Conventional Encryption Function              ┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃akl83    │Cryptographic solution to a problem of access control in a hierarchy         ┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃elgamal85│A public key cryptosystem and a signature scheme based on discrete logarithms┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃shamir85 │Identity-Based Cryptosystems and Signature Schemes                           ┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃gudes80  │The Design of a Cryptography Based Secure File System                        ┃
┠─────────┼─────────────────────────────────────────────────────────────────────────────┨
┃rsa78    │A method for obtaining digital signatures and public-key cryptosystems       ┃
┗━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

But how to achieve this behaviour? Of course we will implement a custom #lang for BibTeX files. And with that in place all we need to do is to add the following line at the top of our bibliography.bib file:

#lang bibtex

As the line does not start with @, BibTeX will ignore it - yet it allows us to provide a custom reader for the rest of the file, provide some querying procedures and finally construct a readline-based user interface when the file is run.

Our life is actually even easier as there already is a reader for the raw BibTeX data. The scribblib/bibtex module contains bibtex-parse procedure which performs all the heavy-lifting for us.

For pretty table display the uni-table package contains all the unicode table rendering with styling support. And querying is just a matter of a few filter evaluations.

raco pkg install https://gitlab.com/racketeer/bibtex-lang

All the implementation details can be seen in the source code which is available under the same dual license as most of the Racket ecosystem.

Hope you liked this little show-case of how language-oriented programming can make your life easier and see ya next time if you wanna get some more!