Skip to content

Commit 71ec50d

Browse files
committed
Improve formatting
- Define (half) title page as a reusable function - Style headings
1 parent f9aebdc commit 71ec50d

File tree

4 files changed

+75
-33
lines changed

4 files changed

+75
-33
lines changed

src/pages/fps.typ

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#import "stdlib.typ": title, subtitle, authors, edition
1+
#import "stdlib.typ": title, authors, title-page
2+
3+
#set document(
4+
title: title,
5+
author: authors
6+
)
27

38
// Default styling
49

@@ -11,44 +16,48 @@
1116
size: 12pt
1217
)
1318

14-
// Headings start at level 2 so that parts can be level 1, and
15-
// #set heading(offset: 2)
1619
#set heading(numbering: "1.")
1720

18-
// #show heading.where(level: 3): it => [
19-
// #colbreak()
20-
// #counter(heading).display(it.numbering) #strong(it.body)
21-
// #v(36pt)
22-
// ]
23-
24-
21+
// Heading styles
22+
#let heading-multiplier = 1.2
23+
#let heading-base = 1.73em
24+
#let heading-space-base = 1.16em
25+
// Chapter heading is 2 levels above level 2 heading
26+
#show heading.where(level: 1): it => {
27+
// Chapter heading starts on an odd page. Don't create a page break if the
28+
// page is already empty.
29+
pagebreak(weak: true, to: "odd")
30+
set text(size: 1.73em * 1.2 * 1.2)
31+
it
32+
v(1.16em * 1.2 * 1.2)
33+
}
34+
#show heading.where(level: 2): it => {
35+
v(heading-space-base)
36+
set text(size: heading-base)
37+
it
38+
v(0.5em)
39+
}
40+
#show heading.where(level: 3): it => {
41+
v(1.16em / 1.2)
42+
set text(size: 1.73em / 1.2)
43+
it
44+
v(0.5em)
45+
}
46+
#show heading.where(level: 4): it => {
47+
v(1.16em / 1.2 / 1.2)
48+
set text(size: 1.73em / 1.2 / 1.2)
49+
it
50+
v(0.5em)
51+
}
2552
// Front Matter
2653

27-
#let makeTitle = text(size: 24pt)[#title]
28-
#let makeSubtitle = text(size: 18pt)[#subtitle]
29-
3054
// Half Title page
31-
#makeTitle
55+
#title-page(half: true)
3256

3357
// Full Title page
3458
#pagebreak(to: "odd")
35-
#makeTitle
36-
#makeSubtitle
37-
#v(18pt)
38-
#authors
39-
40-
#edition
41-
#v(36pt)
59+
#title-page(half: false)
4260

43-
Copyright 2022--2025 Noel Welsh. Licensed under CC BY-SA 4.0
44-
45-
Portions of this work are based on Scala with Cats, by Dave Pereira-Gurnell and Noel Welsh. Scala with Cats is licensed under CC BY-SA 3.0.
46-
47-
Artwork by Jenny Clements.
48-
49-
#v(18pt)
50-
51-
Published by Inner Product Consulting Ltd, UK.
5261

5362
// Dedication
5463
#pagebreak(to: "odd")
@@ -68,6 +77,7 @@ This book is dedicated to those who laid the path that I have followed, to those
6877
#include "preface/license.typ"
6978

7079
// Main matter
80+
#pagebreak(to: "odd")
7181
#set page(numbering: "1")
7282
#set heading(numbering: "1.")
7383
#counter(page).update(1)

src/pages/preface/license.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "../stdlib.typ": info, warning, solution
2-
== License {-}
2+
== License
33

44

55
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit #link("http://creativecommons.org/licenses/by-sa/4.0/")[http://creativecommons.org/licenses/by-sa/4.0/]

src/pages/preface/preface.typ

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#import "../stdlib.typ": info, warning, solution
2-
#pagebreak(to: "even")
32
= Preface
43

54

src/pages/stdlib.typ

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,37 @@
3636
#let title = "Functional Programming Strategies"
3737
#let subtitle = "In Scala with Cats"
3838
#let authors = "Noel Welsh"
39-
#let edition = "May 2025"
39+
40+
#let title-page(half: true) = {
41+
page(
42+
align(
43+
left + horizon,
44+
block(width: 90%)[
45+
#let v-space = v(2em, weak: true)
46+
#text(3em)[*#title*]
47+
48+
#v-space
49+
#text(1.6em, authors)
50+
51+
#if not half [
52+
#v-space
53+
#text([Draft built on #datetime.today().display()])
54+
#v-space
55+
56+
Copyright 2022--#datetime.today().display("[year]") Noel Welsh.
57+
Licensed under CC BY-SA 4.0
58+
59+
Portions of this work are based on Scala with Cats, by Dave
60+
Pereira-Gurnell and Noel Welsh. Scala with Cats is licensed under
61+
CC BY-SA 3.0.
62+
63+
Artwork by Jenny Clements.
64+
65+
#v-space
66+
67+
Published by Inner Product Consulting Ltd, UK.
68+
]
69+
],
70+
),
71+
)
72+
}

0 commit comments

Comments
 (0)