summaryrefslogtreecommitdiff
path: root/tests/suite/model/figure.typ
blob: 37fb4ecdaa36b50213d016da8df1dc406b0a586e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Test figures.

--- figure-basic ---
#set page(width: 150pt)
#set figure(numbering: "I")

We can clearly see that @fig-cylinder and
@tab-complex are relevant in this context.

#figure(
  table(columns: 2)[a][b],
  caption: [The basic table.],
) <tab-basic>

#figure(
  pad(y: -6pt, image("/assets/images/cylinder.svg", height: 2cm)),
  caption: [The basic shapes.],
  numbering: "I",
) <fig-cylinder>

#figure(
  table(columns: 3)[a][b][c][d][e][f],
  caption: [The complex table.],
) <tab-complex>

--- figure-align ---
#show figure: set align(start)
#figure(
  rect[This is \ left],
  caption: [Start-aligned]
)

--- figure-table ---
// Testing figures with tables.
#figure(
  table(
    columns: 2,
    [Second cylinder],
    image("/assets/images/cylinder.svg"),
  ),
  caption: "A table containing images."
) <fig-image-in-table>

--- figure-placement ---
#set page(height: 160pt, columns: 2)
#set place(clearance: 10pt)

#lines(4)

#figure(
  placement: auto,
  scope: "parent",
  caption: [I],
  rect(height: 15pt, width: 80%),
)

#figure(
  placement: bottom,
  caption: [II],
  rect(height: 15pt, width: 80%),
)

#lines(2)

#figure(
  placement: bottom,
  caption: [III],
  rect(height: 25pt, width: 80%),
)

#figure(
  placement: auto,
  scope: "parent",
  caption: [IV],
  rect(width: 80%),
)

#lines(15)

--- figure-scope-without-placement ---
// Error: 2-27 parent-scoped placement is only available for floating figures
// Hint: 2-27 you can enable floating placement with `figure(placement: auto, ..)`
#figure(scope: "parent")[]

--- figure-theorem ---
// Testing show rules with figures with a simple theorem display
#show figure.where(kind: "theorem"): it => {
  set align(start)
  let name = none
  if not it.caption == none {
    name = [ #emph(it.caption.body)]
  } else {
    name = []
  }

  let title = none
  if not it.numbering == none {
    title = it.supplement
    if not it.numbering == none {
      title += " " +  it.counter.display(it.numbering)
    }
  }
  title = strong(title)
  pad(
    top: 0em, bottom: 0em,
    block(
      fill: green.lighten(90%),
      stroke: 1pt + green,
      inset: 10pt,
      width: 100%,
      radius: 5pt,
      breakable: false,
      [#title#name#h(0.1em):#h(0.2em)#it.body#v(0.5em)]
    )
  )
}

#set page(width: 150pt)
#figure(
  $a^2 + b^2 = c^2$,
  supplement: "Theorem",
  kind: "theorem",
  caption: "Pythagoras' theorem.",
  numbering: "1",
) <fig-formula>

#figure(
  $a^2 + b^2 = c^2$,
  supplement: "Theorem",
  kind: "theorem",
  caption: "Another Pythagoras' theorem.",
  numbering: none,
) <fig-formula>

#figure(
  ```rust
  fn main() {
    println!("Hello!");
  }
  ```,
  caption: [Hello world in _rust_],
)

--- figure-breakable ---
// Test breakable figures
#set page(height: 6em)
#show figure: set block(breakable: true)

#figure(table[a][b][c][d][e], caption: [A table])

--- figure-caption-separator ---
// Test custom separator for figure caption
#set figure.caption(separator: [ --- ])

#figure(
  table(columns: 2)[a][b],
  caption: [The table with custom separator.],
)

--- figure-caption-show ---
// Test figure.caption element
#show figure.caption: emph

#figure(
  [Not italicized],
  caption: [Italicized],
)

--- figure-caption-where-selector ---
// Test figure.caption element for specific figure kinds
#show figure.caption.where(kind: table): underline

#figure(
  [Not a table],
  caption: [Not underlined],
)

#figure(
  table[A table],
  caption: [Underlined],
)

--- figure-par ---
// Ensure that a figure body is considered a paragraph.
#show par: highlight

#figure[Text]

#figure(
  [Text],
  caption: [A caption]
)

--- figure-and-caption-show ---
// Test creating custom figure and custom caption

#let gap = 0.7em
#show figure.where(kind: "custom"): it => rect(inset: gap, {
  align(center, it.body)
  v(gap, weak: true)
  line(length: 100%)
  v(gap, weak: true)
  align(center, it.caption)
})

#figure(
  [A figure],
  kind: "custom",
  caption: [Hi],
  supplement: [A],
)

#show figure.caption: it => emph[
  #it.body
  (#it.supplement
   #context it.counter.display(it.numbering))
]

#figure(
  [Another figure],
  kind: "custom",
  caption: [Hi],
  supplement: [B],
)

--- figure-caption-position ---
#set figure.caption(position: top)

--- figure-caption-position-bad ---
// Error: 31-38 expected `top` or `bottom`, found horizon
#set figure.caption(position: horizon)

--- figure-localization-fr ---
// Test French
#set text(lang: "fr")
#figure(
  circle(),
  caption: [Un cercle.],
)

--- figure-localization-zh ---
// Test Chinese
#set text(lang: "zh")
#figure(
  rect(),
  caption: [一个矩形],
)

--- figure-localization-ru ---
// Test Russian
#set text(lang: "ru")

#figure(
    polygon.regular(size: 1cm, vertices: 8),
    caption: [Пятиугольник],
)

--- figure-localization-el ---
// Test Greek
#set text(lang: "el")
#figure(
  circle(),
  caption: [Ένας κύκλος.],
)

--- issue-2165-figure-caption-panic ---
#figure.caption[]

--- issue-2328-figure-entry-panic ---
// Error: 4-43 footnote entry must have a location
// Hint: 4-43 try using a query or a show rule to customize the footnote instead
HI#footnote.entry(clearance: 2.5em)[There]

--- issue-2530-figure-caption-panic ---
#figure(caption: [test])[].caption

--- issue-3586-figure-caption-separator ---
// Test that figure caption separator is synthesized correctly.
#show figure.caption: c => test(c.separator, [#": "])
#figure(table[], caption: [This is a test caption])

--- issue-4966-figure-float-counter ---
#let c = context counter(figure.where(kind: image)).display()
#set align(center)

#c

#figure(
  square(c),
  placement: bottom,
  caption: [A]
)

#c

#figure(
  circle(c),
  placement: top,
  caption: [B]
)

#c