|
4 | 4 | /// #internal[Mostly internal.]
|
5 | 5 | /// The counter used for the note icons.
|
6 | 6 | ///
|
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)```) |
10 | 9 | /// -> counter
|
11 | 10 | #let notecounter = counter("notecounter")
|
12 | 11 |
|
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 = ("●", "○", "◆", "◇", "■", "□", "▲", "△", "♥", "♡") |
15 | 20 |
|
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 |
28 | 22 | /// -> 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) |
35 | 52 | }
|
36 | 53 |
|
37 | 54 | ///#internal()
|
|
54 | 71 | top: config.at("top", default: 2.5cm),
|
55 | 72 | bottom: config.at("bottom", default: 2.5cm),
|
56 | 73 | book: config.at("book", default: false),
|
57 |
| - clearance: config.at("clearance", default: 8pt), |
| 74 | + clearance: config.at("clearance", default: 12pt), |
58 | 75 | flush-numbers: config.at("flush-numbers", default: false),
|
59 |
| - numbering: config.at("numbering", default: as-note), |
| 76 | + numbering: config.at("numbering", default: note-numbering), |
60 | 77 | )
|
61 | 78 | }
|
62 | 79 |
|
|
65 | 82 | /// This will update the marginalia config with the provided config options.
|
66 | 83 | ///
|
67 | 84 | /// 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`. |
83 | 85 | #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 |
84 | 95 | inner: (far: 5mm, width: 15mm, sep: 5mm),
|
| 96 | + /// Outside/right margins. Analogous to `inner`. |
| 97 | + /// -> dictionary |
85 | 98 | outer: (far: 5mm, width: 15mm, sep: 5mm),
|
| 99 | + /// Top margin. |
| 100 | + /// -> length |
86 | 101 | top: 2.5cm,
|
| 102 | + /// Bottom margin. |
| 103 | + /// -> length |
87 | 104 | 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 |
88 | 107 | book: false,
|
| 108 | + /// Minimal vertical distance between notes and to wide blocks. |
| 109 | + /// -> length |
89 | 110 | clearance: 8pt,
|
| 111 | + /// Disallow note icons hanging into the whitespace. |
| 112 | + /// -> boolean |
90 | 113 | 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, |
92 | 117 | ) = { }
|
93 | 118 | #let configure(..config) = (
|
94 | 119 | context {
|
|
101 | 126 | }
|
102 | 127 | )
|
103 | 128 |
|
104 |
| -/* Page setup helper */ |
105 |
| - |
| 129 | +/// Page setup helper |
| 130 | +/// |
106 | 131 | /// This will generate a dictionary ```typc ( margin: .. )``` compatible with the passed config.
|
107 | 132 | /// This can then be spread into the page setup like so:
|
108 | 133 | ///```typ
|
109 | 134 | /// #set page( ..page-setup(..config) )```
|
110 | 135 | ///
|
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. |
113 | 137 | /// -> 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 | +) = { |
115 | 143 | let config = _fill_config(..config)
|
116 | 144 | if config.book {
|
117 | 145 | return (
|
|
322 | 350 |
|
323 | 351 | /// Create a marginnote.
|
324 | 352 | /// 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") |
331 | 368 | if numbered {
|
332 | 369 | notecounter.step()
|
333 | 370 | 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) |
336 | 372 | notecounter.display(_config.get().numbering)
|
337 | 373 | h(1.5pt)
|
338 | 374 | body
|
339 | 375 | } 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) |
342 | 377 | box(
|
343 | 378 | width: 0pt,
|
344 | 379 | {
|
|
372 | 407 | } else {
|
373 | 408 | h(0pt, weak: true)
|
374 | 409 | 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) |
377 | 411 | body
|
378 | 412 | }
|
379 | 413 | box(context {
|
|
387 | 421 | }
|
388 | 422 |
|
389 | 423 | /// 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()```. |
403 | 424 | /// -> content
|
404 | 425 | #let notefigure(
|
| 426 | + /// The figure content, e.g.~an image. Pass-through to ```typ #figure()```, but used to adjust the vertical position. |
| 427 | + /// -> content |
405 | 428 | content,
|
| 429 | + /// Put the notefigure in the opposite margin. |
| 430 | + /// -> boolean |
406 | 431 | reverse: false,
|
| 432 | + /// How much to shift the note. ```typc 100%``` corresponds to the height of `content` + `gap`. |
| 433 | + /// -> relative length |
407 | 434 | dy: 0pt - 100%,
|
| 435 | + /// Whether to put a mark. |
| 436 | + /// -> boolean |
408 | 437 | 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 |
422 | 440 | gap: 0.55em,
|
| 441 | + /// A label to attach to the figure. |
| 442 | + /// -> none | label |
423 | 443 | label: none,
|
| 444 | + /// Pass-through to ```typ #figure()```. |
| 445 | + /// -> arguments |
424 | 446 | ..figureargs,
|
425 | 447 | ) = (
|
426 | 448 | context {
|
|
451 | 473 | } else {
|
452 | 474 | get-right().width
|
453 | 475 | }
|
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 |
455 | 477 | if numbered {
|
456 | 478 | h(1.5pt, weak: true)
|
457 | 479 | notecounter.display(_config.get().numbering)
|
|
485 | 507 | ///#set page(..page-setup(..config, book: false))
|
486 | 508 | ///#wideblock(reverse: true)[...]
|
487 | 509 | ///```
|
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): |
492 | 510 | /// -> 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 | +) = ( |
494 | 521 | context {
|
495 | 522 | if double and reverse {
|
496 | 523 | panic("Cannot be both reverse and double wide.")
|
|
0 commit comments