-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ENIB-Community/add-import-from-yml-example
add examples
- Loading branch information
Showing
13 changed files
with
148 additions
and
29 deletions.
There are no files selected for viewing
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# glossary.yaml | ||
|
||
ntc: | ||
short: NTC | ||
long: Nonlinear Transform Coding | ||
description: | | ||
This is the opposite of @ltc. | ||
ltc: | ||
short: LTC | ||
long: Linear Transform Coding | ||
description: | | ||
Transform Coding constraint to linear transforms. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// EXAMPLE MADE BY Philipp Jungkamp (https://github.com/PJungkamp) in issue: https://github.com/ENIB-Community/glossarium/issues/15 | ||
|
||
// The glossary command here is modeled after the bibliography command and accepts similar arguments. | ||
|
||
|
||
|
||
#import "@local/glossarium:0.2.6": * | ||
// Replace the local import with a import to the preview namespace. | ||
// If you don't know what that mean, please go read typst documentation on how to import packages at https://typst.app/docs/packages/. | ||
|
||
#let glossary(files, title: "Glossary", full: false) = { | ||
let read-glossary-entries(file) = { | ||
let entries = yaml(file) | ||
|
||
assert( | ||
type(entries) == dictionary, | ||
message: "The glossary at `" + file + "` is not a dictionary", | ||
) | ||
|
||
for (k, v) in entries.pairs() { | ||
assert( | ||
type(v) == dictionary, | ||
message: "The glossary entry `" + k + "` in `" + file + "` is not a dictionary", | ||
) | ||
|
||
for key in v.keys() { | ||
assert( | ||
key in ("short", "long", "description"), | ||
message: "Found unexpected key `" + key + "` in glossary entry `" + k + "` in `" + file + "`", | ||
) | ||
} | ||
|
||
assert( | ||
type(v.short) == str, | ||
message: "The short form of glossary entry `" + k + "` in `" + file + "` is not a string", | ||
) | ||
|
||
if "long" in v { | ||
assert( | ||
type(v.long) == str, | ||
message: "The long form of glossary entry `" + k + "` in `" + file + "` is not a string", | ||
) | ||
} | ||
|
||
if "description" in v { | ||
assert( | ||
type(v.description) == str, | ||
message: "The description of glossary entry `" + k + "` in `" + file + "` is not a string", | ||
) | ||
} | ||
} | ||
|
||
return entries.pairs().map(((key, entry)) => ( | ||
key: key, | ||
short: eval(entry.short, mode: "markup"), | ||
long: eval(entry.at("long", default: ""), mode: "markup"), | ||
desc: eval(entry.at("description", default: ""), mode: "markup"), | ||
file: file, | ||
)) | ||
} | ||
|
||
let entries = () | ||
|
||
if type(files) != array { | ||
files = (files,) | ||
} | ||
|
||
for file in files { | ||
let new = read-glossary-entries(file) | ||
|
||
for entry in new { | ||
let duplicate = entries.find((e) => e.key == entry.key) | ||
if duplicate != none { | ||
panic("Found duplicate key `" + entry.key + "` in files `" + entry.file + "` and `" + duplicate.file + "`") | ||
} | ||
} | ||
|
||
entries += new | ||
} | ||
|
||
[= #title] | ||
print-glossary(entries, show-all: full) | ||
} | ||
|
||
#set page(numbering: "1") | ||
#show: make-glossary | ||
|
||
= Test Document | ||
|
||
Reference to @ntc | ||
|
||
#glossary("glossary.yml") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version := "0.2.6" | ||
|
||
|
||
# copy typst package to local registry | ||
local: | ||
mkdir -p ~/.local/share/typst/packages/local/glossarium/{{version}} | ||
cp -r * ~/.local/share/typst/packages/local/glossarium/{{version}} | ||
|
||
build-examples: local | ||
find examples/* -type d -exec typst compile --root {} {}/main.typ \; | ||
|
||
# format typst code (use typstfmt) | ||
fmt: | ||
find -name "**.typ" -exec typstfmt {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
# This makefile is only here of compatibility purposes. | ||
# I highly recommand to use the command laucher just (https://just.systems/man/en/). | ||
|
||
|
||
version=0.2.6 | ||
|
||
local: ## copy typst package to local registry | ||
build-examples: | ||
@echo THIS MAKE COMMAND IS NOT THE OFFICIAL WAY | ||
@echo TO BUILD THE EXAMPLES. PLEASE USE THE JUST | ||
@echo RECIPES DEFINED IN THE justfile IN THIS REPO. | ||
@echo "" | ||
mkdir -p ~/.local/share/typst/packages/local/glossarium/${version} | ||
cp -r * ~/.local/share/typst/packages/local/glossarium/${version} | ||
|
||
all: ## build example | ||
typst compile --root . example/example.typ | ||
|
||
watch: ## watch example | ||
typst watch --root . example/example.typ | ||
|
||
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}' | ||
find examples/* -type d -exec typst compile --root {} {}/main.typ \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters