Skip to content

Commit

Permalink
Merge pull request #20 from ENIB-Community/add-import-from-yml-example
Browse files Browse the repository at this point in the history
add examples
  • Loading branch information
slashformotion authored Jan 27, 2024
2 parents 7923330 + dc79a03 commit 37621b2
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 29 deletions.
File renamed without changes
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
- name: typst version
run: typst --version
- name: Compile
run: typst compile --root . example/example.typ
run: make build-examples
- name: Upload example PDF
uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}_PDF_EXAMPLE
path: example/example.pdf
name: ${{ github.sha }}_PDF_EXAMPLES
path: examples/*
if-no-files-found: error
2 changes: 1 addition & 1 deletion .github/workflows/post-result-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
Please note that files only stay for around 90 days!
| Name | Link |
--------------------------------------------------------------------
|---|---|
| Commit | ${{ env.HEAD_SHA }} |
| Workflow Run (click here to get PDF link) | ${{ env.JOB_PATH }} |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Glossarium is a simple, easily customizable typst glossary inspired by [LaTeX glossaries package](https://www.ctan.org/pkg/glossaries) . You can see an example showing the different features in [`example.typ`](example/example.typ).

![Screenshot](example/example.png)
![Screenshot](.github/example.png)

## Manual

Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion example/example.typ → examples/full-example/main.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#import "../glossarium.typ": make-glossary, print-glossary, gls, glspl
#import "@local/glossarium:0.2.6": make-glossary, print-glossary, gls, glspl
// 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/.

#show: make-glossary

#set page(numbering: "1", paper: "a5")
Expand Down
13 changes: 13 additions & 0 deletions examples/import-terms-from-yaml-file/glossary.yml
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 added examples/import-terms-from-yaml-file/main.pdf
Binary file not shown.
92 changes: 92 additions & 0 deletions examples/import-terms-from-yaml-file/main.typ
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")
14 changes: 14 additions & 0 deletions justfile
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 {} \;
25 changes: 10 additions & 15 deletions makefile
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 \;
16 changes: 9 additions & 7 deletions tbump.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this if your project is hosted on GitHub:
# github_url = "https://github.com/<user or organization>/<project>/"
github_url = "https://github.com/ENIB-Community/glossarium/"

[version]
current = "0.2.6"
Expand All @@ -21,20 +21,22 @@ tag_template = "v{new_version}"

[[file]]
src = "typst.toml"
search = 'version = "{current_version}"'

[[file]]
src = "makefile"
search = 'version={current_version}'
src = "justfile"

[[file]]
src = "README.md"
search = '#import "@preview/glossarium:{current_version}": make-glossary, print-glossary, gls, glspl'

[[file]]
src = "examples/import-terms-from-yaml-file/import-terms-from-yaml-file.typ"

[[file]]
src = "examples/full-example/main.typ"

[[before_commit]]
name = "compile examples"
cmd = "typst compile example/example.typ --root . "

cmd = "make "

[[after_push]]
name = "Create local version of package"
Expand Down
2 changes: 1 addition & 1 deletion typst.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ authors = ["slashformotion", "Dherse"]
license = "MIT"
description = "Glossarium is a simple, easily customizable typst glossary."
repository = "https://github.com/ENIB-Community/glossarium"
exclude = ["tbump.toml", "example/*", ".gitignore", "makefile", ".github/*"]
exclude = ["tbump.toml", "examples/*", ".gitignore", "makefile", ".github/*"]

0 comments on commit 37621b2

Please sign in to comment.