groff Command Examples

groff, short for “GNU troff,” is a powerful typesetting system developed by the GNU Project as a replacement for the traditional UNIX utilities troff and nroff. Designed for formatting and typesetting documents, groff provides a comprehensive set of tools and features for producing high-quality printed output, including manuals, reports, books, and more. With its flexible markup language and extensive capabilities, groff has become a popular choice among authors, publishers, and developers for creating professional-looking documents efficiently.

Key features and functionalities of groff include:

  • Markup Language: groff uses a sophisticated markup language based on the roff syntax, allowing users to specify the structure and formatting of their documents using simple text-based commands. The markup language supports a wide range of formatting options, including fonts, styles, page layouts, headers, footers, tables, and mathematical equations.
  • Device-Independent Output: groff generates device-independent output, meaning that documents can be formatted for various output devices, such as printers, terminals, plotters, and PDF files, without requiring changes to the source document. This flexibility allows users to produce consistent and professional-looking output across different platforms and media.
  • Extensible Architecture: groff features an extensible architecture that allows users to customize and extend its functionality through the use of macros, preprocessors, and postprocessors. Users can create custom macros to automate repetitive tasks, define new formatting styles, and enhance the capabilities of groff to suit their specific requirements.
  • Support for Multiple Languages: groff supports typesetting in multiple languages and character sets, making it suitable for internationalization and localization efforts. Users can create documents containing text in various languages, scripts, and writing systems, including English, Arabic, Chinese, Japanese, and more, with proper handling of bidirectional text and complex typography.
  • Integration with Other Tools: groff seamlessly integrates with other UNIX utilities and software tools, allowing users to leverage existing infrastructure and workflows. It can be combined with preprocessors like eqn, tbl, and pic to handle mathematical equations, tables, and graphics, respectively, enhancing the typesetting capabilities of groff for technical and scientific documents.
  • Open Source and Free Software: As part of the GNU Project, groff is distributed under a free software license, providing users with the freedom to use, modify, and distribute the software according to their needs. Its open-source nature fosters collaboration, innovation, and community-driven development, ensuring that groff remains a reliable and sustainable solution for typesetting and document formatting.

groff Command Examples

1. Format output for a PostScript printer, saving the output to a file:

# groff [path/to/input.roff] > [path/to/output.ps]

2. Render a man page using the ASCII output device, and display it using a pager:

# groff -man -T ascii [path/to/manpage.1] | less --RAW-CONTROL-CHARS

3. Render a man page into an HTML file:

# groff -man -T html [path/to/manpage.1] > [path/to/manpage.html]

4. Typeset a roff file containing [t]ables and [p]ictures, using the [me] macro set, to PDF, saving the output:

# groff [-t] [-p] -[me] -T [pdf] [path/to/input.me] > [path/to/output.pdf]

5. Run a groff command with preprocessor and macro options guessed by the grog utility:

# eval "$(grog -T utf8 [path/to/input.me])"

Summary

By offering a comprehensive set of features, extensive customization options, and robust output capabilities, groff continues to be a versatile and reliable typesetting system for a wide range of applications. Whether creating technical manuals, academic papers, or literary works, groff empowers users to produce professional-looking documents with precision and efficiency, making it an indispensable tool in the toolkit of writers, publishers, and developers alike.

Related Post