tingerrr / hydra Goto Github PK
View Code? Open in Web Editor NEWA typst package for displaying the active section in the page header or footer.
License: MIT License
A typst package for displaying the active section in the page header or footer.
License: MIT License
I'm building alternating page headers showing the current chapter on even, and the current section on odd pages. Here is a small example:
#import "@preview/hydra:0.2.0": hydra
#set heading(numbering: "1.1")
#show heading.where(level: 1): it => pagebreak(weak: true) + it
#set par(justify: true)
#set page(paper: "a7",
header: locate(loc => {
if calc.even(loc.page()) {
hydra(sel: heading.where(level: 1))
} else {
[#h(1fr)#hydra(sel: heading.where(level: 2))]
}
}),
)
= First chapter
#lorem(10)
== First chapter first section
#lorem(150)
== First chapter second section
#lorem(20)
= Second
#lorem(10)
=== Second chapter first subsection
#lorem(30)
=== Second chapter second subsection
#lorem(40)
As you can see, the header on the last page refers to First chapter first section
; but this is wrong because we're now in Second chapter
. Are you ok with a PR if I can fix this (make hydra not cross higher-level headings), or do you think waiting for the "new features for general handling of headings" is better?
Second thing, not a bug:
If you have a look at Second chapter
, what do you think about a descend-until-level: 3
option? (I felt ridiculous giving Motivation
and Outline
full section status ๐คช )
#import "@preview/hydra:0.0.1": hydra
instead of the correct #import "@preview/hydra:0.1.0": hydra
Without placement auto, hydra correctly does not display Heading 1 in the header :
But when using placement auto, the image is placed at the top and hydra interprets this as being part of section 1 :
Maybe it's related to #16.
Given a document like so:
#import "@preview/hydra:0.3.0": hydra
#let hdyra = hydra.with(paper: "a7")
#set page(
paper: "a7",
flipped: true,
width: 100pt,
header: hydra(skip-starting: false, 2),
)
= Chapter
#lorem(5)
#pagebreak()
// = Chapter
== Section
#lorem(5)
The following two pages are rendered:
If the second // = Chapter
is no longer commented out, the header on page 2 disappears. This will remain an issue until typst allows us to check the structure of the document more thoroughly to really ensure the first content of a page is the primary element, any of its ancestors or spacing/layout content.
Add a tidy generated manual and add more specific examples to explain specific use cases such as is-book
.
Given a show rule which introduces an "invisible" element such as v(...)
before the heading, the margin redundancy check fails, causing hydra
to display the last heading on a page which starts with a new heading.
#import "@preview/hydra:0.4.0": hydra
#set page(header: context hydra(1))
#set heading(numbering: "1.1")
#show heading.where(level: 1) : it => pagebreak(weak: true) + {
// uncommenting this or adding a block around this whole rule fixes the issue
// metadata(())
v(1em)
it
}
= First
#lorem(10)
= Second
#lorem(10)
#pagebreak()
#lorem(10)
To work around this, consider surrounding your headings with a container, i.e. a block
or box
, avoid using metadata
as it is likely not intended to cause the location collapse, see the upstream issue.
Upstream issue: typst#4029.
Supersedes #2.
If the margin is set to be zero-sized, hydra panics, thinking it's outside the header and there is no anchor.
With some show rules for vertical spacing on first-level headings, omitting block wrapping breaks the redundancy check. Adding the block back fixes the issue.
#import "@preview/hydra:0.2.0": hydra
#set page(header: hydra(
display: (_, it) => {
if it.numbering != none [
Chapter #counter(heading).display()
]
it.body
})
)
#set heading(numbering: "1.1")
// if the block is removed this will no longer check for redundancy correctly,
// some of the spacing also subtly changes.
#show heading.where(level: 1) : it => pagebreak(weak: true) + block({
set text(2em, weight: "bold")
v(8em)
if it.numbering != none [
Chapter #counter(heading).display()
#v(.5em)
]
it.body
v(0.5em)
})
= First
asda
= Second
a
= Third
asd
#pagebreak()
asdas
Removing the block will cause each page to reference its next section instead of the last/none.
The README lacks documentation for existence and behavior of fallback-next
.
Some users have expressed the desire to select the last heading on the current page over what hydra currently considers the active element, if one exists.
Given a document like so:
#import "@preview/hydra:0.4.0": hydra
#show heading.where(level: 1): it => pagebreak(weak: true) + it
#set page(paper: "a7", flipped: true, width: 100pt, header: context hydra(1))
= Incorrect
= Correct
#hide[.]
renders the following two pages:
Where the first page incorrectly shows the next heading. This seems to be directly correlated to typst#2631.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.