Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Octachron/talaria_bibtex
A bibtex file parser
https://github.com/Octachron/talaria_bibtex
bibtex ocaml
Last synced: 3 months ago
JSON representation
A bibtex file parser
- Host: GitHub
- URL: https://github.com/Octachron/talaria_bibtex
- Owner: Octachron
- License: other
- Created: 2015-04-09T14:48:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-11T10:31:18.000Z (9 months ago)
- Last Synced: 2024-05-31T10:41:24.652Z (6 months ago)
- Topics: bibtex, ocaml
- Language: OCaml
- Size: 46.9 KB
- Stars: 21
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
A simple bibtex parser using open records to encode strongly typed bibtex item.
To use this library, first parse a bibtex file using```Ocaml
let dtb = Bibtex.parse @@ Lexing.from_string
"
@article{ Nothingness,
title={On empty articles},
author={Nobody, U. and Nonymous, A.},
year={1995},
pages={0-0}
}
"
```
Bitex items are stored inside a string map using their identifiants
(e.g. "Nothingness" ) as key.
```Ocaml
let item = Bibtex.Database.find "Nothingness" dtb
```Item fields can be accessed using the open record syntax (see [orec](https://github.com/Octachron/orec)). For convenience, the module Bibtex_fields(=Bibtex.Fields) define a `'a named_field` type which combines an access field with a name and a conversion function to string. The list of predefined fields can be found in the `Bibtex_fields` module.
```Ocaml
let () =
let open Bibtex.Fields in
assert ( item.%{year.f} = Some 1995 );
assert( item.%{page.f} = Some ( Interv(0,0) ) );
assert( item.%{title.f} = Some "On empty articles" )```
If needed, more fields can be added to the parser by using a custom [~with_keys] arguments.
First-class fields allow to write generic function like
```Ocaml
let mayp field fmt =
let open Bibtex.Fields in
match item.%{field} with
| None -> ()
| Some x -> Printf.printf fmt xlet () =
let open Bibtex.Fields in
mayp (str kind) "@%s";
mayp uid.f "{%s,\n";
mayp title.f "title={%s},\n";
mayp (str authors) "author={%s},\n";
mayp year.f "year={%d},\n";
mayp (str pages) "pages={%s},\n";
print_string "}\n"```
#Example
```Ocamllet dtb = Bibtex.parse @@ Lexing.from_string
"
@article{ Nothingness,
title={On empty articles},
author={Nobody, U. and Nonymous, A.},
year={1995},
pages={0-0}
}
"let item = Bibtex.Database.find "Nothingness" dtb
let mayp field fmt =
let open Bibtex.Fields in
match item.%{field} with
| None -> ()
| Some x -> Printf.printf fmt xlet () =
let open Bibtex.Fields in
mayp (str kind) "@%s";
mayp uid.f "{%s,\n";
mayp title.f "title={%s},\n";
mayp (str authors) "author={%s},\n";
mayp year.f "year={%d},\n";
mayp (str pages) "pages={%s},\n";
print_string "}\n"```