Groff (GNU troff) is a typesetting system that reads plain text mixed with formatting commands and produces formatted output. Output may be PostScript, PDF, html, or ASCII/UTF8 for display at the terminal. Formatting commands may be either low-level typesetting requests ("primitives") or macros from a supplied set. Users may also write their own macros. All three may be combined.
Present on most Unix systems owing to its long association with Unix manuals (manpages), groff is capable of producing typographically sophisticated documents while consuming only minimal system resources.
Groff is released under the GNU General Public License.
We need to compile our document into ps
(PostScript) or pdf
(Portable Document Format) formats:
-
ps format:
$ groff -ms file.ms > output.ps $_
-
pdf format:
$ groff -ms -Tpdf file.ms > output.pdf $_
-
We also can compile with
-mspdf
flag to have some extra features like TOC:$ groff -mspdf file.ms > output.pdf $_
-
groff
has three way to create a comment:
\" This is a comment
.\" Also a comment but, it has to be at the beginning of the line
.ig
This is a multiline comment
everything in this block will be ignored.
..
We can define a macro to stop repeating ourselves and save time,
kinda like functions in every programming language
and exactly like macros in C
language.
.de MacroName
\" Body
..
And now we can use them just like other macros:
.MacroName
\" body
Custom bullet list:
.de list
.IP
\(bu
..
\" usage
.list
Test item one
Boxed code block:
.nr ln 1
.de cb
.QS
.B1
.ft CR
.sp 1n
.br
.sp 1n
.nf
.in +1m
.nm +0 1 1 -5
..
.de /cb
.br
.sp 1n
.nm
.fi
.ft
.in
.B2
.QE
..
\" usage
.cb
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello world!\\n");
return 0;
}
./cb
Every document (in general, not only in groff) at least needs a title and author:
.TL
The Title
.AU
The Author
We can add institution:
.AI
Home
We can also have abstraction:
.AB no
This is an abstraction
.AE
We can have page footer and header:
.ds RH Top right
.ds CH Top middle \" reserved for page number
.ds LH Top left
.ds RF Buttom right
.ds CF Buttom middle \" reserved for current date (.DA)
.ds LF Buttom left
Change font size:
.nr PS 18