summaryrefslogtreecommitdiff
path: root/tests/typ/meta/ref.typ
blob: 2bed2125b7567640bc5cac02b738357e02443a9d (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
// Test references.

---
#set heading(numbering: "1.")

= Introduction <intro>
See @setup.

== Setup <setup>
As seen in @intro, we proceed.

---
// Error: 1-5 label does not exist in the document
@foo

---
= First <foo>
= Second <foo>

// Error: 1-5 label occurs multiple times in the document
@foo

---

#show ref: it => {
  if it.element != none and it.element.func() == figure {
    let element = it.element
    "["
    element.supplement
    "-"
    str(element.counter.at(element.location()).at(0))
    "]"
    // it
  } else {
    it
  }
}

#figure(
  image("/cylinder.svg", height: 3cm),
  caption: [A sylinder.],
  supplement: "Fig",
) <fig1>

#figure(
  image("/tiger.jpg", height: 3cm),
  caption: [A tiger.],
  supplement: "Figg",
) <fig2>

#figure(
  $ A = 1 $,
  kind: "equation",
  supplement: "Equa",

) <eq1>
@fig1

@fig2

@eq1

---
#set heading(numbering: (..nums) => {
  nums.pos().map(str).join(".")
  }, supplement: [Chapt])

#show ref: it => {
  if it.element != none and it.element.func() == heading {
    let element = it.element
    "["
    emph(element.supplement)
    "-"
    numbering(element.numbering, ..counter(heading).at(element.location()))
    "]"
  } else {
    it
  }
}

= Introduction <intro>

= Summary <sum>

== Subsection <sub>

@intro

@sum

@sub

---

#show ref: it => {
  if it.element != none {
    if it.element.func() == text {
      let element = it.element
      "["
      element
      "]"
    } else if it.element.func() == underline {
      let element = it.element
      "{"
      element
      "}"
    } else {
      it
    }
  } else {
    it
  }
}

@txt

Ref something unreferable <txt>

@under
#underline[
Some underline text.
] <under>