Skip to content

Commit 1dd5628

Browse files
authored
Merge pull request #80 from de-soot/main
edited groff post to number headings
2 parents 4f547d4 + 799a2b2 commit 1dd5628

File tree

5 files changed

+85
-59
lines changed

5 files changed

+85
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ cd [Path of source code folder]
2828
bundle exec jekyll serve
2929
```
3030
6. Navigate to http://localhost:4000 in a browser.
31-
7. Add your own Markdown posts inside `_posts`.
31+
7. Add your own Markdown posts inside the `_posts` folder.
3232
8. Profit!

_posts/2025-02-20-groff-apa.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permalink: /groff-apa
88

99
This guide explains why and how I used groff with the ms and refer macros to write my college essay in Neovim.
1010

11-
# Table of Contents <a name=tableofcontents></a>
11+
# 1. Table of Contents <a name=tableofcontents></a>
1212

1313
1. [Table of Contents](/groff-apa#tableofcontents)
1414

@@ -45,7 +45,7 @@ This guide explains why and how I used groff with the ms and refer macros to wri
4545

4646
11. [Conclusion](/groff-apa#conclusion)
4747

48-
# Preface <a name=preface></a>
48+
# 2. Preface <a name=preface></a>
4949

5050
Many colleges give students a mandatory class where they learn how to cite and do referencing in essays.
5151

@@ -59,7 +59,7 @@ I made a [Github repository](https://github.com/de-soot/groff-apa) as a companio
5959

6060
A fun fact about this blog post: this is actually my second time writing this whole thing because I frustratingly lost the first one in the dumbest way possible. I accidentally deleted the folder containing it because I forgot that I put it in the folder. Unfortunately, it was already gone by the time I realised due to the auto-emptying routine of my Trash folder scheduled to run once every hour.
6161

62-
# Introduction <a name=introduction></a>
62+
# 3. Introduction <a name=introduction></a>
6363

6464
The [American Psychological Association](https://apa.org) (APA) 7th Edition [style guide](https://apastyle.apa.org) is the most popular for formatting references and citations in college-level essays (at least that was what my lecturer said when they gave out the writing assignment).
6565

@@ -69,11 +69,11 @@ The [ms](https://www.gnu.org/software/groff/manual/groff.html.node/ms.html) ("ma
6969

7070
However, groff by itself cannot do citations and referencing out-of-the-box. Fortunately, it does come with a preprocessor called refer that does the citing and referencing for it. Although the defaults for refer do not conform to APA guidelines, it is not too complex to change those defaults to match any style guide as long as you know where to find the right things to change.
7171

72-
# Prerequisites <a name=prerequisites></a>
72+
# 4. Prerequisites <a name=prerequisites></a>
7373

7474
This guide assumes you are using a Unix-based system (e.g. GNU/Linux, *BSD, macOS, etc.) and already know how to write and compile basic `groff ms` documents to Portable Document Format (PDF). If not, do not worry. There are many resources online for getting started, such as Luke Smith's videos on [groff](https://videos.lukesmith.xyz/w/eDqgKby1W4sHQGZgqZbMLe) and [refer](https://videos.lukesmith.xyz/w/5ANbTYv7cgF69FhpAkVBwi). For more detail, see GNU's official [manual](https://www.gnu.org/software/groff/manual/groff.html) or `troff`'s [HOWTO](https://troff.org/TheGroffFriendsHowto.pdf).
7575

76-
# Cover Page <a name=coverpage></a>
76+
# 5. Cover Page <a name=coverpage></a>
7777

7878
My assignment did not require me to include a cover page, but yours might. By default, groff puts cover page information on the same page as the essay. Luckily, the ms macros contain a convenient way to change this. Just put [`.RP no`](https://linux.die.net/man/7/groff_ms) as the first line of your document (`.RP` stands for "report"; the `no` argument tells it to not repeat the cover page information on the next page):
7979

@@ -83,7 +83,7 @@ My assignment did not require me to include a cover page, but yours might. By de
8383

8484
This is also needed for the next section on page numbering.
8585

86-
# Page Numbering <a name=pagenumbering></a>
86+
# 6. Page Numbering <a name=pagenumbering></a>
8787

8888
The first page does not have any headers (including page numbering) because groff expects it to include cover page information (i.e. the title of the paper; optionally author(s), institution(s), date, and abstract).
8989

@@ -110,23 +110,23 @@ The `.RP no` macro is needed for this, but it produces a cover page. Use PDF-edi
110110

111111
which works because even though the title (`.TL`) is required, it stops at the abstract (`.AB`, which ends at `.AE`; the `no` argument suppresses the "Abstract" heading).
112112

113-
## Suppress Page Headers <a name=suppressheader></a>
113+
## 6.1 Suppress Page Headers <a name=suppressheader></a>
114114

115115
If instead you want to **not** have any page headers (including page numbering) for reasons such as plagerism report checkers potentially producing errors, disabling automatic page numbering is as easy as defining the central header to be empty:
116116

117117
```
118118
.ds CH
119119
```
120120

121-
# Font <a name=font></a>
121+
# 7. Font <a name=font></a>
122122

123123
Many lecturers demand assignments to be submitted in double-spaced Times New Roman in 12 point size. This section covers how to change the font family, size, style, and line spacing.
124124

125-
## Font Family <a name=fontfamily></a>
125+
## 7.1 Font Family <a name=fontfamily></a>
126126

127127
By default, groff already outputs text in your [device's default serif font family](https://www.gnu.org/software/groff/manual/groff.html.node/Using-Fonts.html) (typically Times New Roman), but sometimes (very rarely, in my experience) lecturers prefer sans-serif or even monospace in some cases.
128128

129-
### Default Fonts <a name=defaultfonts></a>
129+
### 7.1.1 Default Fonts <a name=defaultfonts></a>
130130

131131
Changing to another one of the default fonts in groff is simple.
132132

@@ -150,11 +150,11 @@ and (back to) serif font family:
150150

151151
There are many other default fonts in groff listed in [this post](https://technicallywewrite.com/2024/04/12/changefonts).
152152

153-
### Custom Fonts <a name=customfonts></a>
153+
### 7.1.2 Custom Fonts <a name=customfonts></a>
154154

155155
Installing custom fonts for groff is a little bit trickier; I have not been able to get it to work on my device yet. I did find a [guide that seemed promising](https://www.port.de/cgi-bin/groff/AddingFonts) though. Maybe I will revisit this if I get it working in the future.
156156

157-
## Font Size <a name=fontsize></a>
157+
## 7.2 Font Size <a name=fontsize></a>
158158

159159
The default font size in groff is a little bit less than 12pt ([10pt](https://www.gnu.org/software/groff/manual/groff.html.node/Manipulating-Type-Size-and-Vertical-Spacing.html), to be exact), but it is very easy to change. Simply add this line to your plaintext document to change the font size to 12pt:
160160

@@ -164,15 +164,15 @@ The default font size in groff is a little bit less than 12pt ([10pt](https://ww
164164

165165
As for what `PS` stands for, it probably means something like "Point Size"; `.nr` stands for "Number Registers".
166166

167-
## Line Spacing <a name=linespacing></a>
167+
## 7.3 Line Spacing <a name=linespacing></a>
168168

169169
All parts of an APA-styled paper [should be double-spaced](https://apastyle.apa.org/style-grammar-guidelines/paper-format/line-spacing). By default, groff uses [120% of font size](https://www.gnu.org/software/groff/manual/groff.html.node/Manipulating-Type-Size-and-Vertical-Spacing.html) as vertical spacing. Fortunately, changing this to double-spacing is just as simple as changing the font size: just set the vertical spacing (`.nr VS`) to double your font size (`.nr PS`).
170170

171171
```
172172
.nr VS 24
173173
```
174174

175-
## Font Style <a name=fontstyle></a>
175+
## 7.4 Font Style <a name=fontstyle></a>
176176

177177
Here is how to make your text **bold**,
178178

@@ -192,13 +192,13 @@ And to set it back to normal:
192192
.ft R \" Stands for Regular or Roman
193193
```
194194

195-
# In-text Citation <a name=intextcitation></a>
195+
# 8. In-text Citation <a name=intextcitation></a>
196196

197197
Now that everything is set up, we can start to get into the citations.
198198

199199
refer uses numbered footnotes by default, but APA wants the author(s) and date included in their in-text citations. This section will cover how to do exactly as APA says.
200200

201-
## Parenthetical Citation <a name=parentheticalcitation></a>
201+
## 8.1 Parenthetical Citation <a name=parentheticalcitation></a>
202202

203203
After some research, I found a [blog post "no-tears" guide](https://preciouschicken.com/blog/posts/no-tears-references-groff), 2 [Github](https://github.com/Koshkov/groff-paper-template) [repositories](https://github.com/skurtulmus/refer-styles), and a post from the [GNU mailing list archive](https://lists.gnu.org) (which I cannot seem to find anymore). I extracted the refer block (denoted by `.R1` and `.R2`) from all those sources and combined them to make a frankenstein that works perfectly for most APA parenthetical citations:
204204

@@ -215,17 +215,17 @@ join-authors " & " ", " " & " # Change default "and" to ampersand (&) when joini
215215
.R2 \" Refer block end
216216
```
217217

218-
## Narrative Citation <a name=narrativecitation></a>
218+
## 8.2 Narrative Citation <a name=narrativecitation></a>
219219

220220
My lecturer luckily did not require me to use narrative citations, but yours might. If you do have to use narrative citation, unfortunately, refer does not have any support for narrative citations being alongside parenthetical citations. While it is possible to repurpose the citation formatting part of the refer block to change it from parenthetical to narrative, it would still not be possible to have both narrative and parenthetical citation on the same page.
221221

222222
The only practical solution I can think of for this problem is to keep the refer block as-is and write the narrative citations manually. This will require you to have a separate document for producing the referencing for the narrative citations, because refer will not make entries for them in the reference list as it will not recognise the narrative citations that you manually typed in, treating them like ordinary text. This also means that you need to generate 2 separate output PDFs and extract the correct reference list from the one without narrative citations to merge (using PDF-editing software) with the other one that does.
223223

224-
# Reference List <a name=referencelist></a>
224+
# 9. Reference List <a name=referencelist></a>
225225

226226
This section is where we start to dive into refer's code (usually located inside either `/usr/share/groff/current/tmac` or `/usr/local/share/groff/current/tmac`). Rest assured, the changes that will be made will not be difficult as long as you know 3 things: what to change, what to change them to, and where to find them (all 3 being what I had to figure out on my own by reading and tinkering with the source code).
227227

228-
## Formatting the Heading <a name=formattingtheheading></a>
228+
## 9.1 Formatting the Heading <a name=formattingtheheading></a>
229229

230230
The "References" heading is left-aligned by default, whereas [APA wants it centered](https://apastyle.apa.org/style-grammar-guidelines/paper-format/reference-list). Some extra changes not specified by APA my lecturer wanted were to make the Heading a little bigger and add an extra line of space below it.
231231

@@ -259,7 +259,7 @@ Below is a list explaining each change made:
259259
- (Optional) `.nr PS 14` above it increases the font size to 14pt, just remember to reset it back to normal (12pt) with `.nr PS 12` after.
260260
- (Optional) `.sp 2` adds two extra lines of space below the heading.
261261

262-
## Space Between Entries <a name=spacebetweenentries></a>
262+
## 9.2 Space Between Entries <a name=spacebetweenentries></a>
263263

264264
There is no space between reference entries by default. This is already conforming to APA, but my lecturer wanted extra padding between the entries (even if that meant [breaking APA guidelines](https://apastyle.apa.org/style-grammar-guidelines/paper-format/reference-list)) and maybe yours might too.
265265

@@ -280,7 +280,7 @@ Inside `refer-ms.tmac` on lines 44--45, you can find this:
280280

281281
{%comment%}
282282

283-
### For Specific Entries <a name=forspecificentries></a>
283+
### 9.2.1 For Specific Entries <a name=forspecificentries></a>
284284

285285
For reference lists that span more than one page, some entries (especially large ones) may be split between 2 pages. While it would be easy to press the enter key a couple times in a WYSIWYG word processor, you should know by now that things are not going to be that easy in groff and refer.
286286

@@ -300,7 +300,7 @@ To fix an entry being split between pages, first identify the entry above it and
300300

301301
{%endcomment%}
302302

303-
## Field Ordering <a name=fieldordering></a>
303+
## 9.3 Field Ordering <a name=fieldordering></a>
304304

305305
The way refer orders the fields of each reference entry is hard-coded and different from what APA desires. More specifically, the date field is placed after the title field instead of being in between it and the author(s) field.
306306

@@ -336,7 +336,7 @@ Rearranging `D` (date) into the correct order (right after `A` (author(s)) and b
336336
.ds ref*spec!4 Q A D T R G P I C O
337337
```
338338

339-
## Punctuation <a name=punctuation></a>
339+
## 9.4 Punctuation <a name=punctuation></a>
340340

341341
Switching the order of the fields messes up the hard-coded punctuation order, but there are also some defaults that do not follow APA guidelines.
342342

@@ -421,7 +421,7 @@ The list below details the changes:
421421
- All `\fP` in `arg 5` are moved to `arg 4` to make sure the punctuations after each field are not in bold or italics.
422422
- When numbering pages, APA does not denote with `p.` for single pages or `pp.` for page ranges, so they were removed in their respective rows.
423423

424-
### Period Suppression <a name=periodsuppression></a>
424+
### 9.4.1 Period Suppression <a name=periodsuppression></a>
425425

426426
By default, refer appends a period at the end of each entry. This means that a period is added after the last field that contains a DOI or URL, which APA has [explicitly stated to not do](https://apastyle.apa.org/instructional-aids/reference-guide.pdf).
427427

@@ -443,7 +443,7 @@ Now just remove the period (`.`) on the last line (213):
443443
. as ref*string
444444
```
445445

446-
# Exporting as PDF <a name=exportingaspdf></a>
446+
# 10. Exporting as PDF <a name=exportingaspdf></a>
447447

448448
The plaintext document can be compiled with either `groff`,
449449

@@ -466,7 +466,7 @@ Below is a list explaining what each of the optional arguments mean:
466466
- `-R` selects refer macros.
467467
- (Optional) `-dpaper=a4` and `-P-pa4` exports the paper to the international-standard A4 size instead of the default US letter.
468468

469-
# Conclusion <a name=conclusion></a>
469+
# 11. Conclusion <a name=conclusion></a>
470470

471471
If you found this helpful in any way or have any questions, feel free to leave a comment below. Also read my [previous guide](/justify-text) on how I justify and hyphenate the text on this website.
472472

_posts/2025-12-08-2s-complement.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ If we flip all the bits of `x` using the bitwise NOT operator (`~`), we get a ne
2121
We will call this new number `~x`, where `x + ~x = 2^n - 1`, since 2^n - 1 has all `n` number of bits set to `1`.
2222

2323
Rearranging the above equation for `x`, we get `x = (2^n - 1) - ~x`.
24-
It is then easy to find that `-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x`.
25-
Now see the picture of where "flip the bits and add one" comes from.
24+
It is then easy to find that
25+
26+
`-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x`.
27+
28+
Now start to see the picture of where "flip the bits and add one" comes from.
2629

2730
But we cannot just flip bits and add 1 to get `-x` with ordinary bits, that would just be `~x + 1`.
2831
We are still missing the `-2^n` in the equation, but how would we get that?
@@ -36,3 +39,20 @@ When we flip the bits of `x`, this new bit we added will also get flipped along
3639
Putting all the pieces together, we get that for a number `x` represented by `n` bits (with an extra bit having a place value of `-2^n`) where `x = (2^n - 1) - ~x`, you would need to flip its bits and add one to get `-2^n + ~x + 1 = -x`.
3740

3841
Hopefully after reading this, you will have gained a better understanding of using 2's complement for converting binary numbers to negative.
42+
43+
<script src="https://giscus.app/client.js"
44+
data-repo="de-soot/de-soot.github.io"
45+
data-repo-id="R_kgDOK6_5tA"
46+
data-category="Announcements"
47+
data-category-id="DIC_kwDOK6_5tM4CflCT"
48+
data-mapping="title"
49+
data-strict="0"
50+
data-reactions-enabled="1"
51+
data-emit-metadata="0"
52+
data-input-position="top"
53+
data-theme="preferred_color_scheme"
54+
data-lang="en"
55+
data-loading="lazy"
56+
crossorigin="anonymous"
57+
async>
58+
</script>

_site/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ cd [Path of source code folder]
2828
bundle exec jekyll serve
2929
```
3030
6. Navigate to http://localhost:4000 in a browser.
31-
7. Add your own Markdown posts inside `_posts`.
31+
7. Add your own Markdown posts inside the `_posts` folder.
3232
8. Profit!

0 commit comments

Comments
 (0)