Skip to content

Commit 4b152c8

Browse files
committed
smartaref:0.1.0
1 parent 120dd6a commit 4b152c8

File tree

13 files changed

+530
-0
lines changed

13 files changed

+530
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pdf
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Permission to use, copy, modify, and/or distribute this software for
2+
any purpose with or without fee is hereby granted.
3+
4+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
5+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
6+
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
7+
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
8+
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
9+
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
10+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Clever references for Typst
2+
3+
Smart handling of consecutive references (i.e. `cleveref` for Typst).
4+
5+
## Figures, tables, listings, sections, equations and footnotes example
6+
7+
See [example/example.typ](example/example.typ).
8+
9+
![Figures, tables, listings, sections, equations and footnotes example](example/example.png)
10+
11+
## Subfigures example
12+
13+
See [example/example-subfig.typ](example/example-subfig.typ).
14+
15+
![Subfigures example](example/example-subfig.png)
16+
17+
## Heading-dependent numbering of subfigures
18+
19+
See [example/example-subfig-headings.typ](example/example-subfig-headings.typ).
20+
21+
![Heading-dependent numbering of subfigures](example/example-subfig-headings.png)
22+
23+
## Subpar example
24+
25+
See [example/example-subpar.typ](example/example-subpar.typ).
26+
27+
![Subfigures example](example/example-subpar.png)
185 KB
Loading
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#set page(width: 12cm, height: auto)
2+
3+
#import "@preview/hallon:0.1.0" as hallon: subfigure
4+
#import "@preview/smartaref:0.1.0": cref, Cref
5+
6+
// Apply subfigure styles (using one heading level as figure numbering prefix,
7+
// e.g. "1.1a").
8+
#show: hallon.style-figures.with(heading-levels: 1)
9+
10+
// Set heading numbering style.
11+
#set heading(numbering: "1.1")
12+
13+
// Highlight links.
14+
#show link: set text(fill: blue)
15+
#show ref: set text(fill: blue)
16+
17+
// === [ heading dependent figure numbering ] ==================================
18+
19+
#let example-fig = rect(fill: aqua)
20+
21+
= Heading one
22+
23+
`ref`: See @fig1, @subfig1-foo and @subfig1-bar.
24+
25+
`cref`: See #cref[@fig1 @subfig1-foo @subfig1-bar].
26+
27+
#figure(
28+
grid(
29+
columns: 2,
30+
gutter: 1.5em,
31+
subfigure(
32+
example-fig,
33+
caption: [foo],
34+
label: <subfig1-foo>,
35+
),
36+
// manual placement of subfigure (figure with "subfigure" kind)
37+
[#figure(
38+
example-fig,
39+
caption: [bar],
40+
kind: "subfigure",
41+
) <subfig1-bar>],
42+
),
43+
gap: 1em,
44+
caption: lorem(5),
45+
) <fig1>
46+
47+
`ref`: See @fig2, @subfig2-foo and @subfig2-bar.
48+
49+
`cref`: See #cref(supplement: "figs.")[@fig2 @subfig2-foo @subfig2-bar].
50+
51+
#figure(
52+
grid(
53+
columns: 2,
54+
gutter: 1.5em,
55+
subfigure(
56+
example-fig,
57+
caption: [foo],
58+
label: <subfig2-foo>,
59+
),
60+
subfigure(
61+
example-fig,
62+
caption: [bar],
63+
label: <subfig2-bar>,
64+
),
65+
),
66+
gap: 1em,
67+
caption: lorem(5),
68+
) <fig2>
69+
70+
= Heading two
71+
72+
`ref`: @fig3, @subfig3-foo and @subfig3-bar are ...
73+
74+
`Cref`: #Cref[@fig3 @subfig3-foo @subfig3-bar] are ...
75+
76+
#figure(
77+
grid(
78+
columns: 2,
79+
gutter: 1.5em,
80+
subfigure(
81+
example-fig,
82+
caption: [foo],
83+
label: <subfig3-foo>,
84+
),
85+
subfigure(
86+
example-fig,
87+
caption: [bar],
88+
label: <subfig3-bar>,
89+
),
90+
),
91+
gap: 1em,
92+
caption: lorem(5),
93+
) <fig3>
94+
95+
`ref`: @fig4, @subfig4-foo and @subfig4-bar are ...
96+
97+
`Cref`: #Cref(supplement: "Figs.")[@fig4 @subfig4-foo @subfig4-bar] are ...
98+
99+
#figure(
100+
grid(
101+
columns: 2,
102+
gutter: 1.5em,
103+
subfigure(
104+
example-fig,
105+
caption: [foo],
106+
label: <subfig4-foo>,
107+
),
108+
subfigure(
109+
example-fig,
110+
caption: [bar],
111+
label: <subfig4-bar>,
112+
),
113+
),
114+
gap: 1em,
115+
caption: lorem(5),
116+
) <fig4>
55.6 KB
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#set page(width: 12cm, height: auto)
2+
3+
#import "@preview/hallon:0.1.0" as hallon: subfigure
4+
#import "@preview/smartaref:0.1.0": cref, Cref
5+
6+
// Apply subfigure styles.
7+
#show: hallon.style-figures
8+
9+
// Use short supplement for figures and subfigures.
10+
//
11+
// NOTE: place after `hallon.style-subfig` show rule for supplement of
12+
// "subfigure" kind to take effect.
13+
#show figure.where(kind: image): set figure(supplement: "Fig.")
14+
#show figure.where(kind: image): set figure.caption(separator: [. ])
15+
#show figure.where(kind: "subfigure"): set figure(supplement: "Fig.")
16+
17+
// Highlight links.
18+
#show link: set text(fill: blue)
19+
#show ref: set text(fill: blue)
20+
21+
// === [ subfigure example ] ===================================================
22+
23+
#let example-fig = rect(fill: aqua)
24+
25+
= Subfigure example
26+
27+
`ref`: See @fig-example, @subfig-example-foo and @subfig-example-bar.
28+
29+
`cref`: See #cref[@fig-example @subfig-example-foo @subfig-example-bar].
30+
31+
`Cref`: #Cref[@fig-example @subfig-example-foo @subfig-example-bar] are ...
32+
33+
#figure(
34+
grid(
35+
columns: 2,
36+
gutter: 1.5em,
37+
subfigure(
38+
example-fig,
39+
caption: [foo],
40+
label: <subfig-example-foo>,
41+
),
42+
subfigure(
43+
example-fig,
44+
caption: [bar],
45+
label: <subfig-example-bar>,
46+
),
47+
),
48+
gap: 1em,
49+
caption: lorem(5),
50+
) <fig-example>
57.8 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#set page(width: 12cm, height: auto)
2+
3+
#import "@preview/subpar:0.2.2"
4+
#import "@preview/smartaref:0.1.0": cref, Cref
5+
6+
// Highlight links.
7+
#show link: set text(fill: blue)
8+
#show ref: set text(fill: blue)
9+
10+
// === [ subpar example ] ======================================================
11+
12+
#let example-fig = rect(fill: aqua)
13+
14+
= Subpar example
15+
16+
`ref`: See @fig-example, @subfig-example-foo and @subfig-example-bar.
17+
18+
// NOTE: incorrect reference. uses "1a" for @subfig-example-bar, should be "1b".
19+
`cref`: See #cref[@fig-example @subfig-example-foo @subfig-example-bar].
20+
21+
`Cref`: #Cref[@fig-example @subfig-example-foo @subfig-example-bar] are ...
22+
23+
#subpar.grid(
24+
columns: 2,
25+
figure(
26+
example-fig,
27+
caption: [foo],
28+
), <subfig-example-foo>,
29+
figure(
30+
example-fig,
31+
caption: [bar],
32+
), <subfig-example-bar>,
33+
caption: lorem(5),
34+
label: <fig-example>,
35+
)
446 KB
Loading

0 commit comments

Comments
 (0)