Skip to content

Commit a0b3cdc

Browse files
committed
v0.1.2
1 parent c22bcef commit a0b3cdc

File tree

5 files changed

+3453
-2072
lines changed

5 files changed

+3453
-2072
lines changed

Marginalia.pdf

18 KB
Binary file not shown.

lib.typ

Lines changed: 117 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,51 @@
44
/// #internal[Mostly internal.]
55
/// The counter used for the note icons.
66
///
7-
/// It is recommended to reset this counter regularly if the default symbols are used,
8-
/// as after ten notes it will start to number them.
9-
///#example(scale-preview: 100%, `notecounter.update(1)`)
7+
/// If you use @note-numbering without @note-numbering.repeat, it is reccommended you reset this occasionally, e.g. per heading or per page.
8+
/// #example(scale-preview: 100%, ```typc notecounter.update(1)```)
109
/// -> counter
1110
#let notecounter = counter("notecounter")
1211

13-
#let _notenumbering = ("", "", "", "", "", "", "", "", "", "")
14-
#let _notenumbering = ("", "", "", "", "", "", "", "", "", "")
12+
/// Icons to use for note markers.
13+
///
14+
/// ```typc ("◆", "●", "■", "▲", "♥", "◇", "○", "□", "△", "♡")```
15+
#let note-markers = ("", "", "", "", "", "", "", "", "", "")
16+
/// Icons to use for note markers, alternating filled/outlined.
17+
///
18+
/// ```typc ("●", "○", "◆", "◇", "■", "□", "▲", "△", "♥", "♡")```
19+
#let note-markers-alternating = ("", "", "", "", "", "", "", "", "", "")
1520

16-
/// #internal[Mostly internal.]
17-
/// Format a counter like the note icons.
18-
/// Default numbering for notes.
19-
///#example(`notecounter.display(as-note)`)
20-
///#example(```
21-
///let i = 1
22-
///while i < 12 {
23-
/// [ #as-note(i) ]
24-
/// i = i + 1
25-
///}
26-
///```)
27-
/// - ..counter (int):
21+
/// Format note marker
2822
/// -> content
29-
#let as-note(..counter) = { }
30-
#let as-note(.., last) = {
31-
let symbol = if last > _notenumbering.len() or last <= 0 [ #(last - _notenumbering.len()) ] else {
32-
_notenumbering.at(last - 1)
33-
}
34-
return text(weight: 900, font: "Inter", size: 6pt, style: "normal", fill: rgb(54%, 72%, 95%), symbol)
23+
#let note-numbering(
24+
/// #example(```typ
25+
/// #for i in array.range(1,15) [
26+
/// #note-numbering(markers: note-markers, i)
27+
/// ]\
28+
/// #for i in array.range(1,15) [
29+
/// #note-numbering(markers: note-markers-alternating, i)
30+
/// ]
31+
/// ```)
32+
/// -> array(string)
33+
markers: note-markers-alternating,
34+
/// Whether to (```typc true```) loop over the icons, or (```typc false```) continue with numbers after icons run out.
35+
/// #example(```typ
36+
/// #for i in array.range(1,15) [
37+
/// #note-numbering(repeat: true, i)
38+
/// ]\
39+
/// #for i in array.range(1,15) [
40+
/// #note-numbering(repeat: false, i)
41+
/// ]
42+
/// ```)
43+
/// -> boolean
44+
repeat: true,
45+
..,
46+
/// -> int
47+
number
48+
) = {
49+
let index = if repeat { calc.rem(number - 1, markers.len()) } else { number - 1 }
50+
let symbol = if index < markers.len() { markers.at(index) } else { str(index + 1 - markers.len()) }
51+
return text(weight: 900, font: "Inter", size: 5pt, style: "normal", fill: rgb(54%, 72%, 95%), symbol)
3552
}
3653

3754
///#internal()
@@ -54,9 +71,9 @@
5471
top: config.at("top", default: 2.5cm),
5572
bottom: config.at("bottom", default: 2.5cm),
5673
book: config.at("book", default: false),
57-
clearance: config.at("clearance", default: 8pt),
74+
clearance: config.at("clearance", default: 12pt),
5875
flush-numbers: config.at("flush-numbers", default: false),
59-
numbering: config.at("numbering", default: as-note),
76+
numbering: config.at("numbering", default: note-numbering),
6077
)
6178
}
6279

@@ -65,30 +82,38 @@
6582
/// This will update the marginalia config with the provided config options.
6683
///
6784
/// The default values for the margins have been chosen such that they match the default typst margins for a4. It is strongly recommended to change at least one of either `inner` or `outer` to be wide enough to actually contain text.
68-
/// - inner (dictionary): Inside/left margins.
69-
/// - `far`: Distance between edge of page and margin (note) column.
70-
/// - `width`: Width of the margin column.
71-
/// - `sep`: Distance between margin column and main text column.
72-
///
73-
/// The page inside/left margin should equal `far` + `width` + `sep`.
74-
///
75-
/// If partial dictionary is given, it will be filled up with defaults.
76-
/// - outer (dictionary): Outside/right margins. Analogous to `inner`.
77-
/// - top (length): Top margin.
78-
/// - bottom (length): Bottom margin.
79-
/// - book (boolean): If ```typc true```, will use inside/outside margins, alternating on each page. If ```typc false```, will use left/right margins with all pages the same.
80-
/// - clearance (length): Minimal vertical distance between notes and to wide blocks.
81-
/// - flush-numbers (boolean): Disallow note icons hanging into the whitespace.
82-
/// - numbering (str, function): Function or `numbering`-string to generate the note markers from the `notecounter`.
8385
#let configure(
86+
/// Inside/left margins.
87+
/// - `far`: Distance between edge of page and margin (note) column.
88+
/// - `width`: Width of the margin column.
89+
/// - `sep`: Distance between margin column and main text column.
90+
///
91+
/// The page inside/left margin should equal `far` + `width` + `sep`.
92+
///
93+
/// If partial dictionary is given, it will be filled up with defaults.
94+
/// -> dictionary
8495
inner: (far: 5mm, width: 15mm, sep: 5mm),
96+
/// Outside/right margins. Analogous to `inner`.
97+
/// -> dictionary
8598
outer: (far: 5mm, width: 15mm, sep: 5mm),
99+
/// Top margin.
100+
/// -> length
86101
top: 2.5cm,
102+
/// Bottom margin.
103+
/// -> length
87104
bottom: 2.5cm,
105+
/// If ```typc true```, will use inside/outside margins, alternating on each page. If ```typc false```, will use left/right margins with all pages the same.
106+
/// -> boolean
88107
book: false,
108+
/// Minimal vertical distance between notes and to wide blocks.
109+
/// -> length
89110
clearance: 8pt,
111+
/// Disallow note icons hanging into the whitespace.
112+
/// -> boolean
90113
flush-numbers: false,
91-
numbering: as-note,
114+
/// Function or `numbering`-string to generate the note markers from the `notecounter`.
115+
/// -> function | string
116+
numbering: note-numbering,
92117
) = { }
93118
#let configure(..config) = (
94119
context {
@@ -101,17 +126,20 @@
101126
}
102127
)
103128

104-
/* Page setup helper */
105-
129+
/// Page setup helper
130+
///
106131
/// This will generate a dictionary ```typc ( margin: .. )``` compatible with the passed config.
107132
/// This can then be spread into the page setup like so:
108133
///```typ
109134
/// #set page( ..page-setup(..config) )```
110135
///
111-
/// Takes the same options as @@configure().
112-
/// - ..config (dictionary): Missing entries are filled with package defaults. Note: missing entries are _not_ taken from the current marginalia config, as this would require context.
136+
/// Takes the same options as @configure.
113137
/// -> dictionary
114-
#let page-setup(..config) = {
138+
#let page-setup(
139+
/// Missing entries are filled with package defaults. Note: missing entries are _not_ taken from the current marginalia config, as this would require context.
140+
/// -> dictionary
141+
..config
142+
) = {
115143
let config = _fill_config(..config)
116144
if config.book {
117145
return (
@@ -322,23 +350,30 @@
322350

323351
/// Create a marginnote.
324352
/// Will adjust it's position downwards to avoid previously placed notes, and upwards to avoid extending past the bottom margin.
325-
///
326-
/// - numbered (boolean): Whether to put a mark.
327-
/// - reverse (boolean): Whether to put it in the opposite (inner/left) margin.
328-
/// - dy (length): Vertical offset of the note.
329-
/// - body (content):
330-
#let note(numbered: true, reverse: false, dy: 0pt, body) = {
353+
#let note(
354+
/// Whether to put a mark.
355+
/// -> boolean
356+
numbered: true,
357+
/// Whether to put it in the opposite (inner/left) margin.
358+
/// -> boolean
359+
reverse: false,
360+
/// Inital vertical offset of the note.
361+
/// Note may get shifted still to avoid other notes.
362+
/// -> length
363+
dy: 0pt,
364+
/// -> content
365+
body
366+
) = {
367+
set text(size: 7.5pt, style: "normal", weight: "regular")
331368
if numbered {
332369
notecounter.step()
333370
let body = context if _config.get().flush-numbers {
334-
set par(spacing: 0.55em, leading: 0.4em, hanging-indent: 0pt)
335-
set text(size: 0.8em, weight: "regular")
371+
set par(spacing: 0.8em, leading: 0.4em, hanging-indent: 0pt)
336372
notecounter.display(_config.get().numbering)
337373
h(1.5pt)
338374
body
339375
} else {
340-
set par(spacing: 0.55em, leading: 0.4em, hanging-indent: 0pt)
341-
set text(size: 0.8em, weight: "regular")
376+
set par(spacing: 0.8em, leading: 0.4em, hanging-indent: 0pt)
342377
box(
343378
width: 0pt,
344379
{
@@ -372,8 +407,7 @@
372407
} else {
373408
h(0pt, weak: true)
374409
let body = {
375-
set par(spacing: 0.55em, leading: 0.4em, hanging-indent: 0pt)
376-
set text(size: 0.8em, weight: "regular")
410+
set par(spacing: 0.8em, leading: 0.4em, hanging-indent: 0pt)
377411
body
378412
}
379413
box(context {
@@ -387,40 +421,28 @@
387421
}
388422

389423
/// Creates a figure in the margin.
390-
///
391-
/// // - content (content): The figure content, e.g.~an image. Pass-through to ```typ #figure()```, but used to adjust the vertical position.
392-
/// - content (content):
393-
/// - reverse (boolean): Put the notefigure in the opposite margin.
394-
/// - dy (relative length): How much to shift the note. ```typc 100%``` corresponds to the height of `content` + `gap`.
395-
/// - numbered (boolean): Whether to put a mark.
396-
/// - label (none, label): A label to attach to the figure.
397-
/// - caption (none, content): The caption. Pass-through to ```typ #figure()```.
398-
/// - gap (length): Pass-through to ```typ #figure()```, but used to adjust the vertical position.
399-
/// - kind (auto, str, function): Pass-through to ```typ #figure()```.
400-
/// - supplement (none,auto,content,function): Pass-through to ```typ #figure()```.
401-
/// - numbering (none,str,function): Pass-through to ```typ #figure()```.
402-
/// - outlined (boolean): Pass-through to ```typ #figure()```.
403424
/// -> content
404425
#let notefigure(
426+
/// The figure content, e.g.~an image. Pass-through to ```typ #figure()```, but used to adjust the vertical position.
427+
/// -> content
405428
content,
429+
/// Put the notefigure in the opposite margin.
430+
/// -> boolean
406431
reverse: false,
432+
/// How much to shift the note. ```typc 100%``` corresponds to the height of `content` + `gap`.
433+
/// -> relative length
407434
dy: 0pt - 100%,
435+
/// Whether to put a mark.
436+
/// -> boolean
408437
numbered: false,
409-
label: none,
410-
gap: 0.55em,
411-
caption: none,
412-
kind: auto,
413-
supplement: none,
414-
numbering: "1",
415-
outlined: true,
416-
) = { }
417-
#let notefigure(
418-
content,
419-
reverse: false,
420-
dy: 0pt - 100%,
421-
numbered: false,
438+
/// Pass-through to ```typ #figure()```, but used to adjust the vertical position.
439+
/// -> length
422440
gap: 0.55em,
441+
/// A label to attach to the figure.
442+
/// -> none | label
423443
label: none,
444+
/// Pass-through to ```typ #figure()```.
445+
/// -> arguments
424446
..figureargs,
425447
) = (
426448
context {
@@ -451,7 +473,7 @@
451473
} else {
452474
get-right().width
453475
}
454-
let height = measure(width: width, content).height + measure(text(size: 0.8em, weight: "regular", v(gap))).height
476+
let height = measure(width: width, content).height + measure(text(size: 7.5pt, v(gap))).height
455477
if numbered {
456478
h(1.5pt, weak: true)
457479
notecounter.display(_config.get().numbering)
@@ -485,12 +507,17 @@
485507
///#set page(..page-setup(..config, book: false))
486508
///#wideblock(reverse: true)[...]
487509
///```
488-
///
489-
/// - reverse (boolean): Whether to extend into the inside/left margin instead.
490-
/// - double (boolean): Whether to extend into both margins. Cannot be combined with `reverse`.
491-
/// - body (content):
492510
/// -> content
493-
#let wideblock(reverse: false, double: false, body) = (
511+
#let wideblock(
512+
/// Whether to extend into the inside/left margin instead.
513+
/// -> boolean
514+
reverse: false,
515+
/// Whether to extend into both margins. Cannot be combined with `reverse`.
516+
/// -> boolean
517+
double: false,
518+
/// -> content
519+
body
520+
) = (
494521
context {
495522
if double and reverse {
496523
panic("Cannot be both reverse and double wide.")

0 commit comments

Comments
 (0)