From 3f804f7378da9233d7af441a71e62400b7fb48d9 Mon Sep 17 00:00:00 2001 From: slashformotion Date: Fri, 26 Jan 2024 23:51:16 +0100 Subject: [PATCH] add parameter disable-back-references fixes #13 --- example/example.typ | 4 +++- glossarium.typ | 45 +++++++++++++++++++++++---------------------- makefile | 13 +++++++++---- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/example/example.typ b/example/example.typ index 02cbd84..f0e0ee6 100644 --- a/example/example.typ +++ b/example/example.typ @@ -80,5 +80,7 @@ At the moment, customization is not built-in to the function and instead follows ), ), // show all term even if they are not referenced, default to true - show-all: true + show-all: true, + // disable the back ref at the end of the descriptions + disable-back-references: true, ) diff --git a/glossarium.typ b/glossarium.typ index 3d3b080..ed50d06 100644 --- a/glossarium.typ +++ b/glossarium.typ @@ -71,7 +71,7 @@ SOFTWARE.*/ body } -#let print-glossary(entries, show-all: false) = { +#let print-glossary(entries, show-all: false, disable-back-references: false) = { __glossary_entries.update( (x) => { for entry in entries { @@ -105,7 +105,7 @@ SOFTWARE.*/ locate( loc => { let term_references = __query_labels_with_key(loc, entry.key) - if term_references.len() != 0 or show-all { + if term_references.len() != 0 or show-all { let desc = entry.at("desc", default: "") let long = entry.at("long", default: "") let hasLong = long != "" and long != [] @@ -121,26 +121,27 @@ SOFTWARE.*/ } } if hasDesc [: #desc ] else [. ] - - term_references.map((x) => x.location()) - .sorted(key: (x) => x.page()) - .fold( - (values: (), pages: ()), - ((values, pages), x) => if pages.contains(x.page()) { - (values: values, pages: pages) - } else { - values.push(x) - pages.push(x.page()) - (values: values, pages: pages) - }, - ) - .values - .map( - (x) => link( - x, - )[#numbering(x.page-numbering(), ..counter(page).at(x))], - ) - .join(", ") + if disable-back-references == true { + term_references.map((x) => x.location()) + .sorted(key: (x) => x.page()) + .fold( + (values: (), pages: ()), + ((values, pages), x) => if pages.contains(x.page()) { + (values: values, pages: pages) + } else { + values.push(x) + pages.push(x.page()) + (values: values, pages: pages) + }, + ) + .values + .map( + (x) => link( + x, + )[#numbering(x.page-numbering(), ..counter(page).at(x))], + ) + .join(", ") + } } }, ) diff --git a/makefile b/makefile index bc76ef2..f3b6d30 100644 --- a/makefile +++ b/makefile @@ -1,14 +1,19 @@ version=0.2.5 -local: +local: ## copy typst package to local registry mkdir -p ~/.local/share/typst/packages/local/glossarium/${version} cp -r * ~/.local/share/typst/packages/local/glossarium/${version} -all: +all: ## build example typst compile --root . example/example.typ -watch: +watch: ## watch example typst watch --root . example/example.typ -fmt: +fmt: ## format typst code find -name "**.typ" -exec typstfmt {} \; + + +.PHONY: help +help: ## Show this help + @grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'