fix: reference numbering

This commit is contained in:
Kristofers Solo 2025-08-26 15:11:42 +03:00
parent ebd6bb8113
commit 3e4719c17b
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
2 changed files with 51 additions and 45 deletions

View File

@ -153,7 +153,7 @@ Skatīt @dpd-0
) <dpd-1> ) <dpd-1>
=== Funkciju sadalījums moduļos === Funkciju sadalījums moduļos
Funkciju sadalījums moduļos ir aprakstīts tabulā (@function-modules[tab]). Funkciju sadalījums moduļos ir aprakstīts tabulā (@function-modules[tab.]).
#figure( #figure(
caption: "Funkciju sadalījums pa moduļiem", caption: "Funkciju sadalījums pa moduļiem",

View File

@ -1,4 +1,3 @@
#import "@preview/headcount:0.1.0": *
#import "utils.typ": make-abstract, make-documentary-page, make-title #import "utils.typ": make-abstract, make-documentary-page, make-title
#let indent = 1cm #let indent = 1cm
@ -38,6 +37,7 @@
place: none, place: none,
logo: none, logo: none,
outline-title: "SATURS", outline-title: "SATURS",
attachments: none,
body, body,
) = { ) = {
// Set document metadata. // Set document metadata.
@ -77,21 +77,6 @@
// show math.equation: set text(weight: 400) // show math.equation: set text(weight: 400)
// Configure appearance of equation references
show ref: it => {
if it.element != none and it.element.func() == math.equation {
// Override equation references.
link(it.element.location(), numbering(
it.element.numbering,
..counter(math.equation).at(it.element.location()),
))
} else {
// Other references as usual.
it
}
}
// Configure lists and terms. // Configure lists and terms.
set list(marker: ([•], [--], [\*], [·])) set list(marker: ([•], [--], [\*], [·]))
set enum(numbering: "1aiA)") set enum(numbering: "1aiA)")
@ -117,15 +102,27 @@
set quote(block: true) set quote(block: true)
// Tables & figures // Tables & figures
show heading.where(level: 1): it => {
let kinds = query(figure).map(fig => fig.kind).dedup()
for kind in kinds {
counter(figure.where(kind: kind)).update(0)
}
it
}
set figure(numbering: it => {
let count = counter(heading).get()
numbering("1.1.", count.first(), it)
})
show figure: set block(breakable: true) // allow for tables to span to next pages mid sentence show figure: set block(breakable: true) // allow for tables to span to next pages mid sentence
show figure: set par(justify: false) // disable justify for figures (tables) show figure: set par(justify: false) // disable justify for figures (tables)
show figure.caption: set align(end)
show table.cell.where(y: 0): strong show table.cell.where(y: 0): strong
set table(align: left) set table(align: left)
show figure: set image(width: 80%)
set figure(numbering: dependent-numbering("1.1.")) show figure: set image(width: 80%)
show figure: set figure.caption(position: top, separator: " ") show figure: set figure.caption(position: top, separator: " ")
show figure.caption: set align(end)
show figure.where(kind: image): set figure(supplement: "att") show figure.where(kind: image): set figure(supplement: "att")
show figure.caption.where(kind: image): set align(start) show figure.caption.where(kind: image): set align(start)
@ -134,10 +131,8 @@
position: bottom, position: bottom,
separator: ". ", separator: ". ",
) )
show heading: reset-counter(counter(figure.where(kind: image)))
show figure.where(kind: table): set figure(supplement: "tabula") show figure.where(kind: table): set figure(supplement: "tabula")
show heading: reset-counter(counter(figure.where(kind: table)))
show figure.where(kind: "attachment"): set figure(numbering: "1.1.") show figure.where(kind: "attachment"): set figure(numbering: "1.1.")
show figure.where(kind: "attachment"): set figure.caption(separator: ". ") show figure.where(kind: "attachment"): set figure.caption(separator: ". ")
@ -158,9 +153,6 @@
fig fig
} }
// disable default reference suppliments
// set ref(supplement: it => {})
// Custom show rule for references // Custom show rule for references
show ref: it => { show ref: it => {
let el = it.element let el = it.element
@ -168,38 +160,51 @@
return it return it
} }
let numbers = numbering( let numbers = numbering(
el.numbering, el.numbering,
..counter(el.func()).at(el.location()), ..counter(el.func()).at(el.location()),
) )
// return el.supplement // Handle math equations
// (No supplement handling needed)
if el.func() == math.equation {
if el.func() == heading { return link(it.element.location(), numbers)
return link(
el.location(),
[#numbers #el.body],
)
} }
let get-supplement(default) = {
let supplement = if type(it.supplement) == content { if type(it.supplement) == content {
// supplement provided by user // Supplement provided by user in the ref, e.g., ref(..., supplement: "foo")
if it.supplement == [] { if it.supplement == [] {
"" // empty supplement return ""
} else { }
[~#it.supplement.] return [~#it.supplement]
} }
} else { // Fallback to the figure's default supplement, e.g., figure(..., supplement: "att.")
// fallback to default [~#default]
[~#el.supplement.]
} }
if el.func() == figure { // Handle headings
// (With supplement handling)
if el.func() == heading {
let supplement = get-supplement(el.body)
return link(el.location(), [#numbers#supplement]) return link(el.location(), [#numbers#supplement])
} }
// Handle figures
// (With supplement handling)
if el.func() == figure {
// Override figure references.
let chap = counter(heading).at(el.location()).first()
let fig_num = counter(figure.where(kind: el.kind))
.at(el.location())
.first()
let numbers = numbering("1.1.", chap, fig_num)
let supplement = get-supplement(el.supplement)
return link(el.location(), [#numbers#supplement])
}
it it
} }
@ -254,6 +259,7 @@
// Display bibliography. // Display bibliography.
bibliography bibliography
make-documentary-page( make-documentary-page(
title, title,
authors, authors,