|  | 
|  | 1 | +# Outrageous | 
|  | 2 | + | 
|  | 3 | +Easier customization of outline entries. | 
|  | 4 | + | 
|  | 5 | +## Examples | 
|  | 6 | + | 
|  | 7 | +For the full source see [`examples/basic.typ`](./examples/basic.typ) and for | 
|  | 8 | +more examples see the [`examples` directory](./examples). | 
|  | 9 | + | 
|  | 10 | +### Default Style | 
|  | 11 | + | 
|  | 12 | + | 
|  | 13 | + | 
|  | 14 | +```typ | 
|  | 15 | +#import "@preview/outrageous:0.4.1" | 
|  | 16 | +#show outline.entry: outrageous.show-entry | 
|  | 17 | +``` | 
|  | 18 | + | 
|  | 19 | +### Custom Settings | 
|  | 20 | + | 
|  | 21 | + | 
|  | 22 | + | 
|  | 23 | +```typ | 
|  | 24 | +#import "@preview/outrageous:0.4.1" | 
|  | 25 | +#show outline.entry: outrageous.show-entry.with( | 
|  | 26 | +  // the typst preset retains the normal Typst appearance | 
|  | 27 | +  ..outrageous.presets.typst, | 
|  | 28 | +  // we only override a few things: | 
|  | 29 | +  // level-1 entries are italic, all others keep their font style | 
|  | 30 | +  font-style: ("italic", auto), | 
|  | 31 | +  // no fill for level-1 entries, a thin gray line for all deeper levels | 
|  | 32 | +  fill: (none, line(length: 100%, stroke: gray + .5pt)), | 
|  | 33 | +) | 
|  | 34 | +``` | 
|  | 35 | + | 
|  | 36 | +## Usage | 
|  | 37 | + | 
|  | 38 | +### `show-entry` | 
|  | 39 | + | 
|  | 40 | +Show the given outline entry with the provided styling. Should be used in a show | 
|  | 41 | +rule like `#show outline.entry: outrageous.show-entry`. | 
|  | 42 | + | 
|  | 43 | +```typ | 
|  | 44 | +#let show-entry( | 
|  | 45 | +  entry, | 
|  | 46 | +  font-weight: presets.outrageous-toc.font-weight, | 
|  | 47 | +  font-style: presets.outrageous-toc.font-style, | 
|  | 48 | +  vspace: presets.outrageous-toc.vspace, | 
|  | 49 | +  font: presets.outrageous-toc.font, | 
|  | 50 | +  fill: presets.outrageous-toc.fill, | 
|  | 51 | +  gap: presets.outrageous-toc.gap, | 
|  | 52 | +  fill-right-pad: presets.outrageous-toc.fill-right-pad, | 
|  | 53 | +  fill-align: presets.outrageous-toc.fill-align, | 
|  | 54 | +  prefix-transform: presets.outrageous-toc.prefix-transform, | 
|  | 55 | +  body-transform: presets.outrageous-toc.body-transform, | 
|  | 56 | +  page-transform: presets.outrageous-toc.page-transform, | 
|  | 57 | +  state-key: "outline-page-number-max-width", | 
|  | 58 | +) = { /* ... */ } | 
|  | 59 | +``` | 
|  | 60 | + | 
|  | 61 | +**Arguments:** | 
|  | 62 | + | 
|  | 63 | +For all the arguments that take arrays, the array's first item specifies the | 
|  | 64 | +value for all level-one entries, the second item for level-two, and so on. The | 
|  | 65 | +array's last item will be used for all deeper/following levels as well. | 
|  | 66 | + | 
|  | 67 | +- `entry`: [`content`] — The | 
|  | 68 | +  [`outline.entry`](https://typst.app/docs/reference/model/outline/#definitions-entry) | 
|  | 69 | +  element from the show rule. | 
|  | 70 | +- `font-weight`: [`array`] of ([`str`] or [`int`] or `auto` or `none`) — | 
|  | 71 | +  The entry's font weight. Setting to `auto` or `none` keeps the context's | 
|  | 72 | +  current style. | 
|  | 73 | +- `font-style`: [`array`] of ([`str`] or `auto` or `none`) — The entry's | 
|  | 74 | +  font style. Setting to `auto` or `none` keeps the context's current style. | 
|  | 75 | +- `vspace`: [`array`] of ([`relative`] or [`fraction`] or `auto` or `none`) | 
|  | 76 | +  — The vertical space above the entry. Setting to `auto` or `none` keeps | 
|  | 77 | +  the context's current setting. | 
|  | 78 | +- `font`: [`array`] of ([`str`] or [`array`] or `auto` or `none`) — The | 
|  | 79 | +  entry's font. Setting to `auto` or `none` keeps the context's current font. | 
|  | 80 | +- `fill`: [`array`] of ([`content`] or `auto` or `none`) — The entry's | 
|  | 81 | +  fill. Setting to `auto` keeps the context's current setting. | 
|  | 82 | +- `gap`: [`array`] of ([`length`] or `auto` or `none`) — The gap between | 
|  | 83 | +  the entry's prefix and body. Setting to `auto` keeps the context's current | 
|  | 84 | +  setting. Setting to `none` is the same as `0pt`. | 
|  | 85 | +- `fill-right-pad`: [`relative`] or `none` — Horizontal space to put | 
|  | 86 | +  between the fill and page number. | 
|  | 87 | +- `fill-align`: [`bool`] — Whether `fill-right-pad` should be relative to | 
|  | 88 | +  the current page number or the widest page number. Setting this to `true` has | 
|  | 89 | +  the effect of all fills ending on the same vertical line. | 
|  | 90 | +- `prefix-transform`: [`function`] or `none` — Callback for custom edits | 
|  | 91 | +  to the entry's prefix. It gets passed the entry's level ([`int`]) and prefix | 
|  | 92 | +  ([`content`]) and should return [`content`] or `none`. If `none` is returned, | 
|  | 93 | +  no modifications are made. | 
|  | 94 | +- `body-transform`: [`function`] or `none` — Callback for custom edits to | 
|  | 95 | +  the entry's body. It gets passed the entry's level ([`int`]), prefix | 
|  | 96 | +  ([`content`]) and body ([`content`]) and should return [`content`] or `none`. | 
|  | 97 | +  If `none` is returned, no modifications are made. | 
|  | 98 | +- `page-transform`: [`function`] or `none` — Callback for custom edits to | 
|  | 99 | +  the entry's page number. It gets passed the entry's level ([`int`]) and page | 
|  | 100 | +  number ([`content`]) and should return [`content`] or `none`. If `none` is | 
|  | 101 | +  returned, no modifications are made. | 
|  | 102 | +- `state-key`: [`str`] — The key to use for the internal state which | 
|  | 103 | +  tracks the maximum page number width. The state is global for the entire | 
|  | 104 | +  document and thus applies to all outlines. If you wish to re-calculate the max | 
|  | 105 | +  page number width for `fill-align`, then you must provide a different key for | 
|  | 106 | +  each outline. | 
|  | 107 | + | 
|  | 108 | +**Returns:** [`content`] | 
|  | 109 | + | 
|  | 110 | +### `presets` | 
|  | 111 | + | 
|  | 112 | +Presets for the arguments for [`show-entry()`](#show-entry). You can use them in | 
|  | 113 | +your show rule with | 
|  | 114 | +`#show outline.entry: outrageous.show-entry.with(..outrageous.presets.outrageous-figures)`. | 
|  | 115 | + | 
|  | 116 | +```typ | 
|  | 117 | +#let presets = ( | 
|  | 118 | +  // outrageous preset for a Table of Contents | 
|  | 119 | +  outrageous-toc: ( | 
|  | 120 | +    // ... | 
|  | 121 | +  ), | 
|  | 122 | +  // outrageous preset for List of Figures/Tables/Listings | 
|  | 123 | +  outrageous-figures: ( | 
|  | 124 | +    // ... | 
|  | 125 | +  ), | 
|  | 126 | +  // preset without any style changes | 
|  | 127 | +  typst: ( | 
|  | 128 | +    // ... | 
|  | 129 | +  ), | 
|  | 130 | +) | 
|  | 131 | +``` | 
|  | 132 | + | 
|  | 133 | +### `repeat` | 
|  | 134 | + | 
|  | 135 | +Utility function to repeat content to fill space with a fixed size gap. | 
|  | 136 | + | 
|  | 137 | +```typ | 
|  | 138 | +#let repeat(gap: none, justify: false, body) = { /* ... */ } | 
|  | 139 | +``` | 
|  | 140 | + | 
|  | 141 | +**Arguments:** | 
|  | 142 | + | 
|  | 143 | +- `gap`: [`length`] or `none` — The gap between repeated items. | 
|  | 144 | +- `justify`: [`bool`] — Whether to increase the gap to justify the items. | 
|  | 145 | +- `body`: [`content`] — The content to repeat. | 
|  | 146 | + | 
|  | 147 | +**Returns:** [`content`] | 
|  | 148 | + | 
|  | 149 | +### `align-helper` | 
|  | 150 | + | 
|  | 151 | +Utility function to help with aligning multiple items. | 
|  | 152 | + | 
|  | 153 | +```typ | 
|  | 154 | +#let align-helper(state-key, what-to-measure, display) = { /* ... */ } | 
|  | 155 | +``` | 
|  | 156 | + | 
|  | 157 | +**Arguments:** | 
|  | 158 | + | 
|  | 159 | +- `state-key`: [`str`] — The key to use for the [`state`] that keeps track | 
|  | 160 | +  of the maximum encountered width. | 
|  | 161 | +- `what-to-measure`: [`content`] — The content to measure at this call. | 
|  | 162 | +- `display`: [`function`] — A callback which gets passed the maximum | 
|  | 163 | +  encountered width and the width of the current item (what was given to | 
|  | 164 | +  `what-to-measure`), both as [`length`], and should return [`content`] which | 
|  | 165 | +  can make use of these widths for alignment. | 
|  | 166 | + | 
|  | 167 | +**Returns:** [`content`] | 
|  | 168 | + | 
|  | 169 | +[`str`]: https://typst.app/docs/reference/foundations/str/ | 
|  | 170 | +[`int`]: https://typst.app/docs/reference/foundations/int/ | 
|  | 171 | +[`bool`]: https://typst.app/docs/reference/foundations/bool/ | 
|  | 172 | +[`content`]: https://typst.app/docs/reference/foundations/content/ | 
|  | 173 | +[`function`]: https://typst.app/docs/reference/foundations/function/ | 
|  | 174 | +[`array`]: https://typst.app/docs/reference/foundations/array/ | 
|  | 175 | +[`relative`]: https://typst.app/docs/reference/layout/relative/ | 
|  | 176 | +[`fraction`]: https://typst.app/docs/reference/layout/fraction/ | 
|  | 177 | +[`state`]: https://typst.app/docs/reference/introspection/state/ | 
|  | 178 | +[`length`]: https://typst.app/docs/reference/layout/length/ | 
0 commit comments