11# hydra
2- Hydra is a [ typst] package allowing you to easily display the current section anywhere in your
3- document. In short it will show you the current section only when you need to know it, that is
4- when the last section still has remainig text but it's heading is nowhere to be seen.
2+ Hydra is a [ typst] package allowing you to easily display the heading like elements anywhere in your
3+ document. In short, it will show you the currently active element only when it is not visible.
54
6- By default hydra also assumes that you use ` a4 ` page size and margin, see its named parameters
7- to adjust this.
8-
9- ## Note on API
10- The current API is subject to change in the next version when new features for general handling of
11- headings is added.
5+ Some of hydra's features rely on the size of the top-margin, if you use a different page size than
6+ ` a4 ` or a custom top margin for your pages, make sure to configure hydra, otherwise those cheks may
7+ not work.
128
139## Example
1410``` typst
15- #import "@preview/hydra:0.2 .0": hydra
11+ #import "@preview/hydra:0.3 .0": hydra
1612
1713#set page(header: hydra() + line(length: 100%))
1814#set heading(numbering: "1.1")
@@ -39,60 +35,33 @@ headings is added.
3935![ ex5]
4036
4137## Documentation
42- Changing the default behavior can be done using the various named parameters:
43- ``` typst
44- #let hydra(
45- sel: heading, // the elements to consider
46- prev-filter: (ctx, p, n) => true, // check if the last element is eligible
47- next-filter: (ctx, p, n) => true, // check if the next element is eligible
48- display: core.display, // displays the eligible element
49- fallback-next: false, // fallback to the next heading if necessary
50- binding: none, // whether the redundancy check should be book binding aware
51- paper: "a4", // the paper size to use
52- page-size: auto, // the smaller page size if set
53- top-margin: auto, // the top margin is set
54- loc: none, // a location from which to search
55- ) = {
56- ...
57- }
38+ For a more in-depth description of hydra's functionality and the reference read its [ manual] .
39+
40+ ## Contribution
41+ ### Testing
42+ This package serves as my real-world test for [ ` typst-test ` ] [ typst-test ] , it is not required for
43+ contributions, but encouraged as it speeds up the review process.
44+
45+ Other than that tests can be run using the following command structure for each test:
46+ ``` bsh
47+ test=...
48+ typst --root . "tests/typ/${test}.typ" "tests/out/${test}/{n}.png"
49+ # some command to compare images in tests/ref/${test} and tests/out/${test}
5850```
5951
60- ` sel ` can be a ` selector ` /` element ` , or a tuple of (` selector ` /` element ` , ` function ` ), where the
61- function is used in querying this is mainly useful for selecting ranges of headings without building
62- a complicated selector ` (heading, (ctx, h) => h.level in (1, 2, 3)) ` . This function is executed for
63- each matching element in your document.
64-
65- ` loc ` can be used in contexts where location is already known, this avoids a call to ` locate ` ,
66- allowing you to inspect the result of ` display ` directly.
67-
68- ` prev-filter ` and ` next-filter ` are used to check if an element is eligible for being displayed.
69- They receive the ` context ` , the previous and next element relative to the given ` loc ` , the element
70- that is checked for is not ` none ` , but the other may be. These functions are executed at most once.
71-
72- If ` binding ` is set to ` left ` /` right ` , it will not display the element if it is visible on the
73- previous open page. This means for a book with ` left ` binding, if hydra is used on the right page
74- while the previous section is visible on the left page, it will display nothing. Does nothing on
75- ` none ` .
76-
77- To display the current section even if it's right at the top of the page, set ` fallback-next ` to
78- ` true ` , this will, if no previous section is eligible, display the next one if it is.
79-
80- Of ` paper ` , ` page-size ` and ` top-margin ` exactly one must be given. ` paper ` and ` page-size ` are for
81- convenience and will be used to calculate the ` top-margin ` for you. Use them as follows:
82-
83- 1 . If you use a custom top margin, pass it to ` top-margin `
84- 2 . If you use no custom top margin but a custom page size, pass the * smaller* page size to
85- ` page-size `
86- 3 . If you use no custom top margin or page size, but a custom paper, pass it ` paper `
87-
88- ### Anywhere but the header
89- To use the hydra function out side of the header of your doc while retaining its behavior, place the
90- ` hydra-anchor() ` in the header of your document, it'll use this to search as if it was used in the
91- header itself.
52+ ## Examples and manual
53+ Furthermore, I use [ ` just ` ] [ just ] and [ ` nushell ` ] [ nushell ] to run common commands. It's once again
54+ not required, as I'll generate those myself if you don't on a PR, but if you already use both you
55+ can run the example and manual generation using ` just gen ` .
9256
9357[ ex1 ] : examples/example1.png
9458[ ex2 ] : examples/example2.png
9559[ ex3 ] : examples/example3.png
9660[ ex4 ] : examples/example4.png
9761[ ex5 ] : examples/example5.png
62+ [ manual ] : docs/manual.pdf
63+
9864[ typst ] : https://github.com/typst/typst
65+ [ typst-test ] : https://github.com/tingerrr/typst-test
66+ [ just ] : https://just.systems/
67+ [ nushell ] : https://www.nushell.sh/
0 commit comments