-
Notifications
You must be signed in to change notification settings - Fork 29
/
template.typ
250 lines (214 loc) · 6.16 KB
/
template.typ
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
#let script-size = 7.97224pt
#let footnote-size = 8.50012pt
#let small-size = 9.24994pt
#let normal-size = 10.00002pt
#let large-size = 11.74988pt
// This function gets your whole document as its `body` and formats
// it as an article in the style of the American Mathematical Society.
#let ams-article(
// The article's title.
title: [Paper title],
// An array of authors. For each author you can specify a name,
// department, organization, location, and email. Everything but
// but the name is optional.
authors: (),
// Your article's abstract. Can be omitted if you don't have one.
abstract: none,
// The article's paper size. Also affects the margins.
paper-size: "us-letter",
// The path to a bibliography file if you want to cite some external
// works.
bibliography-file: none,
// The document's content.
body,
) = {
// Formats the author's names in a list with commas and a
// final "and".
let names = authors.map(author => author.name)
let author-string = if authors.len() == 2 {
names.join(" and ")
} else {
names.join(", ", last: ", and ")
}
// Set document metadata.
set document(title: title, author: names)
// Set the body font. AMS uses the LaTeX font.
set text(size: normal-size, font: "New Computer Modern")
// Configure the page.
set page(
paper: paper-size,
// The margins depend on the paper size.
margin: if paper-size != "a4" {
(
top: (116pt / 279mm) * 100%,
left: (126pt / 216mm) * 100%,
right: (128pt / 216mm) * 100%,
bottom: (94pt / 279mm) * 100%,
)
} else {
(
top: 117pt,
left: 118pt,
right: 119pt,
bottom: 96pt,
)
},
// The page header should show the page number and list of
// authors, except on the first page. The page number is on
// the left for even pages and on the right for odd pages.
header-ascent: 14pt,
header: locate(loc => {
let i = counter(page).at(loc).first()
if i == 1 { return }
set text(size: script-size)
grid(
columns: (6em, 1fr, 6em),
if calc.even(i) [#i],
align(center, upper(
if calc.odd(i) { title } else { author-string }
)),
if calc.odd(i) { align(right)[#i] }
)
}),
// On the first page, the footer should contain the page number.
footer-descent: 12pt,
footer: locate(loc => {
let i = counter(page).at(loc).first()
if i == 1 {
align(center, text(size: script-size, [#i]))
}
})
)
// Configure headings.
set heading(numbering: "1.")
show heading: it => {
// Create the heading numbering.
let number = if it.numbering != none {
counter(heading).display(it.numbering)
h(7pt, weak: true)
}
// Level 1 headings are centered and smallcaps.
// The other ones are run-in.
set text(size: normal-size, weight: 400)
if it.level == 1 {
set align(center)
set text(size: normal-size)
smallcaps[
#v(15pt, weak: true)
#number
#it.body
#v(normal-size, weak: true)
]
counter(figure.where(kind: "theorem")).update(0)
} else {
v(11pt, weak: true)
number
let styled = if it.level == 2 { strong } else { emph }
styled(it.body + [. ])
h(7pt, weak: true)
}
}
// Configure lists and links.
set list(indent: 24pt, body-indent: 5pt)
set enum(indent: 24pt, body-indent: 5pt)
show link: set text(font: "New Computer Modern Mono")
// Configure equations.
show math.equation: set block(below: 8pt, above: 9pt)
show math.equation: set text(weight: 400)
// Configure citation and bibliography styles.
set bibliography(style: "springer-mathphys", title: [References])
show figure: it => {
show: pad.with(x: 23pt)
set align(center)
v(12.5pt, weak: true)
// Display the figure's body.
it.body
// Display the figure's caption.
if it.has("caption") {
// Gap defaults to 17pt.
v(if it.has("gap") { it.gap } else { 17pt }, weak: true)
smallcaps(it.supplement)
if it.numbering != none {
[ ]
it.counter.display(it.numbering)
}
[. ]
it.caption.body
}
v(15pt, weak: true)
}
// Theorems.
show figure.where(kind: "theorem"): it => block(above: 11.5pt, below: 11.5pt, {
strong({
it.supplement
if it.numbering != none {
[ ]
counter(heading).display()
it.counter.display(it.numbering)
}
[.]
})
emph(it.body)
})
// Display the title and authors.
v(35pt, weak: true)
align(center, upper({
text(size: large-size, weight: 700, title)
v(25pt, weak: true)
text(size: footnote-size, author-string)
}))
// Configure paragraph properties.
set par(first-line-indent: 1.2em, justify: true, leading: 0.58em)
show par: set block(spacing: 0.58em)
// Display the abstract
if abstract != none {
v(20pt, weak: true)
set text(script-size)
show: pad.with(x: 35pt)
smallcaps[Abstract. ]
abstract
}
// Display the article's contents.
v(29pt, weak: true)
body
// Display the bibliography, if any is given.
if bibliography-file != none {
show bibliography: set text(8.5pt)
show bibliography: pad.with(x: 0.5pt)
bibliography(bibliography-file)
}
// The thing ends with details about the authors.
show: pad.with(x: 11.5pt)
set par(first-line-indent: 0pt)
set text(7.97224pt)
for author in authors {
let keys = ("department", "organization", "location")
let dept-str = keys
.filter(key => key in author)
.map(key => author.at(key))
.join(", ")
smallcaps(dept-str)
linebreak()
if "email" in author [
_Email address:_ #link("mailto:" + author.email) \
]
if "url" in author [
_URL:_ #link(author.url)
]
v(12pt, weak: true)
}
}
// The ASM template also provides a theorem function.
#let theorem(body, numbered: true) = figure(
body,
kind: "theorem",
supplement: [Theorem],
numbering: if numbered { "1" },
)
// And a function for a proof.
#let proof(body) = block(spacing: 11.5pt, {
emph[Proof.]
[ ] + body
h(1fr)
box(scale(160%, origin: bottom + right, sym.square.stroked))
})