Hubbry Logo
Roff (software)Roff (software)Main
Open search
Roff (software)
Community hub
Roff (software)
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Roff (software)
Roff (software)
from Wikipedia
roff
Original authorsJoe Ossanna, Ken Thompson
DeveloperAT&T Bell Laboratories
Initial releaseNovember 3, 1971; 54 years ago (1971-11-03)
Operating systemUnix and Unix-like
TypeCommand

roff is a typesetting markup language. As the first Unix text-formatting computer program, it is a predecessor of the nroff and troff document processing systems.[1]: 290 

Roff was a Unix version of the runoff text-formatting program from Multics, which was a descendant of RUNOFF for CTSS (the first computerized text-formatting application). [1]

History

[edit]

CTSS

[edit]

roff is a descendant of the RUNOFF program by Jerry Saltzer, which ran on CTSS. Douglas McIlroy and Robert Morris wrote runoff for Multics in BCPL based on Saltzer's program written in MAD assembler. Their program in turn was "transliterated" by Ken Thompson into PDP-7 assembler language for his early Unix operating system, circa 1970.[2][3]

When the first PDP-11 was acquired for Unix in late 1970, the justification cited to management for the funding required was that it was to be used as a word processing system, and so roff was quickly transliterated again, into PDP-11 assembly, in 1971.

roff printed the man pages for Versions 1 to 3 of Unix, and when the Bell Labs patent department began using it, it became the first Unix application with an outside client.[4] Dennis Ritchie noted that the ability to rapidly modify roff (because it was locally written software) to provide special features was an important factor in leading to the adoption of Unix by the patent department to fill its word processing needs. This in turn gave Unix enough credibility inside Bell Labs to secure the funding to purchase one of the first PDP-11/45s produced.[citation needed]

See also

[edit]

References

[edit]

Sources

[edit]
  • D. M. Ritchie, The Evolution of the UNIX Time-sharing System (AT&T Bell Laboratories Technical Journal, Vol. 63, No. 8, October 1984)
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
Roff is a family of document formatting systems and an associated extensible designed for plain text input into formatted output for display or . Originating as one of the earliest text-processing tools in the Unix environment, it enables control over text layout, fonts, spacing, and page geometry through commands embedded in the source files. The core roff interpreter processes these files, supporting features like automatic hyphenation, justification, and macro definitions for reusable formatting structures. The history of roff traces back to the RUNOFF program, developed in 1964 by Jerome E. Saltzer for the (CTSS) at MIT, which formatted line-marked text files into justified manuscripts using embedded control words for adjustments like indentation, spacing, and headers. This evolved into the first Unix roff in 1971, authored by Douglas McIlroy, followed by Joe Ossanna's (for line printers and terminals) and (for typesetters) in 1973, which introduced device-specific output drivers. Brian Kernighan's device-independent (ditroff) in the 1980s further standardized the system by separating formatting from rendering, allowing portability across output devices. Roff's architecture includes preprocessors for specialized content—such as tbl for tables, eqn for equations, and pic for diagrams—that generate roff markup from higher-level inputs, alongside postprocessors for formats like or PDF. The language employs requests (commands starting with a dot, e.g., .sp for spacing), escape sequences (e.g., \f for font changes), and registers for variables, enabling complex document production with minimal overhead. It remains foundational for Unix manual pages (man pages) and technical documentation, powering tools that format content for terminals, printers, and modern digital outputs. In contemporary use, the GNU implementation, groff (GNU roff), serves as the de facto standard, extending the original AT&T troff with enhanced compatibility, additional macros, and support for outputs including HTML, DVI, and PDF while preserving backward compatibility. First released in 1990 by James Clark, groff is actively maintained under the GNU General Public License, with its latest stable version (1.23.0) issued in July 2023, ensuring roff's relevance in software engineering and open-source documentation workflows.

Introduction

Definition and Purpose

Roff is a family of document formatting systems originating in the that function as extensible markup languages, blending content with embedded control instructions to direct operations. These systems process input documents to generate formatted output suitable for various devices, such as line printers, typesetters, or modern digital formats. The core purpose of roff is to automate the formatting of text documents, performing essential tasks including line filling, hyphenation, justification, and to produce professional-looking output without manual intervention. This enables efficient creation of structured documents like manuals, reports, and technical papers, where content and layout instructions are interleaved for precise control over appearance. As the first text-formatting program developed for Unix, roff holds historical significance and serves as an early predecessor to modern programmable markup tools like by introducing a framework for embedding formatting logic within text. Its design emphasized extensibility through a programming-like , influencing the evolution of document processing in computing. At its basic architecture, a roff system operates via a pipeline that typically involves optional preprocessors to handle specialized input (such as equations or tables), a central roff formatter to interpret the markup and generate intermediate output, and postprocessors to adapt the results for specific output devices like terminals or printers. This modular approach allows flexibility in processing diverse document types while maintaining compatibility across implementations.

Relation to Other Systems

Roff traces its origins to the RUNOFF program developed by J.H. Saltzer at MIT in the mid-1960s for the (CTSS), which provided basic text formatting capabilities through simple markup commands. This was adapted for the operating system as runoff, incorporating enhancements for more structured document preparation, and subsequently ported to early Unix as roff to support documentation needs. From its Unix implementation, roff evolved into the n/troff family, with introduced in 1973 for formatting output suitable for line printers and terminals, emphasizing simplicity and portability. , developed concurrently by Joseph Ossanna, extended roff for high-quality output on phototypesetters, enabling precise control over typography and layout. Modern derivatives include GNU roff (groff), released in 1990, which builds on these foundations with improved compatibility, additional features, and support for contemporary output devices while maintaining with and . Roff played a foundational role in Unix documentation, serving as the primary tool for generating the system's manual pages (man pages) from the earliest editions, such as the 1971 Unix Programmer's Manual. Its macro packages, like those for man pages, influenced standardized formatting for software references and research documents, embedding roff deeply into Unix culture and subsequent BSD and distributions. In contrast to fixed-format systems prevalent in early word processors, which relied on predefined templates with limited customization, roff introduced programmability through an extensible language of requests and macros, allowing dynamic adjustment of text flow, spacing, and structure. It shares markup-based principles with , developed by in 1978 for mathematical , but roff prioritizes general-purpose document preparation with a lighter syntax, whereas TeX excels in complex equation rendering; both avoid what-you-see-is-what-you-get () interfaces, differing from modern tools like that emphasize visual editing over code-like input. Roff integrates seamlessly within a toolchain of preprocessors to handle specialized content, such as tbl for creating tables, eqn for embedding mathematical equations, and pic for generating diagrams from textual descriptions, which expand input before core processing. This modular approach remains evident in its ongoing use for BSD and man pages, where these components enable comprehensive yet efficient documentation workflows.

History

Origins in RUNOFF

The origins of roff trace back to the RUNOFF program, developed by Jerome H. "Jerry" Saltzer at MIT's Project MAC in the early 1960s as part of the (CTSS). Written in the MAD (Michigan Algorithm Decoder) programming language, RUNOFF was implemented between and 1964 to address the need for automated text formatting in a time-sharing environment running on an 7094 computer. This program marked one of the earliest efforts to use computers for document preparation, replacing manual typing and rudimentary duplication tools like , and enabling users to produce formatted manuscripts efficiently on shared systems. RUNOFF's primary purpose was to process text files—typically prepared using the companion TYPSET editor—and output them in a readable format suitable for line printers or consoles, with basic features like line filling, justification, and . It introduced inline control words beginning with a period (.), which served as non-printing instructions to control formatting, such as .line length n to set the output line width to n characters (defaulting to 60) or .indent m to adjust paragraph indentation by m spaces. These commands allowed simple markup for academic papers, theses, and memos, drawing inspiration from traditional notations while adapting them for computational processing; for instance, .adjust enabled right-justified text, and .double space added spacing between lines. Unlike later systems, RUNOFF lacked macro facilities, relying solely on these primitive control words as direct precursors to roff's request syntax, and it established the enduring "." convention for distinguishing formatting directives from regular text content. Despite its innovations, RUNOFF was inherently limited by the CTSS environment and the hardware of the era, producing output restricted to monospaced fonts on line printers without support for advanced like boldface, italics, or variable spacing. Control words had to start on new lines and were ignored if malformed, with issues like incompatible tab handling in justification mode further constraining usability. These constraints tied the program closely to CTSS's 12-bit BCD file format and specific peripherals, such as 1403 printers, preventing portability but providing a foundational model that influenced subsequent text processing tools at .

Early Bell Labs Implementations

In the late 1960s, following ' withdrawal from the project, Doug McIlroy reimplemented the original CTSS RUNOFF in the programming language for the GE 645 mainframe running under the GECOS operating system at ' Murray Hill facility. This 1969 version marked an early adaptation tailored for industrial research environments, extending the original's capabilities to handle ' internal documentation needs, such as memos and technical papers, with output directed to line printers. McIlroy's implementation introduced key enhancements, including the .na request for no-adjustment of line lengths, the .hy request for automatic hyphenation, number registers to store variables like page numbers, basic arithmetic operations for dynamic content, and improved hyphenation rules to better support justified text. The name "roff," a contraction of "run off," was coined by Bob Morris to distinguish this new system from the existing CTSS RUNOFF, as both were in use concurrently at . Morris, collaborating with McIlroy, contributed to porting the code to related platforms, including a version for the GE 635, further solidifying roff's role in ' document preparation workflow. A version of McIlroy's roff was adapted for , the GE 645-based operating system from which had recently departed, incorporating the aforementioned enhancements for producing research documents. J. F. Ossanna, a key figure in Multics software design at , contributed to this port, ensuring compatibility with the system's environment while maintaining the focus on extensible text formatting for technical output. These early roff implementations represented a pivotal shift from academic tools like RUNOFF to robust systems suited for commercial and industrial text processing at . By 1971, an early assembly-language port of roff—known as "rf"—was developed by for the minicomputer, a precursor to full Unix development, and used to format the inaugural Unix manual pages. This adaptation built directly on McIlroy's codebase, enabling efficient document production on limited hardware and laying groundwork for roff's integration into Unix.

Transition to Unix and nroff/troff

In 1971, and adapted the roff formatter to the 's as part of the early Unix development at , enabling the production of the First Edition Unix Programmer's Manual released on November 3 of that year. This port marked roff's initial integration into the Unix environment, transitioning it from its origins to support the nascent operating system's documentation needs on limited hardware. By 1973, with the release of Unix Version 3, Joe Ossanna introduced , a rewritten and enhanced version of roff optimized for output on terminal devices such as ASCII Teletype models and line printers. This implementation, still coded in PDP-11 assembly, incorporated key advancements including the .de request for macro definitions and .wh for page traps to monitor specific output positions, allowing more dynamic control over formatted text. nroff emphasized simplicity and compatibility with monospaced, fixed-width output, making it suitable for everyday terminal-based previewing and printing without specialized hardware. The debut of followed in 1974 with Unix Version 4, extending Ossanna's work to drive the Graphic Systems C/A/T phototypesetter for professional . This variant introduced support for proportional fonts, to adjust inter-character spacing, ligatures for combined glyphs, and the first use of digitized fonts in a Unix text processor, enabling high-fidelity output with variable spacing to accommodate ascenders and . In contrast to nroff's focus on for terminals, troff prioritized typographic quality for printed documents, though both shared a common input syntax for broad compatibility. The introduction of and profoundly impacted Unix by standardizing documentation production across the system, with these tools becoming essential utilities for generating manuals and technical reports. Their design influenced subsequent developments, such as the device-independent ditroff, which generalized output handling beyond specific hardware.

Post-1970s Developments

Following Joe Ossanna's in late 1977, took over the development of at , rewriting it in to enhance maintainability and portability. In 1979, Kernighan further revised to support multiple phototypesetters, including the Autologic APS-5, while preserving the original input syntax. In the mid-1970s, key preprocessors extended 's capabilities for technical content, including eqn for typesetting mathematical equations, developed by Lorinda Cherry and in 1975, and tbl for formatting tables, introduced by Mike Lesk and Kernighan around the same time. These tools, included in Unix Version 6, allowed higher-level input for complex elements like formulas and tabular data. A major advancement came with the completion of device-independent input in 1982, as detailed in Kernighan's #97 ("A Typesetter-Independent "), which introduced an abstract intermediate output format known as ditroff. This allowed to generate device-agnostic that could be tailored to various output devices without altering the source documents, significantly improving flexibility for typesetting across hardware. The 1980s saw further additions of preprocessors, such as pic for generating diagrams from textual descriptions, with its user manual released in 1981 (revised 1984) by Kernighan, and refer for automating bibliography management and citations. Macro packages also proliferated, including the -ms package originally developed by Mike Lesk for formatting technical papers and memos, and the -man package standardized for Unix manual pages. Portability efforts advanced with the inclusion of standardized and in Unix Version 7, released in 1979, which influenced subsequent distributions like BSD Unix and AT&T's System III and System V. By the late , 's proprietary status under restricted its adoption outside licensed Unix environments, paving the way for open alternatives as Unix clones proliferated. In response, James Clark initiated the groff project in early 1989 as a GNU implementation of ditroff, primarily to meet the Free Software Foundation's needs for free documentation tools.

Core Concepts

Input Conventions

Roff input files consist of text lines and control lines, with text lines containing the content to be formatted and ending in newlines typically after sentences, colons, semicolons, or optionally commas for readability. Control lines, which invoke requests or macros, begin with a dot (.) for standard processing or a neutral apostrophe (') to suppress the break that would otherwise occur before the next text line. In roff, words are defined as sequences of non-space characters, while sentences are identified by end-of-sentence characters such as "!", "?", or "." followed by two spaces or a . To suppress end-of-sentence detection or prevent unwanted breaks—such as after an —the non-printing & can be inserted immediately after the punctuation. This handling ensures proper justification and spacing during filling, which is enabled by default in most implementations. Best practices for preparing roff input emphasize simplicity and portability: lines should be limited to 72 characters or fewer to accommodate editor fill columns and avoid wrapping issues, leading spaces should be avoided for indentation (instead using the .in request), and comments can be added via the at the beginning of a line or after a . Empty s (simply ".") can be used for visual separation in the source without affecting output, while true empty lines (containing only a ) introduce breaks and default vertical spacing. For long lines, the escape (backslash followed by ) allows invisible continuation across multiple input lines. Special characters like the dot (.) or apostrophe (') must be handled carefully in text: if they appear at the start of a line after a space, they are interpreted as control characters, so prefixing them with & allows literal printing. Input files use Unix-style newlines (U+000A) and should stick to US-ASCII or ISO Latin-1 encoding, avoiding invalid control characters to prevent warnings or errors during processing. Editor support enhances productivity for roff authoring: provides nroff-mode, a major mode suitable for all roff dialects, activated manually via M-x nroff-mode or automatically through file-local variables such as mode: nroff and fill-column: 72 at the file's end, or by file extensions common to man pages. Vim supports for roff files by setting the filetype option in a modeline, such as .\ vim: set filetype=groff textwidth=72:`, with "groff" recognizing extensions or "nroff" for stricter compatibility; this requires Vim compiled with relevant features enabled. These conventions promote portability by standardizing input preparation, allowing documents to process consistently across nroff, troff, and derivatives like GNU groff without device-specific adjustments.

Requests and Macros

In roff, requests are the fundamental built-in commands that control formatting and processing, invoked by a period (.) followed by the request name at the beginning of a line, optionally with arguments specified in scalable units such as inches (i), ems (m), or vertical motion units (v). Examples include .ll N to set the line length to N units, .sp [N] to insert N lines of vertical space (defaulting to 1 line if unspecified), and .ce [N] to center the next N lines of text without filling or justifying them. Number registers provide variable storage for integers, defined or modified with .nr reg ±value [increment], where the optional increment applies to subsequent interpolations like \n(reg) for retrieval. Arguments to requests do not undergo interpolation unless explicitly escaped, ensuring predictable behavior in macro expansions. Macros enable reusable code blocks in roff, defined using .de name [end] followed by the macro body and terminated by .. or the specified end string, allowing users to create custom commands that accept arguments accessed via &#36;1, &#36;2, etc., or $* for all arguments. For instance, .de hello Hello, &#36;1! .. defines a macro invoked as .hello World to output "Hello, World!". Macros support integration with conditionals like .if condition text (or { text } for multi-line), which evaluates numeric, string, or existence conditions to execute text if true, and diversions via .di name to capture subsequent output into a named buffer for later reuse, ended by another .di. Escape sequences, introduced by a backslash (\), provide inline control without starting a new line, handling special functions such as \" for comments (ignored until the end of the line in copy mode), \f[font] to change the current font (e.g., \fB for bold), and \s[±N] to adjust type size by or to N points. The backslash itself is escaped as \\, and sequences like \n(reg) interpolate register values directly in text or macro arguments. Unlike requests, escape sequences enable fine-grained formatting within running text. Traps allow macros to be invoked automatically at specific events, using .wh position macname to set a page-location trap that triggers the macro when the vertical position reaches the specified distance from the top (useful for headers or footers, e.g., .wh 0 header), or .it N macname for an input-line trap that activates after N lines of input. These mechanisms facilitate dynamic without manual intervention at every occurrence. Roff includes basic programming constructs for , such as loops with .while condition { followed by the body on subsequent lines until a line containing only }, (e.g., .while \n(a < 5 { .nr a \n(a+1 .sp 1 } to increment register a and add space five times), and arithmetic operations on registers using .nr reg expr where expr supports integer addition (+), (-), (*), division (/ with ), and scaling indicators. variables can store and interpolate text via .ds name "string" and \*[name], complementing numeric registers for more complex manipulations. Limitations in roff's control language include exclusive support for integer arithmetic with no floating-point operations, restricting precision in calculations to whole numbers within a 32-bit signed range (approximately ±2 billion); division truncates toward zero. Register and macro scope is file-local by default, though .rm name removes definitions to manage , and compatibility modes may alter behavior across implementations. These features form the basis for macro packages that extend roff for specialized document types.

Output Processing

The roff formatting system processes input text through a sequential that transforms markup into rendered output suitable for various devices. It reads the input file line by line, initially scanning each line to identify and execute requests—commands prefixed with a period—and escape sequences beginning with a , which control formatting attributes such as font changes or positioning. Following this recognition phase, the system collects words into lines, applying filling to distribute text across the specified line length and justification if enabled, while handling hyphenation either algorithmically (enabled by default) or manually suppressed via the .nh request to prevent unwanted breaks. This ensures that textual content is assembled into cohesive units before further refinement, with no inherent validation of input syntax beyond basic parsing, leading to runtime errors if malformed. Line breaking in roff occurs automatically when accumulated text reaches the full measure set by the line length, such as via the .ll request, promoting natural flow while respecting punctuation and spaces. Manual intervention is possible through blank lines, which force a break, or the : escape sequence to insert an unbreakable space; conversely, lines beginning with an apostrophe (') are treated as no-break controls, preventing interruption before that point to preserve phrases or headings. Adjustment for justification is toggled with the .ad request, distributing extra space evenly across lines for a polished appearance, while inter-sentence spacing adds an additional unit after periods, exclamation marks, or question marks to enhance readability. Vertical spacing is managed via the .vs request, defaulting to 120% of the current font size (e.g., 12 points for a 10-point font), allowing precise control over paragraph separation and overall layout density. Page geometry in roff employs a with the origin at the upper-left corner of the page, where positive directions extend downward and to the right, facilitating absolute positioning of elements. Measurements use basic units of 1/720 inch in traditional implementations, enabling fine-grained control over margins and indents, with page transitions invoked by the .bp request to eject the current page and begin a new one. For device adaptation, roff generates an intermediate output format, such as ditroff, which encodes glyphs, their positions, and attributes in a device-independent manner; this is then passed to postprocessors that interpret device-specific details from DESC files—describing font metrics, resolutions, and capabilities—to produce final output in formats like ASCII for terminals or for printers. Error handling during processing includes issuing warnings for undefined macros or invalid requests, with the .ab request available to abort execution immediately upon detecting critical issues, though the system lacks comprehensive built-in validation to enforce document integrity.

Implementations

GNU groff

GNU groff, the GNU implementation of the roff typesetting system, was initiated in early 1989 by as part of the Project to provide a free alternative to proprietary implementations. The first release, version 0.3.1, appeared in June 1990, and it has since evolved into a robust, device-independent formatter compatible with AT&T's ditroff while adding numerous extensions. Distributed under the GNU General Public License (GPL), groff is maintained by G. Branden Robinson and supports platforms including , BSD variants, and Windows. Key enhancements in groff include its device-independent architecture, which allows output generation for multiple formats without device-specific recompilation, mirroring ditroff's capabilities but under a . It employs a high internal resolution of 72,000 basic units per inch for the device, enabling precise rendering far beyond classical troff's 720 units per inch. Color support is provided via the .color request, which enables or disables color output and works with various color spaces (up to 16 bits per channel), though terminal devices may have limitations. For PDF generation, the pdfroff wrapper simplifies multi-pass processing to produce PDF documents directly from roff input. Groff integrates several s to handle specialized content: gtbl for tables, geqn for mathematical equations, gpic for diagrams, and grefer for bibliographic citations. Additional extensions include gchem for diagrams and grohtml (with its pre-grohtml ) for output. Macro packages are built-in and include -man for Unix manual pages, -mdoc for BSD-style , -ms for general manuscripts, and -me for Berkeley-style memos. Support for X11 environments features drivers like X75 (75 dpi) and X100 (100 dpi), which utilize standard X11 fonts for terminal previewing. Typical usage involves command-line , such as groff -Tutf8 file.roff to a file for terminal output, with options to specify macro packages (e.g., -man) or preprocessors (e.g., -e for eqn). The .sy request allows embedding system calls within documents for dynamic content, such as executing external commands and capturing output. Groff's input handling supports multiple streams, facilitating parallel in pipelines with tools like preprocessors. As the default roff implementation on / distributions, groff is essential for rendering man pages and serves as a lightweight alternative to in minimal or embedded systems. Development remains active, with version 1.23.0 released in July 2023 serving as the current stable release as of late 2025.

Other Variants

The Documenter's Workbench (DWB) , released in 2007 by International (later SCO) based on 's DWB 3.3, remains a proprietary yet source-available implementation faithful to the original Unix V7 and V10 specifications. It preserves legacy behaviors and is deployed in environments like Solaris and for maintaining compatibility with historical Unix documentation workflows. Neatroff, developed by Ali Gholami Rudi and first announced in 2013, is a minimal, portable implementation written in C that emphasizes standards compliance with basic and functionality. Licensed under the (a permissive variant similar to BSD), it avoids extraneous extensions, supporting core requests like paragraph adjustment and font handling without the broader customizability of other systems, making it suitable for lightweight, cross-platform use. The Plan 9 , originating from ' Plan 9 operating system and updated in distributions like 9front, with the latest release in October 2025, produces device-independent output for flexible rendering across terminals and printers. Integrated into the 9front environment—a maintained of Plan 9—it prioritizes simplicity and research-oriented simplicity, with implemented as a script invoking in line-printer mode. Heirloom troff extends the DWB lineage by incorporating legacy features alongside enhancements from , such as output and extended locale support for input characters. Open-source and used in and Solaris derivatives, it ensures backward compatibility for traditional typesetting tasks while adding modern font handling like support. Mandoc, initiated by Kristaps Dzonsons in 2008, with significant contributions from Ingo Schwarze, who became the primary maintainer, functions as a lightweight roff parser primarily for man(7) and mdoc(7) documentation formats rather than full typesetting. It generates outputs in ASCII, , , , and PDF, focusing on portability and semantic markup interpretation to facilitate web and print rendering of Unix manuals without requiring complete roff emulation. These variants differ notably in licensing and scope: DWB retains proprietary status with source availability for enterprise Unix systems, contrasting with the open, permissive licenses of neatroff (ISC), Plan 9 (freely distributable via 9front), and (CDDL/MIT). Neatroff's minimalism prioritizes core compliance over the extensibility seen in groff, while mandoc shifts emphasis from comprehensive typesetting to efficient parsing and multi-format output for documentation-centric applications. Plan 9 and implementations, meanwhile, target integrated OS environments with device independence and legacy preservation, respectively.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.