Skip to content

Commit

Permalink
Merge pull request #17 from ENIB-Community/feat-disable_back_ref
Browse files Browse the repository at this point in the history
add parameter disable-back-references
  • Loading branch information
slashformotion authored Jan 26, 2024
2 parents a77c17f + 3f804f7 commit 9a6cc30
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
4 changes: 3 additions & 1 deletion example/example.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
45 changes: 23 additions & 22 deletions glossarium.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != []
Expand All @@ -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(", ")
}
}
},
)
Expand Down
13 changes: 9 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -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}'

0 comments on commit 9a6cc30

Please sign in to comment.