I used to be an undergraduate pupil once I found Linux in 1993. I used to be so excited to have the ability of a Unix system proper in my dorm room, however regardless of its many capabilities, Linux lacked functions. Word processors like LibreOffice and OpenWorkplace had been years away. If you wished to make use of a phrase processor, you seemingly booted your system into MS-DOS and used WordExcellent, the shareware GalaxyWrite, or the same program.
That was my technique, since I wanted to write down papers for my courses, however I most well-liked staying in Linux. I knew from our “big Unix” campus pc lab that Unix methods offered a set of text-formatting packages known as nroff
and troff
. They are completely different interfaces to the identical system: nroff
generates plaintext output, appropriate for screens or line printers, and troff
generates very fairly output, often for printing on a laser printer.
On Linux, nroff
and troff
are mixed as GNU troff, extra generally referred to as groff. I used to be comfortable to see a model of groff included in my early Linux distribution, so I got down to discover ways to use it to write down class papers. The first macro set I realized was the -me
macro bundle, a simple, simple to be taught macro set.
The very first thing to learn about groff
is that it processes and codecs textual content based on a set of macros. A macro is often a two-character command, set on a line by itself, with a number one dot. A macro would possibly carry a number of choices. When groff
encounters one in all these macros whereas processing a doc, it’s going to routinely format the textual content appropriately.
Below, I will share the fundamentals of utilizing groff -me
to write down easy paperwork like class papers. I will not go deep into the small print, like create nested lists, retains and shows, tables, and figures.
Paragraphs
Let’s begin with a straightforward instance you see in nearly each kind of doc: paragraphs. Paragraphs might be formatted with the primary line both indented or not (i.e., flush in opposition to the left margin). Many printed paperwork, together with tutorial papers, magazines, journals, and books, use a mix of the 2 sorts, with the primary (main) paragraph in a doc or chapter flush left and all different (common) paragraphs indented. In groff -me
, you need to use each paragraph sorts: main paragraphs (.lp
) and common paragraphs (.pp
).
.lp
This is the primary paragraph.
.pp
This is a regular paragraph.
Text formatting
The macro to format textual content in daring is .b
and to format in italics is .i
. If you place .b
or .i
on a line by itself, then all textual content that comes after it will likely be in daring or italics. But it is extra seemingly you simply wish to put one or a couple of phrases in daring or italics. To make one phrase daring or italics, put that phrase on the identical line as .b
or .i
, as an possibility. To format a number of phrases in daring or italics, enclose your textual content in quotes.
.pp
You can do primary formatting similar to
.i italics
or
.b "bold text."
In the above instance, the interval on the finish of daring textual content may also be in daring kind. In most circumstances, that is not what you need. It’s extra appropriate to solely have the phrases daring textual content in daring, however not the trailing interval. To get the impact you need, you may add a second argument to .b
or .i
to point any textual content that ought to path the bolded or italicized textual content, however in regular kind. For instance, you would possibly do that to make sure that the trailing interval does not present up in daring kind.
.pp
You can do primary formatting similar to
.i italics
or
.b "bold text" .
Lists
With groff -me
, you may create two forms of lists: bullet lists (.bu
) and numbered lists (.np
).
.pp
Bullet lists are simple to make:
.bu
Apple
.bu
Banana
.bu
Pineapple
.pp
Numbered lists are as simple as:
.np
One
.np
Two
.np
Three
.pp
Note that numbered lists will reset on the subsequent pp or lp.
Subheads
If you are writing a protracted paper, you would possibly wish to divide your content material into sections. With groff -me
, you may create numbered headings (.sh
) and unnumbered headings (.uh
). In both, enclose the part title in quotes as an argument. For numbered headings, you additionally want to supply the heading stage: 1
will give a first-level heading (e.g., 1.). Similarly, 2
and three
will give second and third stage headings, similar to 2.1 or three.1.1.
.uh Introduction
.pp
Provide one or two paragraphs to explain the work
and why it is vital.
.sh 1 "Method and Tools"
.pp
Provide a couple of paragraphs to explain the way you
did the analysis, together with what tools you used
Smart quotes and block quotes
It’s normal in any tutorial paper to quote different folks’s work as proof. If you are citing a quick quote to spotlight a key message, you may simply kind quotes round your textual content. But groff will not routinely convert your quotes into the “smart” or “curly” quotes utilized by trendy phrase processing methods. To create them in groff -me
, insert an inline macro to create the left quote (*(lq
) and proper quote mark (*(rq
).
.pp
Christine Peterson coined the phrase *(lqopen supply.*(rq
There’s additionally a shortcut in groff -me
to create these quotes (.q
) that I discover simpler to make use of.
.pp
Christine Peterson coined the phrase
.q "open source."
If you are citing an extended quote that spans a number of strains, you will wish to use a block quote. To do that, insert the blockquote macro (.(q
) at first and finish of the quote.
.pp
Christine Peterson just lately wrote about open supply:
.(q
On April 7, 1998, Tim O'Reilly held a gathering of key
leaders within the subject. Announced prematurely as the primary
.q "Freeware Summit,"
by April 14 it was known as the primary
.q "Open Source Summit."
.)q
Footnotes
To insert a footnote, embody the footnote macro (.(f
) earlier than and after the footnote textual content, and use an inline macro (**
) so as to add the footnote mark. The footnote mark ought to seem each within the textual content and within the footnote itself.
.pp
Christine Peterson just lately wrote about open supply:**
.(f
**Christine Peterson.
.q "How I coined the term open source."
.i "OpenSource.com."
1 Feb 2018.
.)f
.(q
On April 7, 1998, Tim O'Reilly held a gathering of key
leaders within the subject. Announced prematurely as the primary
.q "Freeware Summit,"
by April 14 it was known as the primary
.q "Open Source Summit."
.)q
Cover web page
Most class papers require a canopy web page containing the paper’s title, your identify, and the date. Creating a canopy web page in groff -me
requires some meeting. I discover the best manner is to make use of centered blocks of textual content and add additional strains between the title, identify, and date. (I want to make use of two clean strains between every.) At the highest of your paper, begin with the title web page (.tp
) macro, insert 5 clean strains (.sp 5
), then add the centered textual content (.(c
), and further clean strains (.sp 2
).
.tp
.sp 5
.(c
.b "Writing Class Papers with groff -me"
.)c
.sp 2
.(c
Jim Hall
.)c
.sp 2
.(c
February XX, 2018
.)c
.bp
The final macro (.bp
) tells groff so as to add a web page break after the title web page.
Learning extra
Those are the necessities of writing professional-looking a paper in groff -me
with main and indented paragraphs, daring and italics textual content, bullet and numbered lists, numbered and unnumbered part headings, block quotes, and footnotes.
I’ve included a pattern groff file to display all of this formatting. Save the lorem-ipsum.me
file to your system and run it via groff. The -Tps
possibility units the output kind to PostScript so you may ship the doc to a printer or convert it to a PDF file utilizing the ps2pdf
program.
groff -Tps -me lorem-ipsum.me > lorem-ipsum.me.ps
ps2pdf lorem-ipsum.me.ps lorem-ipsum.me.pdf
If you would like to make use of extra superior capabilities in groff -me
, confer with Eric Allman’s “Writing Papers with Groff utilizing −me
,” which you must discover in your system as meintro.me
in groff’s doc
listing. It’s an amazing reference doc that explains different methods to format papers utilizing the groff -me
macros.