Compare commits

...
Author SHA1 Message Date
swaits 86f16a7ac0 feat(glossy): 0.2.2 2024-12-10 20:45:18 +00:00
swaits bf97dcdbab feat(glossy): 0.2.1 2024-12-10 20:45:05 +00:00
25 changed files with 561 additions and 319 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
tests/**/out/
tests/**/diff/
+7 -48
View File
@@ -41,7 +41,7 @@ different goals:
### Import the package
```typst
#import "@preview/glossy:0.2.0": *
#import "@preview/glossy:0.2.2": *
```
### Defining Glossary Terms
@@ -154,8 +154,9 @@ Display the glossary using the `glossary()` function:
```typst
#glossary(
title: "Web Development Glossary",
theme: my-theme,
title: "Web Development Glossary", // Optional: defaults to Glossary
theme: my-theme, // Optionaal: defaults to theme-twocol
ignore-case: false, // Optional: ignore case when sorting terms
groups: ("Web") // Optional: Filter to specific groups
)
```
@@ -177,52 +178,10 @@ Control how terms appear in the document by providing a custom `show-term` funct
#### Included Themes
Glossy comes with several built-in themes that can be used directly or serve as examples for custom themes:
Glossy comes with several built-in themes that can be used directly or serve as
examples for custom themes:
##### theme-twocol
A professional two-column layout ideal for technical documentation. Features:
- Two-column layout for efficient space usage
- Dotted leaders to page numbers
- Clear hierarchy with optional group headings
- Compact but readable formatting
- Terms in regular weight with long forms and descriptions inline
```typst
#glossary(theme: theme-twocol)
```
##### theme-basic
A traditional single-column layout similar to book glossaries. Features:
- Bold terms with indented content
- Clear separation between entries
- Hanging indentation for wrapped lines
- Parenthetical long forms
- Page numbers with "pp." prefix
- Simple, clean design
```typst
#glossary(theme: theme-basic)
```
##### theme-compact
A space-efficient layout perfect for technical documents or appendices. Features:
- Reduced vertical spacing
- Smaller font sizes for secondary information
- Color-coded term components
- Grid-based alignment
- Minimal decorative elements
- Gray text for supplementary information
- Bullet separators between components
```typst
#glossary(theme: theme-compact)
```
![theme gallery image](themeshots.png)
#### Custom Themes
Binary file not shown.
+34 -32
View File
@@ -271,35 +271,28 @@
// Example output: "1, 3, 5" where each number links to the term usage on that page
//
#let __create_backlinks(key, count) = {
// Generate labels for each term usage
let labels = for i in range(count) {
(__term_label(key, i),)
// Convert term (key + count) to labels with their displayed page numbers
let page_labels = range(count).map(i => {
let label = __term_label(key, i)
let loc = locate(label)
(
label,
numbering(__default(loc.page-numbering(), "1"), ..counter(page).at(loc))
)
})
// Filter out repeated page numbers using a regular loop
let seen = (:)
let singulated = ()
for (label, page) in page_labels {
if not seen.keys().contains(page) {
seen.insert(page, true)
singulated.push((label, page))
}
}
// Get page numbers for each usage
let pages = labels
.map(l => locate(l))
.map(loc => numbering(
__default(loc.page-numbering(), "1"),
loc.page()
))
// Create links, excluding duplicate page numbers
let seen = ()
let links = for i in range(labels.len()) {
let label = labels.at(i)
let page = pages.at(i)
if seen.contains(page) {
(none,)
} else {
seen.push(page)
(link(label, page),)
}
}.filter(l => l != none)
// Join links with commas
links.join(", ")
// Convert resulting set to array of links
singulated.map(((label, page)) => link(label, page)).join(", ")
}
// Initializes the glossary system and sets up term reference handling.
@@ -390,7 +383,8 @@
#let glossary(
title: "Glossary",
theme: theme-twocol,
groups: ()
ignore-case: false,
groups: (),
) = context {
// Collect and organize entries by group
let output = (:)
@@ -437,10 +431,18 @@
// Add non-empty groups to output
if current_entries.len() > 0 {
group = if group == none { "" } else { group }
output.insert(
group,
current_entries.sorted(key: e => e.short)
)
// sort entries by case insensitivity if requested
let sorted_entries = current_entries
// 1. create array of tuples with (lower [if ignore-case], entry)
.map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } })
// 2. sort the tuples (by first element then second)
.sorted(key: t => t.first())
// 3. strip away the tuple's first element, leaving an array of entries
.map(t => t.last())
// add entries to this group's output map
output.insert(group, sorted_entries)
}
}
+6 -236
View File
@@ -1,236 +1,6 @@
// Theme definition for a two-column glossary layout with hierarchical sections
//
// This theme provides formatting for three levels of glossary content:
// 1. Section: The overall glossary container
// 2. Groups: Optional categorization of related terms
// 3. Entries: Individual glossary terms and their definitions
//
#let theme-twocol = (
// Renders the main glossary section as a two-column layout
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
set par.line(numbering: none)
heading(level: 1, title)
columns(2, body)
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
heading(level: 2, name)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format the short form and optional long form of the term
let short-display = text(weight: "regular", entry.short)
let long-display = if entry.long == none {
[]
} else {
[#h(0.25em) -- #entry.long]
}
// Format the optional description
let description = if entry.description == none {
[]
} else {
[: #entry.description]
}
// Render the complete entry with dotted leader line to page numbers
text(
size: 0.75em,
weight: "light",
grid(
columns: (auto,auto,auto,1fr,1em,auto),
align: (left, left, left, center, center, right),
[#short-display#entry.label], // Term with label
[#long-display], // Long form (if any)
[#description], // Description (if any)
[#repeat(h(0.25em) + "." + h(0.25em))], // Dotted leader line
[ . ], // Final dot
[#entry.pages] // Page references
)
)
},
)
// Theme definition for a basic single-column glossary layout
//
// This theme provides a traditional glossary format with:
// 1. Bold terms
// 2. Indented descriptions
// 3. Simple page references
// 4. Optional group headings
//
#let theme-basic = (
// Renders the main glossary section as a single column
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
heading(level: 1, title)
body
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
heading(level: 2, name)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format the term parts
let term = text(weight: "bold", entry.short)
let long-form = if entry.long == none {
[]
} else {
[, #entry.long]
}
// Format the description with proper spacing
let description = if entry.description == none {
[]
} else {
[: #entry.description]
}
// Create the complete entry with hanging indent
block(
spacing: 0.5em,
pad(
left: 1em,
bottom: 0.5em,
block(
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages)]
)
)
)
},
)
// Theme definition for a compact glossary layout optimized for space efficiency
//
// This theme provides a dense but readable format with:
// 1. Terms and definitions on same line
// 2. Smaller font size
// 3. Minimal vertical spacing
// 4. Left-aligned groups for quick scanning
// 5. Condensed page references
//
#let theme-compact = (
// Renders the main glossary section with minimal spacing
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
set par(leading: 0.65em)
heading(level: 1, outlined: false, text(weight: "bold", size: 1.1em, title))
body
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
block(
spacing: 0.5em,
pad(
top: 0.5em,
text(weight: "bold", size: 0.9em, name)
)
)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format term components with minimal spacing
let term = text(
size: 0.65em,
weight: "medium",
fill: gray.darken(60%),
entry.short
)
let long-form = if entry.long == none {
[]
} else {
text(size: 0.65em, fill: gray.darken(20%), [ (#entry.long)])
}
let description = if entry.description == none {
[]
} else {
text(size: 0.65em, [· #entry.description])
}
// Create the complete entry with tight spacing
block(
spacing: 0.4em,
grid(
columns: (auto, 1fr, auto),
gutter: 0.5em,
// Term and description column
box[#term#entry.label#long-form #description],
// Dots....
repeat(h(0.25em) + text(fill: gray, ".") + h(0.25em)),
// Page references with smaller font
text(
size: 0.6em,
fill: gray.darken(20%),
entry.pages
)
)
)
},
)
#import "themes/academic.typ": theme-academic
#import "themes/basic.typ": theme-basic
#import "themes/chicago-index.typ": theme-chicago-index
#import "themes/compact.typ": theme-compact
#import "themes/table.typ": theme-table
#import "themes/twocol.typ": theme-twocol
+50
View File
@@ -0,0 +1,50 @@
// Inspired by academic textbook glossaries
#let theme-academic = (
section: (title, body) => {
set text(font: "New Computer Modern")
heading(level: 1, title)
v(1em)
body
},
group: (name, index, total, body) => {
if name != "" and total > 1 {
v(1.5em)
align(left, text(weight: "bold", size: 1.2em, name))
v(0.75em)
line(length: 100%, stroke: 0.5pt)
v(0.75em)
}
body
},
entry: (entry, index, total) => {
let short-display = text(weight: "bold", entry.short)
let long-display = if entry.long == none {
[]
} else {
[. #entry.long]
}
let description = if entry.description == none {
[]
} else {
[. #entry.description]
}
block(
below: 1em,
text(
size: 0.95em,
{
grid(
columns: (1fr, auto),
gutter: 0.75em,
[#short-display#long-display#description],
text(fill: rgb("#666666"), entry.pages)
)
}
)
)
},
)
+70
View File
@@ -0,0 +1,70 @@
// Theme definition for a basic single-column glossary layout
//
// This theme provides a traditional glossary format with:
// 1. Bold terms
// 2. Indented descriptions
// 3. Simple page references
// 4. Optional group headings
//
#let theme-basic = (
// Renders the main glossary section as a single column
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
heading(level: 1, title)
body
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
heading(level: 2, name)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format the term parts
let term = text(weight: "bold", entry.short)
let long-form = if entry.long == none {
[]
} else {
[, #entry.long]
}
// Format the description with proper spacing
let description = if entry.description == none {
[]
} else {
[: #entry.description]
}
// Create the complete entry with hanging indent
block(
spacing: 0.5em,
pad(
left: 1em,
bottom: 0.5em,
block(
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages)]
)
)
)
},
)
@@ -0,0 +1,47 @@
// Inspired by the Chicago Manual of Style's index format
#let theme-chicago-index = (
section: (title, body) => {
set par(hanging-indent: 1em)
heading(level: 1, smallcaps(title))
body
},
group: (name, index, total, body) => {
if name != "" and total > 1 {
v(1em)
text(weight: "medium", style: "italic", name)
v(0.5em)
}
body
},
entry: (entry, index, total) => {
let short-display = text(weight: "regular", entry.short)
let long-display = if entry.long == none {
[]
} else {
[ — #entry.long] // Using em-dash for Chicago style
}
let description = if entry.description == none {
[]
} else {
text(style: "italic", [: #entry.description])
}
block(
below: 0.65em,
text(
size: 0.9em,
{
grid(
columns: (1fr, auto),
gutter: 1em,
[#short-display#entry.label#long-display#description],
[#entry.pages]
)
}
)
)
},
)
+91
View File
@@ -0,0 +1,91 @@
// Theme definition for a compact glossary layout optimized for space efficiency
//
// This theme provides a dense but readable format with:
// 1. Terms and definitions on same line
// 2. Smaller font size
// 3. Minimal vertical spacing
// 4. Left-aligned groups for quick scanning
// 5. Condensed page references
//
#let theme-compact = (
// Renders the main glossary section with minimal spacing
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
set par(leading: 0.65em)
heading(level: 1, outlined: false, text(weight: "bold", size: 1.1em, title))
body
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
block(
spacing: 0.5em,
pad(
top: 0.5em,
text(weight: "bold", size: 0.9em, name)
)
)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format term components with minimal spacing
let term = text(
size: 0.65em,
weight: "medium",
fill: gray.darken(60%),
entry.short
)
let long-form = if entry.long == none {
[]
} else {
text(size: 0.65em, fill: gray.darken(20%), [ (#entry.long)])
}
let description = if entry.description == none {
[]
} else {
text(size: 0.65em, [· #entry.description])
}
// Create the complete entry with tight spacing
block(
spacing: 0.4em,
grid(
columns: (auto, 1fr, auto),
align: left+bottom,
gutter: 0.5em,
// Term and description column
box[#term#entry.label#long-form #description],
// Dots....
repeat(h(0.25em) + text(fill: gray, ".") + h(0.25em)),
// Page references with smaller font
text(
size: 0.6em,
fill: gray.darken(20%),
entry.pages
)
)
)
},
)
+32
View File
@@ -0,0 +1,32 @@
// A tabular theme courtesy of [@Fevol](https://github.com/Fevol)
#let theme-table = (
section: (title, body) => {
heading(level: 1, title)
body
},
group: (name, index, total, body) => {
if name != "" and total > 1 {
heading(level: 2, name)
}
table(columns: 4,
stroke: none,
inset: (x, y) => {
if (x == 0) {
(left: 0pt, rest: 5pt)
} else if (x == 3) {
(right: 0pt, rest: 5pt)
} else {
5pt
}
},
table.header([*Abbreviation*], [*Full Name*], [*Description*], [*Pages*]),
..body
)
},
entry: (entry, index, total) => {
(entry.short, entry.long, entry.description, entry.pages)
}
)
+72
View File
@@ -0,0 +1,72 @@
// Theme definition for a two-column glossary layout with hierarchical sections
//
// This theme provides formatting for three levels of glossary content:
// 1. Section: The overall glossary container
// 2. Groups: Optional categorization of related terms
// 3. Entries: Individual glossary terms and their definitions
//
#let theme-twocol = (
// Renders the main glossary section as a two-column layout
// Parameters:
// title: The glossary section title
// body: Content containing all groups and entries
section: (title, body) => {
set par.line(numbering: none)
heading(level: 1, title)
columns(2, body)
},
// Renders a group of related glossary terms
// Parameters:
// name: Group name (empty string for ungrouped terms)
// index: Zero-based group index
// total: Total number of groups
// body: Content containing the group's entries
group: (name, index, total, body) => {
if name != "" and total > 1 {
heading(level: 2, name)
}
body
},
// Renders a single glossary entry with term, definition, and page references
// Parameters:
// entry: Dictionary containing term data:
// - short: Short form of term
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
// Format the short form and optional long form of the term
let short-display = text(weight: "regular", entry.short)
let long-display = if entry.long == none {
[]
} else {
[#h(0.25em) -- #entry.long]
}
// Format the optional description
let description = if entry.description == none {
[]
} else {
[: #entry.description]
}
// Render the complete entry with dotted leader line to page numbers
text(
size: 0.75em,
weight: "light",
grid(
columns: (auto,1fr,1em,auto),
align: (left, center, center, right),
[#short-display#entry.label#long-display#description], // Term with label
[#repeat(h(0.25em) + "." + h(0.25em))], // Dotted leader line
[ . ], // A 1em wide dot so we definitely get some break between term and pages
[#entry.pages] // Page references
)
)
},
)
Binary file not shown.

After

Width:  |  Height:  |  Size: 606 KiB

@@ -1,6 +1,6 @@
// a minimal example, also listed in the README
#import "@preview/glossy:0.2.0": *
#import "/lib.typ": *
#let myGlossary = (
html: (
@@ -22,6 +22,7 @@
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
#set heading(numbering: "1.1")
#set page(numbering: "1")
= Hello, `glossy`!
In modern web development, languages like @html and @css are essential.
Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.
@@ -0,0 +1,51 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
),
iphone: (
short: "iPhone",
),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
),
atom: (
short: "atom",
),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"
),
)
#show: init-glossary.with(myGlossary)
#set page(numbering: "i")
@html, @iphone, @css
#pagebreak()
#set page(numbering: "1")
@html, @iphone, @css, @atom
#pagebreak()
#counter(page).update(1)
#set page(numbering: "A")
@html, @iphone, @css, @tps
#pagebreak()
#set page(numbering: "I")
@css, @iphone, @tps
#glossary(theme: theme-chicago-index, ignore-case: true)
Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

+40
View File
@@ -0,0 +1,40 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
),
iphone: (
short: "iPhone",
long: "iPhone",
),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
),
atom: (
short: "atom",
long: "atom",
),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"
),
)
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
#set page(numbering: "1")
= Refer to our terms so they show up in the glossary
@html, @iphone:long, @css, @css:cap:pl, @atom:pl, @tps:long
= Default sorting
#glossary(theme: theme-compact)
= Case-insensitive sorting (`ignore-case: true`)
#glossary(ignore-case: true, theme: theme-compact)
Binary file not shown.

After

Width:  |  Height:  |  Size: 651 KiB

@@ -0,0 +1,55 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
),
iphone: (
short: "iPhone",
description: "Revolutionized phones."
),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
),
atom: (
short: "atom",
),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"
),
)
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
#set page(
margin: 1cm,
height: auto,
numbering: "1",
)
#text(size: 24pt, weight: "bold")[`glossy`: theme gallery]
#text(size: 1pt, fill: rgb(0,0,0,0))[
First, we refer to each term at least once so they'll actually show up in the
glossaries. Our terms include: @atom, @iphone, @html:cap, @css, and @tps.
]
#v(-2em)
#import "/src/themes.typ"
#for theme in dictionary(themes) {
block(
breakable: false,
width: 100%,
spacing: 2em,
inset: 1em,
stroke: 1pt+gray,
height: if theme.first() == "theme-twocol" { 1.5in } else { auto },
glossary(title: raw(theme.first()), theme: theme.last(), ignore-case: true)
)
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 651 KiB

+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "glossy"
version = "0.2.0"
version = "0.2.2"
entrypoint = "lib.typ"
authors = ["Stephen Waits <steve@waits.net>"]
license = "MIT"
@@ -8,4 +8,4 @@ description = "A very simple glossary system with easily customizable output."
categories = ["model"]
keywords = ["glossary", "index", "dictionary", "gloss"]
repository = "https://github.com/swaits/typst-collection"
exclude = ["thumbnail.png", "examples/readme.pdf"]
exclude = ["thumbnail.png", "themeshots.pjng", "tests"]