-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.typ
More file actions
369 lines (322 loc) · 11.2 KB
/
main.typ
File metadata and controls
369 lines (322 loc) · 11.2 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#import "lib.typ" as theoretic
#import "@preview/tidy:0.4.3"
#import "tidy-style.typ"
#set par(justify: true, linebreaks: "optimized")
#set text(fill: luma(30), size: 10pt)
#show raw: set text(font: ("Iosevka Term", "IBM Plex Mono", "DejaVu Sans Mono"), size: 1.25 * 0.8em)
#set heading(numbering: "1.1")
#show heading.where(level: 3): set heading(numbering: none)
#show heading.where(level: 4): set heading(numbering: none)
#set table(inset: 7pt, stroke: (0.5pt + luma(90%)))
#show table: set align(left)
#show table.cell.where(y: 0): smallcaps
#set page(
numbering: "1",
columns: 1,
margin: (
x: 2cm,
),
footer: align(center)[#context counter(page).display(page.numbering)], // why is this necessary? idk???
)
/// Balance columns
#let balance(content) = layout(size => {
let count = content.at("count")
let textheight = measure(content, width: size.width).height / count
// block(height: textheight / count, fill: blue, content)
let height = measure(content, height: textheight + 8pt, width: size.width).height
block(height: height, content)
})
#import theoretic.presets.basic: *
#show ref: theoretic.show-ref
#let code-example = tidy.styles.default.show-example.with(
scope: (theoretic: theoretic),
// preamble: "#import theoretic.presets.basic: *\n",
scale-preview: 100%,
)//, dir: ttb)
#let code-example-basic = code-example.with(preamble: "#import theoretic.presets.basic: *\n")
#let VERSION = "0.3.1"
#set document(
author: "nleanba",
title: "Theoretic 0.3.1",
)
#v(2em)
#title[#text(size: 30pt, weight: "regular")[Theoretic #text(fill: luma(50%), VERSION)]]
#v(2em)
#heading(outlined: false, numbering: none)[Contents]
#{
set par(justify: false)
let indents = (0pt, 15pt, 37pt)
let hang-indents = (15pt, 22pt, 54pt)
let text-styles = ((weight: 700, size: 10pt), (size: 10pt), (size: 9pt, weight: 500), (size: 9pt, fill: luma(20%)))
let outline-entry = theoretic.toc-entry.with(
indent: level => { indents.at(level - 1) },
hanging-indent: level => { hang-indents.at(level - 1) },
fmt-prefix: (prefix, level, _s) => {
set text(..text-styles.at(level - 1), number-width: "tabular")
prefix
h(4pt)
},
fmt-body: (body, level, _s) => {
set text(..text-styles.at(level - 1))
body
},
fmt-fill: (level, _s) => {
if level == 2 {
set text(..text-styles.at(2))
box(width: 1fr, align(right, repeat(gap: 9pt, justify: false, [.])))
}
},
fmt-page: (page, level, _s) => {
set text(..text-styles.at(level - 1), number-width: "tabular")
box(width: 18pt, align(right, [#page]))
},
above: level => {
if level == 1 {
10pt
} else {
5pt
}
},
below: auto,
)
balance(columns(2, theoretic.toc(toc-entry: outline-entry)))
}
#show link: it => {
underline(
stroke: 3pt + oklch(70%, 0, 0deg, 20%),
background: true,
offset: 0.5pt,
extent: 1pt,
evade: false,
it,
)
}
#show ref: it => {
if it.has("element") and it.element != none and it.element.func() == heading {
underline(
stroke: 3pt + oklch(70%, 0, 0deg, 20%),
background: true,
offset: 0.5pt,
extent: 1pt,
evade: false,
it,
)
} else { it }
}
#let fn-link(fn) = {
link(label("theoretic-" + fn + "()"), raw(lang: "typ", "#theoretic." + fn + "()"))
}
= Summary
This package provides opinionated functions to create theorems and similar environments.
#code-example(
raw(
lang: "typ",
"<<<#import \"@preview/theoretic:"
+ VERSION
+ "\"
#import theoretic.presets.basic: *
#show ref: theoretic.show-ref
#theorem[This is a theorem.]
#proof[
This is a proof. A QED symbol is placed correctly even after block equations.
$ norm(x) = sqrt( sum_(k = 1)^d x_k ) . $
]
#proposition(<thm:foo>)[Foo][This is a named theorem.]
#proof[@thm:foo[-]][
Proof with a list or enum?
- No problem for QED.
]
",
),
)
= Features <features>
- Except for ```typ #show ref: theoretic.show-ref```, no "setup" is strictly necessary.
Customisation of the environments is achieved via parameters on the #fn-link("theorem") function.
You can use e.g. ```typ #let lemma = theoretic.theorem.with(kind: "lemma", supplement: "Lemmma", /* ... */)```.
#qed[→ See @styling]
For convenience, the ```typc theoretic.presets``` module contains predefined styled environments.
#qed[→ See @presets]
- Flexible References via specific supplements.
#qed[ → #fn-link("show-ref")]
#code-example(```typ
@thm:foo vs @thm:foo[-] vs @thm:foo[--] vs @thm:foo[!] vs @thm:foo[!!] vs @thm:foo[!!!] vs @thm:foo[?] vs @thm:foo[Statement]
```, ratio: 0.6)
- Any theorem can be restated.
#qed[→ #fn-link("restate")]
#code-example(```typc
theoretic.restate(<thm:foo>)
// the head links to the original
```)
- Automatic numbering.
If your headings are numbered, it will use top-level heading numbers as the first component, otherwise it will simply number your theorems starting with Theorem 1.
#code-example-basic(```typ
#theorem(number: "!!")[
Number can be overridden for individual theorems.
]
#theorem(number: 40)[
If a `number` is passed (as opposed to a string or content),
]
#theorem[
...subsequent theorems will pick it up.
]
```)
- Custom outlines: Outline for headings _and/or_ theorems.
#qed[→ #fn-link("toc")]
- Filter for specific kinds of theorem to create e.g. a list of definitions.
- Optionally sorted alphabetically!
- Theorems can have a different title for outlines (#link(label("theoretic-theorem.toctitle"), raw(lang: "typ", "theorem(toctitle: ..)"))) and can even have multiple entries in a sorted outline.
- Highly customizable!
#qed[→ #fn-link("toc-entry")]
- (And this customization can be reused for regular outlines)
#qed[→ #fn-link("show-entry-as")]
- Automatic QED placement!
#qed[→ #link(label("theoretic-theorem.suffix"), raw(lang: "typ", "#theorem(suffix: ..)")) & #fn-link("qed")]
// TODO: QED stuff
In most cases, it should place the QED symbol appropriately automatically:
#code-example-basic(```typ
#proof[This is a proof. $x=y$]
#proof[
This is a proof.
$ x = y $
]
#proof[
#set math.equation(numbering: "(1)")
This is a proof.
$ x = y $
]
#proof(suffix: $smash$)[
This is a proof.
- #lorem(3)
]
#proof[
This is a proof.
- #lorem(3) $ x = y $
]
#proof[
This is a proof.
+ #lorem(3)
+ #lorem(3)
+ #lorem(3)
+ #lorem(3)
]
```)
Specifically, it works for lists, enums, and unnumbered block equations, which may be nested.
If your proof ends with some other block, you should might want to place a ```typ #qed()``` manually.
If you need to place a qed manually which should be aligned to a block equation,
put ```typ #show: qed-in-equation``` before said equation.
#qed[→ #fn-link("qed-in-equation")]
- Exercise solutions:
#qed[→ #fn-link("solutions")]
- Every theorem environment can have a solution, which is shown in a separate section.
- Solutions section automatically hides itself if there are no solutions to show.
#code-example-basic(```typ
>>> #exercise(solution: [Yay! you found the solutions!])[
<<< #exercise(solution: [/***************************/])[
Go look for the solution of this exercise at the end of
this document.
]
```)
// = Open TODOs
// - Ability to reference enumerations within theorem ("See Proposition 2.25 (a)")
= Styling / Customization <styling>
For basic customization, you can override the `supplement`, `kind`, and `options` parameters of #fn-link("theorem").
You can start completely fresh:
#code-example(
dir: ttb,
raw(
lang: "typ",
"<<<#import \"@preview/theoretic:"
+ VERSION
+ "\"\n"
+ ```typ
#show ref: theoretic.show-ref
// simply setting `variant` to one of "plain", "remark", "definition" or "important" changes the style:
#let theorem = theoretic.theorem.with(supplement: "Theorem", kind: "theorem", variant: "important")
// you can also set the other style options directly:
#let lemma = theoretic.theorem.with(
supplement: "Lemma", kind: "lemma",
options: (
head-font: (style: "normal", weight: "bold"),
title-font: (style: "italic", weight: "regular", fill: oklch(40%, 0.2, 12deg)),
body-font: (style: "normal", weight: "regular"),
block-args: (outset: 4pt, fill: oklch(95%, 0.06, 12deg)),
head-punct: none,
head-sep: h(1em),
),
)
#lorem(5)
#theorem[#lorem(5)]
#lemma[Title][#lorem(5)]
```.text,
),
)
See #link(label("theoretic-theorem.options"))[the documentation in the appendix] for more details on the `options` parameter.
Alternatively, you can also build upon a preset style:
#code-example(
raw(
lang: "typ",
"<<<#import \"@preview/theoretic:"
+ VERSION
+ "\"\n"
+ ```typ
#import theoretic.presets.fancy: *
#show ref: theoretic.show-ref
// this is immediately useful for translations:
#let satz = theorem.with(supplement: "Satz")
#satz[Eine deutsche Aussage.]
#theorem[An English theorem.]
// or to add new kinds:
#let lession = theorem.with(supplement: "Lession", kind: "lession", options: (color: yellow), variant: "plain")
#lession[Bar]
<<<#lession(variant: "important")[Important Lesson][...]
>>>#lession(variant: "important")[Important Lesson][
>>> The `variant` parameter is also intended to be called for single theorems.
>>> E.g. in this `fancy` preset, `"important"` adds a line above the supplement.
>>>]
```.text,
),
)
Note that not all preset styles respect the same options. More details are given in the examples in @presets.
If you want to go in a completely new direction, you can also provide your own #link(label("theoretic-theorem.show-theorem"))[`show-theorem`] function to fully control styling.
For how this can look, I recommend looking at how the predefined styles are made: #link("https://github.com/nleanba/typst-theoretic/tree/v0.3.1/src/styles")[See the code on GitHub].
#include "preset-preview.typ"
#set page(
numbering: (.., i) => {
smallcaps("a")
str(i)
},
columns: 1,
)
#counter(page).update(1)
#set heading(numbering: "A.1")
#show heading.where(level: 3): set heading(numbering: none)
#show heading.where(level: 4): set heading(numbering: none)
#show heading.where(level: 5): set heading(numbering: none)
#counter(heading).update(0)
= Detailed Documentation of the Functions
#let docs = tidy.parse-module(
read("src/base.typ"),
name: "theoretic",
scope: (
theoretic: theoretic,
type: tidy-style.show-type.with(style-args: (colors: tidy.styles.default.colors)),
),
preamble: "#import theoretic: *\n#set heading(outlined: false)\n",
enable-curried-functions: false,
)
#tidy.show-module(
docs,
style: tidy-style,
// enable-cross-references: auto,
first-heading-level: 1,
show-outline: false,
omit-private-definitions: true,
// omit-private-parameters: false,
show-module-name: false,
// omit-empty-param-descriptions: true,
// sort-functions: auto,
break-param-descriptions: true,
local-names: (parameters: [Parameters], default: [Default], variables: [Variables]),
)
#v(3em)
#theoretic.solutions()