Groff stands for GNU troff. Groff is typically used to create man pages. But, it does more than that. Its an old school utility which has been around for almost 20 years but still holds its presence.
As a formatting and typesetting engine, this utility acts like a compiler for the input supplied (plain text content and formatting commands) to it and it creates a formatted document as its output. In this article we will understand the basics of this command by discussing some common groff requests along with examples.
Here is the syntax of this command :
groff [-abcegiklpstzCEGNRSUVXZ] [-d cs] [-D arg] [-f fam] [-F dir] [-I dir] [-K arg] [-L arg] [-m name] [-M dir] [-n num]
[-o list] [-P arg] [-r cn] [-T dev] [-w name] [-W name] [file …]
groff -h | –help
groff -v | –version [option …]
1. Basic Groff Example
This example uses groff utility to create a document with a single line without any formatting.
$ groff > grof_output_1 Hi, this is a Line.
This command would produce a PostScript file (PS file) that can be opened in a document viewer.
2. Introduce line spacing using .sp command
If a line space needs to be introduced, use .sp command followed by the number of line spaces required.
$ groff > grof_output_2 .sp 10 This line will occur after 10 spaces. Thanks.
3. Request a break using .br command
For a regular line break, use .br command as shown below.
$ groff > grof_output_3 Hi, .br Welcome to TGS!
4. Change line spacing using .ls command
Line spacing for a document can be changed using .ls command followed by the number of line spacing to be introduced. By default the Line spacing is 1.
$ groff > grof_output_4 .ls 2 Hi, .br Welcome to TGS!
This document will look like the following when viewed in a document viewer:
5. Introduce a break page using .bp command
If it is intended to have the next line or paragraph from the next page of the document then .bp command is used.
$ groff > grof_output_5 Hi, .bp Welcome to TGS!
6. Center lines using .ce command
If some lines need to be pushed towards the center of the document then .ce command can be used.
The argument to .ce determines how many lines need to be pushed to center.
$ groff > grof_output_6 .ce 1 TGS DOCUMENT Hello and welcome to TGS.
7. Set indentation using .in command
If indentation needs to be changed then this can be done through .in command followed by the indentation index.
$ groff > grof_output_7 Hi, .br .in 4 Welcome to TGS!
This document will look like the following when viewed in a document viewer:
8. Combine .br and .ce using .ti
This command can be used to break the text and center the immediate next line to ‘n’ steps. Where ‘n’ is the argument passed to .ti command.
$ groff > grof_output_8 Hi, .ti 5 Welcome to TGS!
9. Set page offset using .po command
If page offset ie space between left edge of the document paper and left margin in the document needs to be set then .po command can be used.
$ groff > grof_output_9 .po 10 Hi, .br Welcome to TGS!
10. Set the font size using .ps command
If the text needs to be increased or decreased in size then .ps command can be used. Please note that you can precede the argument to .ps with – to decrease the font size
$ groff > grof_output_10 Hi, .ps 20 Welcome to TGS!
This document will look like the following when viewed in a document viewer:
Comments on this entry are closed.
Hi,
Thanks a lot,
Very useful article,,,
Good to know about this tool, thanks.
Regards,
Júlio.
Does anybody know if there is a mobi or epub output module. Kinda like the tbl preprocessor.