{"id":66260,"date":"2022-08-06T09:01:48","date_gmt":"2022-08-06T09:01:48","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=66260"},"modified":"2022-08-06T09:01:48","modified_gmt":"2022-08-06T09:01:48","slug":"old-school-technical-writing-with-groff","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=66260","title":{"rendered":"Old-school technical writing with groff"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Old-school technical writing with groff<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/jim-hall\" class=\"username\">Jim Hall<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Sat, 08\/06\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-70128\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>One of my favorite stories about Unix is how it turned into a text processing system. Brian Kernighan <a href=\"https:\/\/opensource.com\/article\/20\/8\/unix-history\" target=\"_blank\" rel=\"noopener\">tells the story in his book<\/a> Unix: A History and a Memoir (chapter 3) but to summarize: The Unix team at Bell Labs ran the original Unix on a PDP-7 computer, but it was a tiny system and didn&#8217;t have sufficient resources to support new work. So Ken Thompson and others lobbied to purchase a new PDP-11 computer. Management denied the request. Around the same time, the Patents department planned to buy a new computer platform to produce patent applications using proprietary document formatting software. The Unix group proposed that the Patents department instead buy a new PDP-11 for the Unix team, and the Unix team would create formatting software for them.<\/p>\n<p>That new formatting system was called <code>nroff<\/code>, short for &#8220;New Roff,&#8221; an updated version of a text formatting program called Roff from a 1960s computer system. The name Roff came from the old expression, &#8220;I&#8217;ll run off a document.&#8221;<\/p>\n<h2>Basic formatting with nroff<\/h2>\n<p>By default, <code>nroff<\/code>\u00a0collects words and fills paragraphs. When <code>nroff<\/code>\u00a0encounters a blank line, it starts a new paragraph. For example, start with this article&#8217;s introduction, which is only a few paragraphs long:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">$ cat intro<br>\nOld-school technical writing with groff<br>\nJim Hall<br>\n\u00a0<br>\nOne of my favorite stories about Unix is how it turned<br>\ninto a text processing system. Brian Kernighan tells the<br>\nstory in his book Unix: A History and a Memoir (chapter 3)<br>\nbut to summarize:<br>\nThe Unix team at Bell Labs ran the original Unix on<br>\na PDP-7 computer, but it was a tiny system and didn't<br>\nhave sufficient resources to support new work. So Ken<br>\nThompson and others lobbied to purchase a new PDP-11<br>\ncomputer. Management denied the request. Around the same<br>\ntime, the Patents department planned to buy a new computer<br>\nplatform to produce patent applications using proprietary<br>\ndocument formatting software. The Unix group proposed<br>\nthat the Patents department instead buy a new PDP-11 for<br>\nthe Unix team, and the Unix team would create formatting<br>\nsoftware for them.<br>\n\u00a0<br>\nThat new formatting system was called nroff, short for<br>\n\"New Roff,\" an updated version of a text formatting program<br>\ncalled Roff from a 1960s computer system. The name Roff<br>\ncame from the old expression, \"I'll run off a document.\"<\/div><\/div><\/pre>\n<p>If you process this file with <code>nroff<\/code>, lines are &#8220;glued&#8221; together so the output is paragraphs with full justification. Using <code>nroff<\/code> also hyphenates words, if that helps balance lines in the text:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">$ nroff intro | head<br>\nOld\u2010school technical writing with groff Jim Hall<br>\n\u00a0<br>\nOne \u00a0of \u00a0my \u00a0favorite \u00a0stories about Unix is how it turned into a<br>\ntext processing system. Brian Kernighan tells the \u00a0story \u00a0in \u00a0his<br>\nbook \u00a0Unix: \u00a0A History and a Memoir (chapter 3) but to summarize:<br>\nThe Unix team at Bell Labs ran the original Unix on a PDP\u20107 \u00a0com\u2010<br>\nputer, \u00a0but \u00a0it \u00a0was a tiny system and didn\u2019t have sufficient re\u2010<br>\nsources to support new work. So Ken Thompson and \u00a0others \u00a0lobbied<br>\nto purchase a new PDP\u201011 computer. Management denied the request.<br>\nAround the same time, the Patents department planned to buy a new<\/div><\/div><\/pre>\n<p>Original Unix systems used a typewriter-style printer that used 66 lines of 80 columns on a US Letter page, and <code>nroff<\/code> makes the same assumptions. It also adds empty lines so each page of output is 66 lines per page, but I&#8217;ve used the <code>head<\/code> command to show just the first few lines of output because my sample text isn&#8217;t very long.<\/p>\n<h2>Breaking lines and centering text<\/h2>\n<p>The first two lines were meant to be separate lines of text. You can insert a formatting instruction to tell <code>nroff<\/code> to add a line break. All <code>nroff<\/code> instructions start with a dot, followed by a brief command. To add a line break, use the <code>.br<\/code> instruction between the first and second line:<\/p>\n<pre>\n<code>Old-school technical writing with groff\n.br\nJim Hall<\/code><\/pre>\n<p>When you process this new file, <code>nroff<\/code> prints the title and author on separate lines:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">$ nroff intro | head <br>\nOld\u2010school technical writing with groff<br>\nJim Hall<br>\n\u00a0<br>\nOne \u00a0of \u00a0my \u00a0favorite \u00a0stories about Unix is how it turned into a<br>\ntext processing system. Brian Kernighan tells the \u00a0story \u00a0in \u00a0his<br>\nbook \u00a0Unix: \u00a0A History and a Memoir (chapter 3) but to summarize:<br>\nThe Unix team at Bell Labs ran the original Unix on a PDP\u20107 \u00a0com\u2010<br>\nputer, \u00a0but \u00a0it \u00a0was a tiny system and didn\u2019t have sufficient re\u2010<br>\nsources to support new work. So Ken Thompson and \u00a0others \u00a0lobbied<br>\nto purchase a new PDP\u201011 computer. Management denied the request.<\/div><\/div><\/pre>\n<p>You can add other formatting to make this document look better. To center the top two lines, use the <code>.ce<\/code> formatting request. This takes a number argument, to indicate how many lines <code>nroff<\/code> should center. Here, you can center the top two output lines with the <code>.ce 2<\/code> request:<\/p>\n<pre>\n<code>.ce 2\nOld-school technical writing with groff\n.br\nJim Hall<\/code><\/pre>\n<p>With this added instruction, <code>nroff<\/code>\u00a0correctly centers the first two lines:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">$ nroff intro | head <br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Old\u2010school technical writing with groff<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Jim Hall<br>\n\u00a0<br>\nOne \u00a0of \u00a0my \u00a0favorite \u00a0stories about Unix is how it turned into a<br>\ntext processing system. Brian Kernighan tells the \u00a0story \u00a0in \u00a0his<br>\nbook \u00a0Unix: \u00a0A History and a Memoir (chapter 3) but to summarize:<br>\nThe Unix team at Bell Labs ran the original Unix on a PDP\u20107 \u00a0com\u2010<br>\nputer, \u00a0but \u00a0it \u00a0was a tiny system and didn\u2019t have sufficient re\u2010<br>\nsources to support new work. So Ken Thompson and \u00a0others \u00a0lobbied<br>\nto purchase a new PDP\u201011 computer. Management denied the request.<\/div><\/div><\/pre>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">More Linux resources<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/linux-commands-cheat-sheet\/?intcmp=70160000000h1jYAAQ\">Linux commands cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/advanced-linux-commands\/?intcmp=70160000000h1jYAAQ\">Advanced Linux commands cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/www.redhat.com\/en\/services\/training\/rh024-red-hat-linux-technical-overview?intcmp=70160000000h1jYAAQ\">Free online course: RHEL technical overview<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-networking?intcmp=70160000000h1jYAAQ\">Linux networking cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-selinux?intcmp=70160000000h1jYAAQ\">SELinux cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/linux-common-commands-cheat-sheet?intcmp=70160000000h1jYAAQ\">Linux common commands cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/resources\/what-are-linux-containers?intcmp=70160000000h1jYAAQ\">What are Linux containers?<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/linux?intcmp=70160000000h1jYAAQ\">Our latest Linux articles<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>Adding page margins<\/h2>\n<p>Printing this to a printer results in text starting on the first line of the page, and against the left edge. To add a few lines of extra space from the top of the page, use the <code>.sp<\/code> request, with the number of blank lines to add:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">.sp 5<br>\n.ce 2<br>\nOld-school technical writing with groff<br>\n.br<br>\nJim Hall<\/div><\/div><\/pre>\n<p>By default, <code>nroff<\/code> formats the output so each line is 65 columns wide. Printing to an 80 column US Letter page leaves 15 empty columns. Adding 7 spaces on the left side neatly balances the output with equal left and right page margins. You can create this page offset using the <code>.po 7<\/code> request:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">.po 7<br>\n.sp 5<br>\n.ce 2<br>\nOld-school technical writing with groff<br>\n.br<br>\nJim Hall<\/div><\/div><\/pre>\n<p>Processing the new file with <code>nroff<\/code> produces a plain text page that&#8217;s ready to print:<\/p>\n<pre>\n<code>$ nroff intro | head\n \n \n \n \n \n                    Old\u2010school technical writing with groff\n                                   Jim Hall\n \n       One  of  my  favorite  stories about Unix is how it turned into a\n       text processing system. Brian Kernighan tells the  story  in  his<\/code><\/pre>\n<h2>Printing to a laser printer<\/h2>\n<p>Later, the Unix team at Bell Labs acquired a phototypesetting machine, capable of producing printed text similar to a laser printer. To support the typesetter&#8217;s new capabilities, the Unix team updated <code>nroff<\/code> to become the typesetter-specific <code>troff<\/code> program, and a few years later updated it again to become <code>ditroff<\/code>, the device-independent version of <code>troff<\/code>.<\/p>\n<p>Linux systems provide modern versions of <code>nroff<\/code> and <code>troff<\/code> using the GNU <code>groff<\/code> program. You can still use the old <code>nroff<\/code> program name to generate plain text output, or <code>troff<\/code> to produce <code>ditroff<\/code>compatible output. Using the <code>groff<\/code> program, you can also prepare documents for other kinds of output files, such as Postscript.<\/p>\n<p>You can process the same input file using <code>groff<\/code>to print on a Postscript-compatible laser printer by selecting a suitable output type using the <code>-T<\/code> option, such as <code>-Tps<\/code> to generate a Postscript file. For example, I can print to a printer with the <a href=\"https:\/\/opensource.com\/article\/21\/9\/print-files-linux\" target=\"_blank\" rel=\"noopener\"><code>lpr<\/code> command<\/a> and the <code>HP_LaserJet_CP1525nw<\/code> device, because that&#8217;s how my Linux system <a href=\"https:\/\/opensource.com\/article\/18\/3\/print-server-raspberry-pi\" target=\"_blank\" rel=\"noopener\">recognizes my laser printer<\/a>:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"text geshifilter-text\">$ groff -Tps intro | lpr -P \"HP_LaserJet_CP1525nw\"<\/code><\/span><\/pre>\n<h2>Generating other kinds of output<\/h2>\n<p>If you instead want to save the output as a PDF file, you can convert the Postscript using the <code>ps2pdf<\/code> tool:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"text geshifilter-text\">$ groff -Tps intro | ps2pdf - &gt; intro.pdf<\/code><\/span><\/pre>\n<p>To generate a web page from the same file, use <code>-Thtml<\/code> to set the output type to HTML:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"text geshifilter-text\">$ groff -Thtml intro &gt; index.html<\/code><\/span><\/pre>\n<p>The <code>groff<\/code> command supports lots of other built-in formatting requests to provide other kinds of document formatting. If you want to learn the other default formatting requests available to you in the GNU <code>groff<\/code> implementations of <code>nroff<\/code> and <code>troff<\/code>, refer to chapter 5 in the <a href=\"https:\/\/www.gnu.org\/software\/groff\/manual\/groff.html#gtroff-Reference\" target=\"_blank\" rel=\"noopener\">The GNU Troff Manual<\/a>.<\/p>\n<p>Formatting documents using these built-in commands takes a lot of effort to keep everything looking the same. Technical writers who use <code>groff<\/code> instead use a collection of formatting requests called <em>macros<\/em>, which provide their own commands to generate section headings, paragraphs, block quotes, footnotes, lists, and other useful document formatting. To learn more about one popular macro package, read <a href=\"https:\/\/opensource.com\/article\/18\/2\/writing-academic-papers-groff-me\" target=\"_blank\" rel=\"noopener\">How to format academic papers on Linux with groff -me<\/a> on Opensource.com.<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Take a trip back in time to experience text formatting from a bygone era.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/08\/1980s-computer-yearbook.png\" width=\"520\" height=\"292\" alt=\"Compute like it's 1989\" title=\"Compute like it's 1989\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>LSE Library. Modified by Opensource.com. CC BY-SA 4.0<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/linux\" hreflang=\"en\">Linux<\/a><\/div>\n<\/p><\/div>\n<div class=\"hidden field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/08\/cc-by-sa-4-8.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Old-school technical writing with groff Jim Hall Sat, 08\/06\/2022 &#8211; 03:00 Register or Login to like Register or Login to like One of my favorite stories about Unix is how it turned into a text processing system. Brian Kernighan tells the story in his book Unix: A History and a Memoir (chapter 3) but to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":66261,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-66260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/66260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66260"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/66260\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/66261"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}