Skip to content

Commit 21d6e1e

Browse files
committed
Styling and numbering for parts
- Styling in TOC - Styling in content - Parts have roman numerals - Chapter numbering does not nest under part numbering
1 parent 5c70c12 commit 21d6e1e

File tree

10 files changed

+80
-63
lines changed

10 files changed

+80
-63
lines changed

src/pages/bibliography.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#import "stdlib.typ": info, warning, solution
22

3-
#bibliography("scala-with-cats.bib", style: "acm-sigproceedings-long-author-list.csl")
3+
#bibliography("scala-with-cats.bib", style: "acm-sigchi-proceedings.csl")

src/pages/fps.typ

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,39 @@
1616
size: 12pt
1717
)
1818

19-
#set heading(numbering: "1.")
20-
21-
#show raw.where(block: true) :set block(fill: rgb("F7F7F7"), inset: 8pt, width: 100%)
22-
#show link :set text(rgb("#996666"))
2319

2420
// Front matter
2521
#include "parts/frontmatter.typ"
2622

2723
// Main matter
24+
#show raw.where(block: true) :set block(fill: rgb("F7F7F7"), inset: 8pt, width: 100%)
25+
#show link :set text(rgb("#996666"))
26+
2827
#pagebreak(to: "odd")
2928
#set page(numbering: "1")
3029
#set heading(numbering: "1.")
3130
#counter(page).update(1)
3231
#counter(heading).update(0)
3332

34-
// Intro
35-
#include "intro/index.typ"
36-
#include "intro/three-levels.typ"
37-
#include "intro/what-is-fp.typ"
38-
39-
// The remainder of the main matter is organized into parts
40-
// Offset headings by 1, so that part headings can be level 1 and chapter
41-
// headings are level 2
42-
#set heading(offset: 1)
33+
// The main matter is organized into parts
4334
// Start parts on an odd page
44-
#show <part>: it => {
35+
#show figure.where(kind: "part"): it => {
4536
pagebreak(weak: true, to: "odd")
46-
it
37+
set text(size: 24pt * 1.2 * 1.2)
38+
align(left)[
39+
#strong[#it.supplement #it.counter.display(it.numbering): #it.body]
40+
]
4741
}
4842
#show heading.where(level: 1): it => {
49-
// Part heading starts on an odd page but we insert them based on the label
43+
// Chapter heading starts on an odd page. Don't create a page break if the
44+
// page is already empty.
45+
pagebreak(weak: true, to: "odd")
5046
set text(size: 24pt * 1.2 * 1.2)
5147
it
5248
v(12pt * 1.2 * 1.2)
5349
}
5450
#show heading.where(level: 2): it => {
55-
// Chapter heading starts on an odd page. Don't create a page break if the
56-
// page is already empty.
57-
pagebreak(weak: true, to: "odd")
58-
set text(size: 24pt * 1.2 * 1.2)
51+
set text(size: 24pt * 1.2)
5952
it
6053
v(12pt * 1.2 * 1.2)
6154
}
@@ -77,6 +70,10 @@
7770
it
7871
v(12pt)
7972
}
73+
// Intro
74+
#include "intro/index.typ"
75+
#include "intro/three-levels.typ"
76+
#include "intro/what-is-fp.typ"
8077

8178
// Part 1: Foundations
8279
#include "parts/part1.typ"

src/pages/intro/what-is-fp.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ In a sense local reasoning and composition are two sides of the same coin. Local
9191

9292
I've made arguments in favour of functional programming and I admit I am biased---I do believe it is a better way to develop code than imperative programming. However, is there any evidence to back up my claim? There has not been much research on the effectiveness of functional programming, but there has been a reasonable amount done on static typing. I feel static typing, particularly using modern type systems, serves as a good proxy for functional programming so let's look at the evidence there.
9393

94-
In the corners of the Internet I frequent the common refrain is that #href("https://danluu.com/empirical-pl/")[static typing has neglible effect on productivity]. I decided to look into this and was surprised that the majority of the results I found support the claim that static typing increases productivity. For example, the literature review in #cite(<uesbeck19:human>, form: "prose") shows a majority of results in favour of static typing, in particular the most recent studies. However the majority of these studies are very small and use relatively inexperienced developers---which is noted in the review by Dan Luu. My belief is that functional programming comes into its own on larger systems. Furthermore, programming languages, like all tools, require proficiency to use effectively. I'm not convinced very junior developers have sufficient skill to demonstrate a significant difference between languages.
94+
In the corners of the Internet I frequent the common refrain is that #href("https://danluu.com/empirical-pl/")[static typing has neglible effect on productivity]. I decided to look into this and was surprised that the majority of the results I found support the claim that static typing increases productivity. For example, one literature review @uesbeck19:human finds a majority of results in favour of static typing, and in particular finds support amongst the more recent studies. However the majority of these studies are very small and use relatively inexperienced developers---which is noted in the review by Dan Luu. My belief is that functional programming comes into its own on larger systems. Furthermore, programming languages, like all tools, require proficiency to use effectively. I'm not convinced very junior developers have sufficient skill to demonstrate a significant difference between languages.
9595

9696
To me the most useful evidence of the effectiveness of functional programming is that industry is adopting functional programming en masse. Consider, say, the widespread and growing adoption of Typescript and React. If we are to argue that FP as embodied by Typescript or React has no value we are also arguing that the thousands of Javascript developers who have switched to using them are deluded. At some point this argument becomes untenable.
9797

src/pages/parts/frontmatter.typ

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#import "../stdlib.typ": title-page, heading-multiplier, heading-space-base, heading-base
22

3+
#let parts-and-headings = figure.where(kind: "part", outlined: true).or(heading.where(outlined: true))
4+
35
// Front matter heading styles
46
#show heading.where(level: 1): it => {
57
// Chapter heading starts on an odd page. Don't create a page break if the
@@ -27,6 +29,30 @@
2729
it
2830
v(12pt)
2931
}
32+
// Formatting part entries in the table of contents
33+
#show outline.entry: it => {
34+
if it.element.func() == figure {
35+
// // we're configuring part printing here, effectively recreating the default show impl with slight tweaks
36+
let res =[Part ] + numbering(it.element.numbering, ..it.element.counter.at(it.element.location())) + [: ] + it.element.body
37+
38+
if it.fill != none {
39+
res += [ ] + box(width: 1fr, it.fill) + [ ]
40+
} else {
41+
res += h(1fr)
42+
}
43+
44+
res += it.page()
45+
link(it.element.location(), res)
46+
} else {
47+
// we're doing indenting here
48+
// h(1em * it.level) + it
49+
link(
50+
it.element.location(),
51+
it.indented(it.prefix(), it.inner()),
52+
)
53+
}
54+
}
55+
3056
// Front Matter
3157

3258
// Half Title page
@@ -36,14 +62,30 @@
3662
#pagebreak(to: "odd")
3763
#title-page(half: false)
3864

65+
// Copyright page
66+
#pagebreak(weak: true, to: "even")
67+
#align(horizon)[
68+
© Copyright 2022--#datetime.today().display("[year]") Noel Welsh.
69+
Licensed under CC BY-SA 4.0
70+
71+
Portions of this work are based on _Scala with Cats_, by Dave
72+
Pereira-Gurnell and Noel Welsh. _Scala with Cats_ is licensed under
73+
CC BY-SA 3.0.
74+
75+
Artwork by Jenny Clements.
76+
77+
#v(2em, weak: true)
78+
79+
Published by Inner Product Consulting Ltd, UK.
80+
]
3981

4082
// Dedication
4183
#pagebreak(to: "odd")
4284
This book is dedicated to those who laid the path that I have followed, to those who will take up where I have left off, and to those who have joined me along the way.
4385

4486
// Table of contents
4587
#pagebreak(to: "odd")
46-
#outline(depth: 3)
88+
#outline(target: parts-and-headings, depth: 3)
4789

4890
// Preface
4991
#pagebreak(to: "odd")

src/pages/parts/part1.typ

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "../stdlib.typ": part
22

3-
#part("parts/part1.png", "Foundations", "sec:part:foundations")[
3+
#part[Foundations] <sec:part:foundations>
44

55
In this first part of the book we're building the foundational strategies on
66
which the rest of the book will build and elaborate. In @sec:adt we look at
@@ -12,4 +12,3 @@ artifacts. For example, we can label part of code as an algebraic data type or a
1212
type class. We'll also see strategies that help us write code but don't
1313
necessarily end up directly reflected in it, such as following the types.
1414

15-
]

src/pages/parts/part2.typ

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "../stdlib.typ": part
22

3-
#part("parts/part2.png", "Type Classes", "sec:part:type-classes")[
3+
#part[Type Classes] <sec:part:type-classes>
44

55
In this part of the book we move on to type classes.
66
We looked at the implementation of type classes in @sec:type-classes.
@@ -13,4 +13,3 @@ while the case studies will focus on their role in design.
1313
In @sec:cats we introduce the #link("https://typelevel.org/cats")[Cats] library.
1414
Cats provides implementation of the type classes we're interested in,
1515
and so it saves a lot of time and typing to use it.
16-
]

src/pages/parts/part3.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#import "../stdlib.typ": part
22

3-
#part("parts/part3.png", "Interpreters", "sec:part:interpreters")[]
3+
#part[Interpreters] <sec:part:interpreters>

src/pages/parts/part4.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#import "../stdlib.typ": part
22

3-
#part("parts/part4.png", "Case Studies", "sec:part:case-study")[]
3+
#part[Case Studies] <sec:part:case-study>

src/pages/scala-with-cats.bib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ @Article{pintrich02:metacognitive
197197
}
198198

199199
@PhdThesis{uesbeck19:human,
200-
author = {Phillip Merlin Uesbeck},
200+
author = {Uesbeck, Phillip Merlin},
201201
title = {On the human factors impact of polyglot programming on programmer productivity},
202202
school = {University of Nevada, Las Vegas},
203203
year = 2019,

src/pages/stdlib.typ

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,12 @@
5454
#let v-space = v(2em, weak: true)
5555
#text(3em)[*#title*]
5656

57-
#v-space
58-
#text(1.6em, authors)
59-
6057
#if not half [
6158
#v-space
62-
#text([Draft built on #datetime.today().display()])
63-
#v-space
64-
65-
Copyright 2022--#datetime.today().display("[year]") Noel Welsh.
66-
Licensed under CC BY-SA 4.0
67-
68-
Portions of this work are based on Scala with Cats, by Dave
69-
Pereira-Gurnell and Noel Welsh. Scala with Cats is licensed under
70-
CC BY-SA 3.0.
71-
72-
Artwork by Jenny Clements.
59+
#text(1.6em, authors)
7360

7461
#v-space
75-
76-
Published by Inner Product Consulting Ltd, UK.
62+
#text([Draft built on #datetime.today().display()])
7763
]
7864
],
7965
),
@@ -85,24 +71,18 @@
8571
link(destination)[#body #footnote(destination)]
8672
}
8773

88-
// A part heading page
74+
// A part heading
8975
//
90-
// image-path: path to the hero image for this part
91-
// name: the name of part as printed in the book
92-
// tag: a tag for references to this part (e.g. "sec:part:one")
93-
// content: content in the part
94-
#let part(image-path, name, tag, content) = [
95-
#align(center)[
96-
#image(image-path, width: 50%)
97-
#heading(level: 1)[
98-
#name
99-
]
100-
#label(tag)
101-
]
102-
<part>
103-
104-
#content
105-
]
76+
// Typical use is
77+
// #part[Name] <label>
78+
#let part = figure.with(
79+
// Matches the key of the counter above
80+
kind: "part",
81+
numbering: "I",
82+
supplement: "Part",
83+
// Empty caption so that parts can be included in the outline
84+
caption: []
85+
)
10686

10787
#let heading-multiplier = 1.2
10888
#let heading-base = 24pt

0 commit comments

Comments
 (0)