aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bib2ref.awk
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2026-06-06 12:02:41 -0400
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2026-06-06 12:02:41 -0400
commiteabf1f6d74dac497ce31e3e2f441cfa25e9f74f2 (patch)
tree626d64c3574cfbc7cc38eae6d142ef22b21cf59b /lib/bib2ref.awk
parent8351a1da3f56cde9939b934bc5533a95aff1c95e (diff)
downloadbibutils-eabf1f6d74dac497ce31e3e2f441cfa25e9f74f2.tar.gz
Initial implementation (only a few years later!)
This is pure Claude. I'd written out the plan for this suite of scripts eons ago, but never found the time to actual do it. Remembered it this morning, pointed Claude at the README, and had something that appears to work in minutes. caveat emptor: the design is mine, but the code is purely LLM generated at this point.
Diffstat (limited to 'lib/bib2ref.awk')
-rw-r--r--lib/bib2ref.awk52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/bib2ref.awk b/lib/bib2ref.awk
new file mode 100644
index 0000000..4d9e595
--- /dev/null
+++ b/lib/bib2ref.awk
@@ -0,0 +1,52 @@
+# bib2ref.awk - convert bibtex entries to refer records
+#
+# Requires bib-parse.awk and bib-canon.awk.
+
+function bib_pass(raw) { }
+
+function r_field(tag, v) {
+ if (v != "") {
+ gsub(/[{}]/, "", v)
+ gsub(/[ \t\r\n]+/, " ", v)
+ printf "%%%s %s\n", tag, bib_trim(v)
+ }
+}
+
+function r_names(tag, v, n, parts, i) {
+ gsub(/[{}]/, "", v)
+ gsub(/[ \t\r\n]+/, " ", v)
+ n = split(v, parts, / +[Aa][Nn][Dd] +/)
+ for (i = 1; i <= n; i++)
+ if (bib_trim(parts[i]) != "")
+ printf "%%%s %s\n", tag, bib_trim(parts[i])
+}
+
+function bib_entry(type, key, d, p, m) {
+ if (bib_out_n++)
+ print ""
+ r_names("A", bib_get("author"))
+ r_names("E", bib_get("editor"))
+ r_field("T", bib_get("title"))
+ r_field("J", bib_get("journal"))
+ r_field("B", bib_get("booktitle"))
+ d = bib_get("year")
+ m = bib_get("month")
+ if (m != "")
+ d = (d != "") ? m " " d : m
+ r_field("D", d)
+ r_field("V", bib_get("volume"))
+ r_field("N", bib_get("number"))
+ p = bib_get("pages")
+ gsub(/--/, "-", p)
+ r_field("P", p)
+ if (bib_get("publisher") != "")
+ r_field("I", bib_get("publisher"))
+ else if (bib_get("institution") != "")
+ r_field("I", bib_get("institution"))
+ else if (bib_get("school") != "")
+ r_field("I", bib_get("school"))
+ r_field("C", bib_get("address"))
+ r_field("K", bib_get("keywords"))
+ r_field("X", bib_get("abstract"))
+ r_field("O", bib_get("note"))
+}