Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/equate.typ
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
#let layout-line(
number: none,
number-align: none,
number-gap: .5em,
number-width: auto,
text-dir: auto,
line
Expand Down Expand Up @@ -232,12 +233,11 @@

let num = box(width: number-width, align(number-align, number))
let line-width = measure(equation(line.join(), measure: true)).width
let gap = 0.5em

layout(bounds => {
let space = if bounds.width.pt().is-infinite() {
// If we're in an unbounded container, the number is placed right next to
// the equation body, with only the `gap` as spacing.
// the equation body, with only the `number-gap` as spacing.
0pt
} else if equation-align == center {
bounds.width - line-width - 2 * number-width
Expand All @@ -247,19 +247,19 @@

let body = if number-align.x == left {
if equation-align == center {
h(-gap) + num + h(space / 2 + gap) + line.join() + h(space / 2) + hide(num)
h(-number-gap) + num + h(space / 2 + number-gap) + line.join() + h(space / 2) + hide(num)
} else if equation-align == right {
num + h(space + 2 * gap) + line.join()
num + h(space + 2 * number-gap) + line.join()
} else {
h(-gap) + num + h(gap) + line.join() + h(space + gap)
h(-number-gap) + num + h(number-gap) + line.join() + h(space + number-gap)
}
} else {
if equation-align == center {
hide(num) + h(space / 2) + line.join() + h(space / 2 + gap) + num + h(-gap)
hide(num) + h(space / 2) + line.join() + h(space / 2 + number-gap) + num + h(-number-gap)
} else if equation-align == right {
h(space + gap) + line.join() + h(gap) + num + h(-gap)
h(space + number-gap) + line.join() + h(number-gap) + num + h(-number-gap)
} else {
line.join() + h(space + 2 * gap) + num
line.join() + h(space + 2 * number-gap) + num
}
}

Expand Down Expand Up @@ -296,8 +296,7 @@
.enumerate()
.filter(((i, line)) => {
if i not in labelled { return false }
return line.last().text == "<equate:revoke>"
})
return line.last().text == "<equate:revoke>" })
.map(((i, _)) => i)

// The "revoke" label shall not count as a labelled line.
Expand Down Expand Up @@ -524,13 +523,17 @@
// - number-mode: Whether to number all lines or only lines containing a label.
// Must be either "line" or "label".
// - debug: Whether to show alignment spacers for debugging.
// - extra-show: Show rule which is applied to block equation that are layouted
// by equate.
//
// Returns: The body with the applied show rules.
#let equate(
breakable: auto,
sub-numbering: false,
number-gap: .5em,
number-mode: "line",
debug: false,
extra-show: it => it,
body
) = {
// Validate parameters.
Expand Down Expand Up @@ -644,12 +647,15 @@
// Update state to allow correct referencing.
sub-numbering-state.update(_ => sub-numbering)

layout-line(
// Apply extra-show to allow for customizing the container of
// equate's block equations.
extra-show(layout-line(
lines.first(),
number: number,
number-gap: number-gap,
number-align: number-align,
text-dir: text-dir
)
))

// Step back counter as we introducted an additional equation
// that increased the counter by one.
Expand All @@ -673,7 +679,7 @@
sub-numbering-state.update(_ => sub-numbering)

// Layout equation as grid to allow page breaks.
block(grid(
extra-show(block(grid(
columns: 1,
row-gutter: par.leading,
..realign(lines).enumerate().map(((i, line)) => {
Expand All @@ -693,11 +699,12 @@
line,
number: number,
number-align: number-align,
number-gap: number-gap,
number-width: max-number-width,
text-dir: text-dir
)
})
))
)))

// Revert equation counter step(s).
if it.numbering == none {
Expand Down