Skip to content

Instantly share code, notes, and snippets.

@Gavinok
Last active May 12, 2024 17:10
Show Gist options
  • Select an option

  • Save Gavinok/1b6e5c6eeeb6b0067269aeebfde69b07 to your computer and use it in GitHub Desktop.

Select an option

Save Gavinok/1b6e5c6eeeb6b0067269aeebfde69b07 to your computer and use it in GitHub Desktop.
Some notes on using Groff to produce a Table of Contents with the ms macros

Table Of Contents

Example of automatic creating of tables of contents in groff

.NH
method

.XS \" index start
method contents
.XE \" end index
.LP
this is the method maragraph
.bp
.NH 2
pethod
.XS
pethod
.XE
.LP
phis is the method maragraph
.TC \" create table of contents

Example of manual creating of tables of contents in groff

.XS 1 \" toc start with index at page 1
method contents
.XA 2 \" index at page 2
pethod
.XE \" end toc listing
.LP
.NH
method
.bp
.NH 2
pethod
.LP
phis is the method maragraph

.TC \" create table of contents on seperate page

No Auto Relocating TOC

groff -Tpdf -ms "$file" > "$base".pdf
pdfroff -Tpdf -ms "$file" > "$base".pdf

Using mspdf to Generate TOC

Automatic TOC Using mspdf

.NH
.XN "method"
.LP
hello
.NH 2
.XN "pethod"
.LP
phis is the method maragraph
.TC \" create table of contents

No Auto Relocating TOC

groff -Tpdf -mspdf "$file" > "$base".pdf

No Auto Relocating TOC alternative

groff -Tps -mspdf "$file" | ps2pdf - > "$base".pdf

Auto Relocating TOC alternative using pdfroff

pdfroff -mspdf "$file" > "$base".pdf
@Gavinok
Copy link
Copy Markdown
Author

Gavinok commented Dec 22, 2022

Personally I use groff for quick things like notes and simple markup but use neatroff for anything I need complex formatting like this since neatroff is substantially nicer to hack on in my experience. Since I use org more these days I don't use groff it's self all that often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment