Skip to content

Commit

Permalink
Add overrides for easier control of sub figure layout
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Apr 19, 2024
1 parent 48371b7 commit dca96d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Above in @full, we see a figure which is composed of 2 other figures, namely @a
## Known Issues
- [x] Relative numbering is incorrect for super-figures, see [#1]
- [ ] Supplement is always "Figure", regardless of `text.lang`, see: [#2]
- [ ] Figure show rule cannot be easily reconfigured
- [x] Figure show rule cannot be easily reconfigured

## TODO
The following tasks remain before the first version of subpar is released:
- [x] documentation
- [ ] manual generation
- [ ] allow more control over figure layout
- [x] allow more control over figure layout
- [ ] add convenient warppers for common types of super figures
- [x] add input validation
- [ ] add a more comprehensive test suite
Expand Down
24 changes: 19 additions & 5 deletions src/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
/// - outlined-sub (bool): Whether the sub figures should appear in an outline
/// of figures.
/// - label: The label to attach to this super figure.
/// - show-sub (function, auto): A show rule override for sub figures. Recevies
/// the sub figure.
/// - show-sub-caption (function, auto): A show rule override for sub figure's
/// captions. Receives the realized numbering and caption element.
/// -> content
#let subpar(
kind: image,
Expand All @@ -47,6 +51,9 @@
outlined-sub: false,
label: none,

show-sub: auto,
show-sub-caption: auto,

body,
) = {
_pkg.t4t.assert.any-type(str, function, kind)
Expand All @@ -63,6 +70,16 @@
_pkg.t4t.assert.any-type(bool, outlined-sub)
_pkg.t4t.assert.any-type(_label, label)

_pkg.t4t.assert.any-type(function, type(auto), show-sub)
_pkg.t4t.assert.any-type(function, type(auto), show-sub-caption)

show-sub = _pkg.t4t.def.if-auto(it => it, show-sub)
show-sub-caption = _pkg.t4t.def.if-auto((num, it) => {
num
[ ]
it.body
}, show-sub-caption)

context {
let n-super = counter(figure.where(kind: kind)).get().first() + 1

Expand Down Expand Up @@ -92,13 +109,10 @@
placement: none,
)

show figure: show-sub
show figure: it => {
let n-sub = sub-figure-counter.get().first() + 1
show figure.caption: it => {
_numbering(numbering-sub, n-sub)
[ ]
it.body
}
show figure.caption: show-sub-caption.with(_numbering(numbering-sub, n-sub))

sub-figure-counter.step()
it
Expand Down

0 comments on commit dca96d4

Please sign in to comment.