-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify inner representation which allows for relative numbering.
- Loading branch information
Showing
9 changed files
with
139 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,5 @@ | ||
#import "util.typ" as _util | ||
|
||
#let keys = ( | ||
superfigure: "__subpar:superfigure-unprepared", | ||
counter: "__subpar:subfigure-counter", | ||
) | ||
|
||
#let subfigure-counter = counter(keys.counter) | ||
|
||
#let apply-for-all( | ||
values, | ||
rule, | ||
) = outer => { | ||
show: inner => { | ||
values.map(rule).fold(inner, (acc, f) => f(acc)) | ||
} | ||
|
||
outer | ||
} | ||
|
||
#let super-figure-unprepared( | ||
kind: image, | ||
numbering-sub: "(a)", | ||
numbering-sub-ref: "1a", | ||
numbering-super: "1", | ||
// TODO: somehow resolve this as good as we can for common kinds and for more languages | ||
supplement: [Figure], | ||
caption: none, | ||
placement: none, | ||
gap: 0.65em, | ||
outlined: true, | ||
body, | ||
) = figure( | ||
kind: keys.superfigure, | ||
placement: placement, | ||
caption: caption, | ||
supplement: supplement, | ||
gap: gap, | ||
outlined: outlined, | ||
_util.embed-payload( | ||
kind: kind, | ||
numbering-sub: numbering-sub, | ||
numbering-sub-ref: numbering-sub-ref, | ||
numbering-super: numbering-super, | ||
body | ||
), | ||
) | ||
|
||
#let super-figure-prepared( | ||
kind-super: image, | ||
kinds-sub: (image, raw, table), | ||
|
||
numbering-sub: "(a)", | ||
numbering-sub-ref: "1a", | ||
numbering-super: "1", | ||
|
||
supplement: none, | ||
caption: none, | ||
placement: none, | ||
gap: 0.65em, | ||
outlined-super: true, | ||
outlined-sub: false, | ||
body, | ||
) = { | ||
let n-super = counter(figure.where(kind: kind-super)).get().first() + 1 | ||
|
||
figure( | ||
kind: kind-super, | ||
numbering: _ => numbering(numbering-super, n-super), | ||
supplement: supplement, | ||
caption: caption, | ||
placement: placement, | ||
gap: gap, | ||
outlined: outlined-super, | ||
{ | ||
show: apply-for-all( | ||
kinds-sub, | ||
kind => body => { | ||
show figure.where(kind: kind): set figure(numbering: _ => numbering( | ||
numbering-sub-ref, n-super, subfigure-counter.get().first() + 1 | ||
)) | ||
body | ||
} | ||
) | ||
|
||
set figure(supplement: supplement, outlined: outlined-sub, placement: none) | ||
set figure.caption(separator: none) | ||
|
||
show figure: it => { | ||
let n-sub = subfigure-counter.get().first() + 1 | ||
show figure.caption: it => { | ||
numbering(numbering-sub, n-sub) | ||
it.separator | ||
[ ] | ||
it.body | ||
} | ||
|
||
subfigure-counter.step() | ||
it | ||
counter(figure.where(kind: it.kind)).update(n => n - 1) | ||
} | ||
|
||
subfigure-counter.update(0) | ||
body | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,72 @@ | ||
#import "core.typ" | ||
#import "util.typ" | ||
|
||
#let super-figure = core.super-figure-unprepared | ||
#let super-figure( | ||
kind-super: image, | ||
kinds-sub: (image, raw, table), | ||
|
||
numbering-sub: "(a)", | ||
numbering-sub-ref: "1a", | ||
numbering-super: "1", | ||
|
||
// TODO: somehow resolve this as good as we can for common kinds and for more languages | ||
supplement: [Figure], | ||
caption: none, | ||
placement: none, | ||
gap: 0.65em, | ||
outlined-super: true, | ||
outlined-sub: false, | ||
label: none, | ||
body, | ||
) = context { | ||
let n-super = counter(figure.where(kind: kind-super)).get().first() + 1 | ||
|
||
[#figure( | ||
kind: kind-super, | ||
numbering: _ => numbering(numbering-super, n-super), | ||
supplement: supplement, | ||
caption: caption, | ||
placement: placement, | ||
gap: gap, | ||
outlined: outlined-super, | ||
{ | ||
show: util.apply-for-all( | ||
kinds-sub, | ||
kind => body => { | ||
show figure.where(kind: kind): set figure(numbering: _ => numbering( | ||
numbering-sub-ref, n-super, core.subfigure-counter.get().first() + 1 | ||
)) | ||
body | ||
} | ||
) | ||
|
||
set figure(supplement: supplement, outlined: outlined-sub, placement: none) | ||
set figure.caption(separator: none) | ||
|
||
show figure: it => { | ||
let n-sub = core.subfigure-counter.get().first() + 1 | ||
show figure.caption: it => { | ||
numbering(numbering-sub, n-sub) | ||
it.separator | ||
[ ] | ||
it.body | ||
} | ||
|
||
core.subfigure-counter.step() | ||
it | ||
counter(figure.where(kind: it.kind)).update(n => n - 1) | ||
} | ||
|
||
core.subfigure-counter.update(0) | ||
body | ||
}, | ||
)#label] | ||
} | ||
|
||
#let subpar( | ||
sub-figure-kinds: (image, raw, table), | ||
outline-subfigures: false, | ||
body, | ||
) = { | ||
show figure.where(kind: core.keys.superfigure): it => { | ||
let payload = util.extract-payload(it.body) | ||
|
||
core.super-figure-prepared( | ||
kind-super: payload.kind, | ||
kinds-sub: sub-figure-kinds, | ||
|
||
numbering-sub: payload.numbering-sub, | ||
numbering-sub-ref: payload.numbering-sub-ref, | ||
numbering-super: payload.numbering-super, | ||
|
||
supplement: it.supplement, | ||
caption: if it.caption != none { it.caption.body }, | ||
placement: it.placement, | ||
gap: it.gap, | ||
outlined-super: it.outlined, | ||
outlined-sub: outline-subfigures, | ||
it.body, | ||
) | ||
} | ||
|
||
// TODO: outline adjustement | ||
|
||
show ref: it => { | ||
if util.is-element(it.element, figure) and it.element.kind == core.keys.superfigure { | ||
let payload = util.extract-payload(it.element.body) | ||
link(it.element.location(), { | ||
it.element.supplement | ||
[ ] | ||
numbering( | ||
// TODO: this is executed in the wrong context, which is the only blocker for relative numbering, see #1 | ||
payload.numbering-super, | ||
counter(figure.where(kind: payload.kind)).at(it.element.location()).first() + 1 | ||
) | ||
}) | ||
} else { | ||
it | ||
} | ||
} | ||
|
||
body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#import "/test/util.typ": * | ||
|
||
#import "/src/lib.typ": subpar, super-figure | ||
#show: subpar | ||
|
||
#let sub-figure-numbering = (super, sub) => numbering("1.1a", counter(heading).get().first(), super, sub) | ||
#let figure-numbering = super => numbering("1.1", counter(heading).get().first(), super) | ||
|
||
#set heading(numbering: "1.1") | ||
#show heading.where(level: 1): it => counter(figure.where(kind: image)).update(0) + it | ||
#show figure.where(kind: image): set figure(numbering: figure-numbering) | ||
|
||
#let super-figure = super-figure.with( | ||
numbering-sub-ref: sub-figure-numbering, | ||
numbering-super: figure-numbering, | ||
) | ||
|
||
#outline(target: figure.where(kind: image)) | ||
|
||
= Chapter | ||
|
||
#figure(fake-image, caption: [aaa]) | ||
|
||
#super-figure( | ||
grid(columns: (1fr, 1fr), | ||
[#figure(fake-image, caption: [Inner caption]) <a>], | ||
[#figure(fake-image, caption: [Inner caption]) <b>], | ||
), | ||
caption: [Outer caption], | ||
label: <full1>, | ||
) | ||
|
||
#figure( | ||
fake-image, | ||
caption: [aaa], | ||
) | ||
|
||
#super-figure( | ||
grid(columns: (1fr, 1fr), | ||
[#figure(`adas`, caption: [Inner caption]) <c>], | ||
[#figure(fake-image, caption: [Inner caption]) <d>], | ||
), | ||
caption: [Outer caption], | ||
label: <full2>, | ||
) | ||
|
||
= Another Chapter | ||
|
||
#figure( | ||
fake-image, | ||
caption: [aaa], | ||
) | ||
|
||
See @full1, @a and @b. | ||
|
||
See also @full2, @c and @d. |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters