Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ A Bibtex entry is represented as another dictionary, see the example above. It h
The `parsed_names` entry contains the values of all name-list fields, as parsed by the biblatex crate.
The crate is pretty good at respecting the different ways in which names can be specified in the
original Biblatex.

## Changelog

## unreleased

Bump biblatex to [0.11.0](https://github.com/typst/biblatex/releases/tag/v0.11.0). This should eliminate most _wasm `unreachable` instruction executed_ errors caused by parsing non-ideal BibTeX files.

## 0.2.0

Expose parsed names to Typst.

## 0.1.0

Initial release.
4 changes: 2 additions & 2 deletions examples/main.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/citegeist:0.2.0": load-bibliography
// #import "@local/citegeist:0.1.1": load-bibliography
// #import "@preview/citegeist:0.2.0": load-bibliography
#import "@local/citegeist:0.2.1": load-bibliography

#let bibtex_string = read("custom.bib")
#let bib = load-bibliography(bibtex_string)
Expand Down
29 changes: 11 additions & 18 deletions plugin/citegeist/plugin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions plugin/citegeist/plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "citegeist"
version = "0.1.0"
version = "0.2.1"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-minimal-protocol = { path = "../" }
biblatex = "0.10"
biblatex = "0.11"
serde = "1.0.204"
serde_cbor = "0.10"
serde_derive = "1.0.204"
Expand Down
12 changes: 8 additions & 4 deletions plugin/citegeist/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ struct MyEntry {
parsed_names: BTreeMap<String, Vec<BTreeMap<String,String>>>
}


#[wasm_func]
pub fn get_bib_map(bib_contents_u8: &[u8]) -> Vec<u8> {
let bib_contents = str::from_utf8(bib_contents_u8).unwrap();
let bibliography = Bibliography::parse(bib_contents).unwrap();
pub fn get_bib_map(bib_contents_u8: &[u8]) -> Result<Vec<u8>, String> {
let bib_contents = str::from_utf8(bib_contents_u8)
.map_err(|e| format!("invalid UTF-8 in bibliography: {e}"))?;

let bibliography = Bibliography::parse(bib_contents)
.map_err(|e| format!("failed to parse bibliography: {e}"))?;

let mut ret: BTreeMap<String, MyEntry> = BTreeMap::new();

for entry in bibliography.iter() {
ret.insert(entry.key.clone(), convert_entry(entry));
}

return to_vec(&ret).unwrap();
to_vec(&ret).map_err(|e| format!("failed to serialize result: {e}"))
}


Expand Down
35 changes: 35 additions & 0 deletions tests/basic/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#import "/tests/test-lib.typ": *

// #import "@local/citegeist:0.2.1": *

#let basic-bib = "
@book{knuth1990,
author = {Knuth, Donald E.},
maintitle = {Maintitle},
mainsubtitle = {Sub},
volume = {1},
part = {2},
year = 1990,
publisher = {Addison-Wesley Professional},
title = {The {\TeX} Book},
}


@misc{generalized-2025,
author = {Katharina Stein and Nils Hodel and Michael Katz and Jörg Hoffmann and Alexander Koller},
title = {Improved Generalized Planning with LLMs through Strategy Refinement and Reflection},
year = {2025},
howpublished = {Submitted to AAAI}
}

"


Hello World

#let bib = load-bibliography(basic-bib)

#assert("knuth1990" in bib)
#assert(bib.knuth1990.entry_type == "book")
#assert(bib.knuth1990.fields.title == "The TeX Book")
19 changes: 19 additions & 0 deletions tests/inline-comment/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

// Tests that citegeist can handle inline comments (as per biblatex 0.11.0).

#import "/tests/test-lib.typ": *

#let basic-bib = "
@book{knuth1990,
author = {Knuth, Donald E.},
maintitle = {Maintitle},
mainsubtitle = {Sub},
volume = {1},
part = {2}, % here's an inline comment
year = 1990,
publisher = {Addison-Wesley Professional},
title = {The {\TeX} Book},
}
"

#let bib = load-bibliography(basic-bib)
4 changes: 4 additions & 0 deletions tests/test-lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

// update this line to control what version is being tested
#import "@local/citegeist:0.2.1": *
// #import "@preview/citegeist:0.2.0": *