troff
Quick Reference
Command Name:
troff
Category:
text processing
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Document formatting
Create formatted documents using the troff typesetting system
- 2
Report generation
Generate professional-quality reports and documents
- 3
Scripting
Use in shell scripts to generate formatted documents programmatically
- 4
Document processing
Manipulate and transform document data
Syntax
troff [OPTION]... [FILE]...
Options
| Option | Description |
|---|---|
| -a | Produce ASCII output instead of device-specific code |
| -b | Print a backtrace with each warning or error |
| -c | Disable color output |
| -C | Enable compatibility mode |
| -d CS | Define a string CS for use in the document |
| -e | Preprocess with eqn (for mathematical equations) |
| -E | Inhibit error messages |
| -f F | Use file F instead of the standard font directory |
| -F DIR | Search directory DIR for device description files |
| -i | Read standard input after all files |
| -I DIR | Search directory DIR for files included with .so requests |
| -m NAME | Use macro file NAME (e.g., -ms, -man, -mm, -mom) |
| -M DIR | Search directory DIR for macro files |
| -n N | Number first page N |
| -o LIST | Output only pages in LIST |
| -p | Preprocess with pic (for diagrams) |
| -P OPTION | Pass OPTION to the postprocessor |
| -r CN | Set register C to the value N |
| -R | Preprocess with refer (for bibliographic references) |
| -s | Preprocess with soelim (for file inclusion) |
| -S | Safer mode (disable some potentially unsafe features) |
| -t | Preprocess with tbl (for tables) |
| -T DEV | Prepare output for device DEV (ps, pdf, html, etc.) |
| -U | Unsafe mode (enable potentially dangerous operations) |
| -v | Print version information |
| -V | Print detailed version information |
| -w | Enable warning messages |
| -W LEVEL | Set warning level to LEVEL |
| -z | Suppress formatted output (useful for checking syntax) |
Examples
How to Use These Examples
The examples below show common ways to use the troff command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
troff -ms document.ms | dpost | lpr
Format a document using ms macros, convert to PostScript with dpost, and send to the printer. This traditional workflow was common for printing formatted documents.
troff -man manual.1 | dpost > manual.ps
Format a man page and convert it to PostScript. This creates a high-quality, typeset version of a manual page suitable for printing.
troff -ms -Tpdf document.ms > document.pdf
Format a document with ms macros directly to PDF. Modern implementations like groff can output to various formats including PDF.
troff -t -e -ms technical.ms | dpost > technical.ps
Format a technical document with tables and equations to PostScript. The -t and -e options enable the tbl (table) and eqn (equation) preprocessors.
Advanced Examples:
troff -t -p -e -ms -rN2 document.ms | dpost > document.ps
Format a document with tables, pictures, and equations, starting page numbering from 2. This demonstrates combining multiple preprocessors and setting register values.
troff -mom document.mom | dpost > document.ps
Format a document using the mom (my own macros) package and output to PostScript. The mom macros offer a more accessible interface to troff's capabilities.