Skip to content

Commit

Permalink
Add quick bibtex2rs parser
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Nov 29, 2023
1 parent 941d64f commit 63eb191
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 12 deletions.
34 changes: 22 additions & 12 deletions crates/ekore/src/bib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
//! List of references.
//! List of References (autogenerated on 2023-11-29T17:43:08.906032).
/// **[The Three-loop splitting functions in QCD: The Singlet case](https://inspirehep.net/literature/648209)**
/// The Three loop splitting functions in QCD: The Nonsinglet case
///
/// [A. Vogt](https://inspirehep.net/authors/984512) ([NIKHEF, Amsterdam](https://inspirehep.net/institutions/903832)), [S. Moch](https://inspirehep.net/authors/997150) ([DESY, Zeuthen](https://inspirehep.net/institutions/902666)), [J.A.M. Vermaseren](https://inspirehep.net/authors/984767) ([NIKHEF, Amsterdam](https://inspirehep.net/institutions/903832))
/// Moch, S. and Vermaseren, J. A. M. and Vogt, A.
/// Published in: Nucl. Phys. B688 (2004), 101-134
///
/// e-Print: [hep-ph/0404111](https://arxiv.org/abs/hep-ph/0404111) \[hep-ph\]
/// DOI: [10.1016/j.nuclphysb.2004.03.030](https:dx.doi.org/10.1016/j.nuclphysb.2004.03.030)
pub fn Moch2004pa() {}

/// The Three-loop splitting functions in QCD: The Singlet case
///
/// DOI: [10.1016/j.nuclphysb.2004.04.024](https://doi.org/10.1016/j.nuclphysb.2004.04.024)
/// Vogt, A. and Moch, S. and Vermaseren, J. A. M.
/// Published in: Nucl. Phys. B691 (2004), 129-181
///
/// Published in: Nucl.Phys.B 691 (2004), 129-181
/// DOI: [10.1016/j.nuclphysb.2004.04.024](https:dx.doi.org/10.1016/j.nuclphysb.2004.04.024)
pub fn Vogt2004mw() {}

/// **[The Three loop splitting functions in QCD: The Nonsinglet case](https://inspirehep.net/literature/646539)**
/// Programs for computing the logarithm of the gamma function, and the digamma function, for complex argument
///
/// [S. Moch](https://inspirehep.net/authors/997150) ([DESY, Zeuthen](https://inspirehep.net/institutions/902666)), [J.A.M. Vermaseren](https://inspirehep.net/authors/984767) ([NIKHEF, Amsterdam](https://inspirehep.net/institutions/903832)), [A. Vogt](https://inspirehep.net/authors/984512) ([NIKHEF, Amsterdam](https://inspirehep.net/institutions/903832))
/// K.S. Kölbig
/// Published in: Computer Physics Communications 4 (1972), 221 - 226
///
/// e-Print: [hep-ph/0403192](https://arxiv.org/abs/hep-ph/0403192) \[hep-ph\]
/// DOI: [https://doi.org/10.1016/0010-4655(72)90012-4](https://doi.org/10.1016/0010-4655(72)90012-4)
pub fn KOLBIG1972221() {}

/// Multi‐precision Laplace transform inversion
///
/// DOI: [10.1016/j.nuclphysb.2004.03.030](https://doi.org/10.1016/j.nuclphysb.2004.03.030)
/// Abate, J. and Valkó, P.
/// Published in: International Journal for Numerical Methods in Engineering 60 (2004), 979 - 993
///
/// Published in: Nucl.Phys.B 688 (2004), 101-134
pub fn Moch2004pa() {}
/// DOI: [10.1002/nme.995](https:dx.doi.org/10.1002/nme.995)
pub fn Abate() {}
59 changes: 59 additions & 0 deletions crates/make_bib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Parse bibtex file to rust crate."""
import datetime
import pathlib
import re

import bibtexparser

# path to bib file
BIBFILE = "refs.bib"

# A single entry
ENTRY = """/// {title}
///
/// {author}
/// {publication}
/// {eprint}
/// {doi}"""
# Combine publication information
PUB = """Published in: {journal} {volume} ({year}), {pages}"""


def clean_nl(t: str) -> str:
"""Shrink whitespace to one."""
return re.sub("\n\\s+", " ", t)


# collect output
out = "//! List of References (autogenerated on {now}).\n\n".format(
now=datetime.datetime.now().isoformat()
)
# Parse .bib file
bib_str = pathlib.Path(BIBFILE).read_text("utf8")
bib_database = bibtexparser.parse_string(bib_str)
# iterate on all elements
for el in bib_database.entries:
title = re.sub(r"^\{(.+)\}$", r"\1", clean_nl(el.fields_dict["title"].value))
author = el.fields_dict["author"].value
publication = PUB.format(
journal=el.fields_dict["journal"].value,
volume=el.fields_dict["volume"].value,
year=el.fields_dict["year"].value,
pages=el.fields_dict["pages"].value,
)
eprint = ""
if "arxiv" in el.fields_dict:
ar = el.fields_dict["arxiv"].value
eprint = f"e-Print: [{ar}](https://arxiv.org/abs/{ar})"
doi = ""
if "doi" in el.fields_dict:
ddoi = el.fields_dict["doi"].value
url = ddoi if "http" in ddoi else f"https:dx.doi.org/{ddoi}"
doi = f"DOI: [{ddoi}]({url})"
doc = ENTRY.format(
title=title, author=author, publication=publication, eprint=eprint, doi=doi
)
out += doc + "\n" + f"pub fn {el.key} () {{}} \n\n"

# Print to terminal - the user can dump to the relevant file
print(out)

0 comments on commit 63eb191

Please sign in to comment.