Bib  Te  X Language
1 Getting Started
2 Bib  Te  X Structs
bibtexcol
bibtexdb
prepare-bibtexdb
3 Bib  Te  X Query Language
bresult
current-bibtexdb
with-bibtexdb
select
like
8.16

BibTeX Language🔗

Dominik Pantůček <dominik.pantucek@trustica.cz>

A BibTeX language allowing programmatic access to BibTeX files akin to how Scribble documents can be used. The Scribble modules contain the doc submodule and BibTeX modules contain the bib binding.

When #lang bibtex module is being run as the main module, it loads the bibliograhy, sets with-bibtexdb up and starts a REPL allowing the user to interactively query the database.

 (require bibtex) package: bibtex-lang

This module is to be used directly as #lang directive at the top of the BibTeX bibliography file.

It uses bibtex-parse from scriblib/bibtex to parse the file and transforms it into a single Racket module containing a single provided binding bib which is an instance of bibtexdb? struct.

1 Getting Started🔗

Consider the following BibTeX bibliography file named "bibliography.bib" with the #lang bibtex line present:

#lang bibtex
@article{dh76,
  title =  {“New directions in cryptography, IEEE Transactions
                  on Information Theory, vol. IT-22, pp. 644-654},
  author =  {Diffie, W and Hellman, ME},
  year =  {1976},
  abstract =  {Two kinds of contemporary developments in
                  cryptography are examined. Widening applications of
                  teleprocessing have given rise to a need for new
                  types of cryptographic systems, which minimize the
                  need for secure key distribution channels and supply
                  the equivalent of a written signature. This paper
                  suggests ways to solve these currently open
                  problems. It also discusses how the theories of
                  communication and computation are beginning to
                  provide the tools to solve cryptographic problems of
                  long standing.}
}
@article{elgamal85,
  author =  {Elgamal, T.},
  journal =  {IEEE Transactions on Information Theory},
  title =  {A public key cryptosystem and a signature scheme
                  based on discrete logarithms},
  year =  {1985},
  volume =  {31},
  number =  {4},
  pages =  {469-472},
  keywords =  {Ciphers;Public key cryptography;Galois
                  fields;Polynomials;Ions;Digital
                  signatures;Roads;Information
                  systems;Generators;Finite element analysis},
  doi =  {10.1109/TIT.1985.1057074},
  abstract =  {A new signature scheme is proposed, together with an
                  implementation of the Diffie-Hellman key
                  distribution scheme that achieves a public key
                  cryptosystem. The security of both systems relies on
                  the difficulty of computing discrete logarithms over
                  finite fields.}
}
@article{rsa78,
  author =  {Rivest, R. L. and Shamir, A. and Adleman, L.},
  title =  {A method for obtaining digital signatures and
                  public-key cryptosystems},
  year =  {1978},
  issue_date =  {Feb. 1978},
  publisher =  {Association for Computing Machinery},
  address =  {New York, NY, USA},
  volume =  {21},
  number =  {2},
  issn =  {0001-0782},
  url =  {https://doi.org/10.1145/359340.359342},
  doi =  {10.1145/359340.359342},
  abstract =  {An encryption method is presented with the novel
                  property that publicly revealing an encryption key
                  does not thereby reveal the corresponding decryption
                  key. This has two important consequences: (1)
                  Couriers or other secure means are not needed to
                  transmit keys, since a message can be enciphered
                  using an encryption key publicly revealed by the
                  intented recipient. Only he can decipher the
                  message, since only he knows the corresponding
                  decryption key. (2) A message can be “signed” using
                  a privately held decryption key. Anyone can verify
                  this signature using the corresponding publicly
                  revealed encryption key. Signatures cannot be
                  forged, and a signer cannot later deny the validity
                  of his signature. This has obvious applications in
                  “electronic mail” and “electronic funds transfer”
                  systems. A message is encrypted by representing it
                  as a number M, raising M to a publicly specified
                  power e, and then taking the remainder when the
                  result is divided by the publicly specified product,
                  n, of two large secret primer numbers p and
                  q. Decryption is similar; only a different, secret,
                  power d is used, where e * d  1(mod (p - 1) * (q -
                  1)). The security of the system rests in part on the
                  difficulty of factoring the published divisor, n.},
  journal =  {Commun. ACM},
  month =  feb,
  pages =  {120–126},
  numpages =  {7},
  keywords =  {security, public-key cryptosystems, privacy, prime
                  number, message-passing, factorization, electronic
                  mail, electronic funds transfer, digital signatures,
                  cryptography, authentication}
}

This file can be run directly by Racket to get the interactive query environment:

  $ racket bibliography.bib
  > (select id author title)
  ┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  ┃Id       ┃Author                  ┃Title                                                  
  ┣━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
  ┃dh76     │Diffie, W and Hellman,  │“New directions in cryptography, IEEE Transactions on 
           │ME                      │Information Theory, vol. IT-22, pp. 644-654            
  ┠─────────┼────────────────────────┼───────────────────────────────────────────────────────┨
  ┃elgamal85│Elgamal, T.             │A public key cryptosystem and a signature scheme based 
                                   │on discrete logarithms                                 
  ┠─────────┼────────────────────────┼───────────────────────────────────────────────────────┨
  ┃rsa78    │Rivest, R. L. and       │A method for obtaining digital signatures and          
           │Shamir, A. and Adleman, │public-key cryptosystems                               
           │L.                                                                             
  ┗━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  > (select id author title #:where (> year 1980))
  ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  ┃Id       ┃Author   ┃Title                                                                 
  ┣━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
  ┃elgamal85│Elgamal, │A public key cryptosystem and a signature scheme based on discrete    
           │T.       │logarithms                                                            
  ┗━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  > (select id author title #:where (and (like author "diffie") (< year 1980)))
  ┏━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  ┃Id  ┃Author           ┃Title                                                              
  ┣━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
  ┃dh76│Diffie, W and    │“New directions in cryptography, IEEE Transactions on Information 
      │Hellman, ME      │Theory, vol. IT-22, pp. 644-654                                    
  ┗━━━━┷━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

2 BibTeX Structs🔗

 (require bibtex/structs) package: bibtex-lang

struct

(struct bibtexcol (numeric? min-width))

  numeric? : boolean?
  min-width : positive-integer?
As all the attributes are considered across all records of the bibliography, they are treated as columns of a normalized table representing the whole bibliography.

The numeric? field is #t if given attribute across all records is a number?. This information is used for inferring the right procedures for sorting rows.

The min-width field contains the smallest size in characters of the attribute across all rows.

struct

(struct bibtexdb (db cols))

  db : (hash/c symbol? (hash/c symbol? string?))
  cols : (hash/c symbol? bibtexcol?)
Represents the whole BibTeX bibliography as a conveniet struct that can be used for querying the data.

The db field contains the converted hash of hashes with the actual bibliography data.

The cols contains bibtexcol? instance for each column (attribute).

procedure

(prepare-bibtexdb raw)  bibtexdb?

  raw : (hash/c symbol? (hash/c symbol? string?))
Converts the bibdb-raw from bibtex-parse into bibtexdb?.

3 BibTeX Query Language🔗

 (require bibtex/query) package: bibtex-lang

struct

(struct bresult (cols rows src))

  cols : (listof symbol?)
  rows : (listof (hash/c symbol? string?))
  src : bibtexdb?
Represents a select query result.

The cols field holds a list of symbol?s representing the query column names.

The rows field holds a list of hash? representing all the rows of the result.

The src field is a reference to the original bibtexdb? from which the query retrieved the result.

parameter

(current-bibtexdb)  bibtexdb?

(current-bibtexdb bib)  void?
  bib : bibtexdb?
A parameter holding bibtexdb? struct which is used by any select queries.

syntax

(with-bibtexdb bib body ...+)

Parameterizes current-bibtexdb to bib and evaluates all the body expressions returning the result of the last one.

syntax

(select key ...+ maybe-where maybe-order-by)

 
key = identifier?
     
maybe-where = 
  | #:where condition
     
condition = (and condition ...)
  | (or condition ...)
  | (not condition)
  | (comparator key reference)
  | (procedure arg ...)
     
comparator = one of < <= = >= >
     
maybe-order-by = 
  | #:order-by key maybe-desc
     
maybe-desc = 
  | desc
 
  reference : number?
  procedure : (-> symbol? any/c ... (-> (hash/c symbol? string?) boolean?))
Performs a query on current-bibtexdb selecting arbitrary number of attributes (columns, keys) from the entries retrieved. If condition is present, it is used to filter the entries.

syntax

(like key ref ...)

 
  key : identifier?
  ref : string?
Returns a (-> (hash/c symbol? string?) boolean?) suitable for filtering bibliography entries. This predicate returns #t for given entry if any of the ref reference strings is contained (case-insensitive) in the value of the supplied key.