Repository navigation
Expand file tree
/
Copy pathtemplate.typ
More file actions
672 lines (608 loc) · 14.6 KB
/
Copy pathtemplate.typ
File metadata and controls
672 lines (608 loc) · 14.6 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
// Store theorem environment numbering
#let thmcounters = state("thm",
(
"counters": ("heading": ()),
"latest": ()
)
)
// Setting theorem environment
#let thmenv(identifier, base, base_level, fmt) = {
let global_numbering = numbering
return (
..args,
body,
number: auto,
numbering: "1.1",
refnumbering: auto,
supplement: identifier,
base: base,
base_level: base_level
) => {
let name = none
if args != none and args.pos().len() > 0 {
name = args.pos().first()
}
if refnumbering == auto {
refnumbering = numbering
}
let result = none
if number == auto and numbering == none {
number = none
}
if number == auto and numbering != none {
result = context {
let heading-counter = counter(heading).get()
return thmcounters.update(thmpair => {
let counters = thmpair.at("counters")
// Manually update heading counter
counters.at("heading") = heading-counter
if not identifier in counters.keys() {
counters.insert(identifier, (0, ))
}
let tc = counters.at(identifier)
if base != none {
let bc = counters.at(base)
// Pad or chop the base count
if base_level != none {
if bc.len() < base_level {
bc = bc + (0,) * (base_level - bc.len())
} else if bc.len() > base_level{
bc = bc.slice(0, base_level)
}
}
// Reset counter if the base counter has updated
if tc.slice(0, -1) == bc {
counters.at(identifier) = (..bc, tc.last() + 1)
} else {
counters.at(identifier) = (..bc, 1)
}
} else {
// If we have no base counter, just count one level
counters.at(identifier) = (tc.last() + 1,)
let latest = counters.at(identifier)
}
let latest = counters.at(identifier)
return (
"counters": counters,
"latest": latest
)
})
}
number = context {
global_numbering(numbering, ..thmcounters.get().at("latest"))
}
}
return figure(
result + // hacky!
fmt(name, number, body, ..args.named()) +
[#metadata(identifier) <meta:thmenvcounter>],
kind: "thmenv",
outlined: false,
caption: none,
supplement: supplement,
numbering: refnumbering,
)
}
}
// Definition of theorem box
#let thmbox(
identifier,
head,
..blockargs,
supplement: auto,
padding: (top: 0.5em, bottom: 0.5em),
namefmt: x => [(#x)],
titlefmt: strong,
bodyfmt: x => x,
separator: [#h(0.1em):#h(0.2em)],
base: "heading",
base_level: none,
) = {
if supplement == auto {
supplement = head
}
let boxfmt(name, number, body, title: auto, ..blockargs_individual) = {
if not name == none {
name = [ #namefmt(name)]
} else {
name = []
}
if title == auto {
title = head
}
if not number == none {
title += " " + number
}
title = titlefmt(title)
body = bodyfmt(body)
pad(
..padding,
block(
width: 100%,
inset: 1.2em,
radius: 0.3em,
breakable: false,
..blockargs.named(),
..blockargs_individual.named(),
[#title#name#separator#body]
)
)
}
return thmenv(
identifier,
base,
base_level,
boxfmt
).with(
supplement: supplement,
)
}
// Setting plain version
#let thmplain = thmbox.with(
padding: (top: 0em, bottom: 0em),
breakable: true,
inset: (top: 0em, left: 1.2em, right: 1.2em),
namefmt: name => emph([(#name)]),
titlefmt: emph,
)
// Counting equation number
#let equation_num(_) = {
context {
let chapt = counter(heading).get().at(0)
let c = counter(math.equation)
let n = c.get().at(0)
"(" + str(chapt) + "." + str(n) + ")"
}
}
// Counting table number
#let table_num(_) = {
context {
let chapt = counter(heading).get().at(0)
let c = counter("table-chapter" + str(chapt))
let n = c.get().at(0)
str(chapt) + "." + str(n + 1)
}
}
// Counting image number
#let image_num(_) = {
context {
let chapt = counter(heading).get().at(0)
let c = counter("image-chapter" + str(chapt))
let n = c.get().at(0)
str(chapt) + "." + str(n + 1)
}
}
// Definition of table format
#let tbl(tbl, caption: "") = {
figure(
tbl,
caption: caption,
supplement: [表],
numbering: table_num,
kind: "table",
)
}
// Definition of image format
#let img(img, caption: "") = {
figure(
if type(img) == "content" {
// For contents such as commutative graphs
align(center, img)
} else {
// For normal images
img
},
caption: caption,
supplement: [図],
numbering: image_num,
kind: "image",
)
}
// Definition of abstruct page
#let abstract_page(abstract_ja, abstract_en, keywords_ja: (), keywords_en: ()) = {
if abstract_ja != [] {
show <_ja_abstract_>: {
align(center)[
#text(size: 20pt, "概要")
]
}
[= 概要 <_ja_abstract_>]
v(30pt)
set text(size: 12pt)
h(1em)
abstract_ja
par(first-line-indent: 0em)[
#text(weight: "bold", size: 12pt)[
キーワード:
#keywords_ja.join(", ")
]
]
} else {
show <_en_abstract_>: {
align(center)[
#text(size: 18pt, "Abstruct")
]
}
[= Abstract <_en_abstract_>]
set text(size: 12pt)
h(1em)
abstract_en
par(first-line-indent: 0em)[
#text(weight: "bold", size: 12pt)[
Key Words:
#keywords_en.join("; ")
]
]
}
}
// Definition of content to string
#let to-string(content) = {
if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")
} else if content.has("body") {
to-string(content.body)
} else if content == [ ] {
" "
}
}
// Definition of chapter outline
#let toc() = {
align(left)[
#text(size: 20pt, weight: "bold")[
#v(30pt)
目次
#v(30pt)
]
]
set text(size: 12pt)
set par(leading: 1.24em, first-line-indent: 0pt)
context {
let elements = query(heading.where(outlined: true))
for el in elements {
let before_toc = query(heading.where(outlined: true).before(here())).find((one) => {one.body == el.body}) != none
let page_num = if before_toc {
numbering("i", counter(page).at(el.location()).first())
} else {
counter(page).at(el.location()).first()
}
link(el.location())[#{
// acknoledgement has no numbering
let chapt_num = if el.numbering != none {
numbering(el.numbering, ..counter(heading).at(el.location()))
} else {none}
if el.level == 1 {
set text(weight: "black")
if chapt_num == none {} else {
chapt_num + " "
}
to-string(el.body)
} else if el.level == 2 {
h(2em) + chapt_num + " " + to-string(el.body)
} else {
h(5em) + chapt_num + " " + to-string(el.body)
}
}]
box(width: 1fr, h(0.5em) + box(width: 1fr, repeat[.]) + h(0.5em))
[#page_num]
linebreak()
}
}
}
// Definition of image outline
#let toc_img() = {
align(left)[
#text(size: 20pt, weight: "bold")[
#v(30pt)
図目次
#v(30pt)
]
]
set text(size: 12pt)
set par(leading: 1.24em, first-line-indent: 0pt)
context {
let elements = query(
figure.where(
outlined: true,
kind: "image"
)
)
for el in elements {
let loc = el.location()
let chapt = counter(heading).at(loc).at(0)
let num = counter(el.kind + "-chapter" + str(chapt)).at(loc).at(0) + 1
let page_num = counter(page).at(loc).first()
let caption_body = to-string(el.caption.body)
str(chapt)
"."
str(num)
h(1em)
caption_body
box(width: 1fr, h(0.5em) + box(width: 1fr, repeat[.]) + h(0.5em))
[#page_num]
linebreak()
}
}
}
// Definition of table outline
#let toc_tbl() = {
align(left)[
#text(size: 20pt, weight: "bold")[
#v(30pt)
表目次
#v(30pt)
]
]
set text(size: 12pt)
set par(leading: 1.24em, first-line-indent: 0pt)
context {
let elements = query(
figure.where(
outlined: true,
kind: "table"
)
)
for el in elements {
let loc = el.location()
let chapt = counter(heading).at(loc).at(0)
let num = counter(el.kind + "-chapter" + str(chapt)).at(loc).at(0) + 1
let page_num = counter(page).at(loc).first()
let caption_body = to-string(el.caption.body)
str(chapt)
"."
str(num)
h(1em)
caption_body
box(width: 1fr, h(0.5em) + box(width: 1fr, repeat[.]) + h(0.5em))
[#page_num]
linebreak()
}
}
}
// Setting empty par
#let empty_par() = {
v(-1em)
box()
}
// Construction of paper
#let master_thesis(
// The master thesis title.
title: "ここにtitleが入る",
// The paper`s author.
author: "ここに著者が入る",
// The author's information
university: "",
school: "",
department: "",
id: "",
mentor: "",
mentor-post: "",
class: "修士",
date: (datetime.today().year(), datetime.today().month(), datetime.today().day()),
paper-type: "論文",
// Abstruct
abstract_ja: [],
abstract_en: [],
keywords_ja: (),
keywords_en: (),
// The paper size to use.
paper-size: "a4",
// The path to a bibliography file if you want to cite some external
// works.
bibliography-file: none,
// The paper's content.
body,
) = {
// citation number
show ref: it => {
if it.element != none and it.element.func() == figure {
let el = it.element
let loc = el.location()
let chapt = counter(heading).at(loc).at(0)
link(loc)[#if el.kind == "image" or el.kind == "table" {
let num = counter(el.kind + "-chapter" + str(chapt)).at(loc).at(0) + 1
it.element.supplement
" "
str(chapt)
"."
str(num)
} else if el.kind == "thmenv" {
let thms = query(selector(<meta:thmenvcounter>))
let number = thmcounters.at(thms.first().location()).at("latest")
it.element.supplement
" "
numbering(it.element.numbering, ..number)
} else {
it
}]
} else if it.element != none and it.element.func() == math.equation {
let el = it.element
let loc = el.location()
let chapt = counter(heading).at(loc).at(0)
let num = counter(math.equation).at(loc).at(0)
it.element.supplement
" ("
str(chapt)
"."
str(num)
")"
} else if it.element != none and it.element.func() == heading {
let el = it.element
let loc = el.location()
let num = numbering(el.numbering, ..counter(heading).at(loc))
if el.level == 1 {
str(num)
"章"
} else if el.level == 2 {
str(num)
"節"
} else if el.level == 3 {
str(num)
"項"
}
} else {
it
}
}
// counting caption number
show figure: it => {
set align(center)
if it.kind == "image" {
set text(size: 12pt)
it.body
it.supplement
" " + it.counter.display(it.numbering)
" " + it.caption.body
context {
let chapt = counter(heading).at(it.location()).at(0)
let c = counter("image-chapter" + str(chapt))
c.step()
}
} else if it.kind == "table" {
set text(size: 12pt)
it.supplement
" " + it.counter.display(it.numbering)
" " + it.caption.body
set text(size: 10.5pt)
it.body
context {
let chapt = counter(heading).at(it.location()).at(0)
let c = counter("table-chapter" + str(chapt))
c.step()
}
} else {
it
}
}
// Set the document's metadata.
set document(title: title, author: author)
// Set the body font. TeX Gyre Pagella is a free alternative
// to Palatino.
set text(font: (
"Times New Roman", // Windows
// "Nimbus Roman", // Ubuntu
// "Hiragino Mincho ProN", // Mac
"Yu Mincho", // Windows
// "Noto Serif CJK JP", // Ubuntu
), size: 12pt)
// Configure the page properties.
set page(
paper: paper-size,
margin: (bottom: 1.75cm, top: 2.25cm),
)
// The first page.
align(center)[
#v(80pt)
#text(
size: 16pt,
)[
#university #school #department
]
#text(
size: 16pt,
)[
#class#paper-type
]
#v(40pt)
#text(
size: 22pt,
)[
#title
]
#v(50pt)
#text(
size: 16pt,
)[
#id #author
]
#text(
size: 16pt,
)[
指導教員: #mentor #mentor-post
]
#v(40pt)
#text(
size: 16pt,
)[
#date.at(0) 年 #date.at(1) 月 #date.at(2) 日 提出
]
#pagebreak()
]
set page(
numbering: "i",
)
counter(page).update(1)
// Show abstruct
abstract_page(abstract_ja, abstract_en, keywords_ja: keywords_ja, keywords_en: keywords_en)
pagebreak()
// Configure paragraph properties.
set par(leading: 0.78em, first-line-indent: 12pt, justify: true)
set par(spacing: 0.78em)
// Configure chapter headings.
set heading(numbering: (..nums) => {
nums.pos().map(str).join(".") + " "
})
show heading.where(level: 1): it => {
pagebreak()
counter(math.equation).update(0)
set text(weight: "bold", size: 20pt)
set block(spacing: 1.5em)
let pre_chapt = if it.numbering != none {
text()[
#v(50pt)
第
#numbering(it.numbering, ..counter(heading).at(it.location()))
章
]
} else {none}
text()[
#pre_chapt \
#it.body \
#v(50pt)
]
}
show heading.where(level: 2): it => {
set text(weight: "bold", size: 16pt)
set block(above: 1.5em, below: 1.5em)
it
}
show heading: it => {
set text(weight: "bold", size: 14pt)
set block(above: 1.5em, below: 1.5em)
it
} + empty_par()
// Start with a chapter outline.
toc()
pagebreak()
toc_img()
pagebreak()
toc_tbl()
set page(
numbering: "1",
)
counter(page).update(1)
set math.equation(supplement: [式], numbering: equation_num)
body
// Display bibliography.
if bibliography-file != none {
show bibliography: set text(12pt)
bibliography(bibliography-file, title: "参考文献", style: "ieee")
}
}
// LATEX character
#let LATEX = {
[L];box(move(
dx: -4.2pt, dy: -1.2pt,
box(scale(65%)[A])
));box(move(
dx: -5.7pt, dy: 0pt,
[T]
));box(move(
dx: -7.0pt, dy: 2.7pt,
box(scale(100%)[E])
));box(move(
dx: -8.0pt, dy: 0pt,
[X]
));h(-8.0pt)
}