groff_tmac(5)
π groff_tmac(5) β File Formats Manual, but make it make sense β¨
okay bestie, buckle up. this is groff_tmac(5) from File Formats Manual and it's literally all about macro files in the GNU roff typesetting system. i'm gonna walk you through it like we're texting, but every single detail is staying, fr fr π«Ά
πΈ NAME πΈ
groff_tmac β macro files in the GNU roff typesetting system
β¨ DESCRIPTION β¨
so check it: definitions of macros, strings, and registers for use in a roff(7) document can be collected into what we call macro files β these are roff input files designed to produce no output themselves but instead ease the preparation of other roff documents. it's giving "backstage crew, not the main character" energy π
there is no syntactical difference between a macro file and any other roff document β only its purpose distinguishes it. and when a macro file is installed at a standard location, named according to a certain convention, and suitable for use by a general audience, it is termed a macro package. the "tmac" name originated in early Unix culture as an abbreviation of "troff macros" (iykyk, history is wild π).
macro packages can be loaded by supplying the -m option to troff(1) or a groff front end. a macro file's name must have the form name.tmac (or tmac.name) and be placed in a "tmac directory" to be loadable with the -m name option. section "Environment" of troff(1) lists these directories, if you need the receipts π. alternatively, a groff document requiring a macro file can load it with the mso ("macro source") request.
macro files are named for their most noteworthy application, but β plot twist β a macro file need not define any macros. it can restrict itself to defining registers and strings or invoking other groff requests. it can even be empty. iconic lazy legend behavior tbh π
encode macro files in ISO 646:1991 IRV (US-ASCII) or ISO Latin-1 (8859-1). to prepare for a future groff release supporting UTF-8 input, restrict files to ISO 646 codes. also soelim(1) by design does not interpret mso requests, and the encodings used by documents employing a macro file can vary β so like, heads up π
π Macro packages π
some macro packages ("major" or "full-service") assume responsibility for page layout and other critical functions; others ("supplemental" or "auxiliary") do not. GNU roff provides most major macro packages found in AT&T and BSD Unix systems, an additional full-service package, and many supplemental packages. it's a whole buffet, bestie π
β οΈ Multiple full-service macro packages cannot be used by the same document. pick one, queen, you can't date them all π
auxiliary packages can, in general, be freely combined, though attention to their use of the groff language name spaces for identifiers (particularly registers, macros, strings, and diversions) should be paid. name space management challenged AT&T troff users; GNU troff's support for arbitrarily long identifiers affords few excuses for name collisions, apart from attempts at compatibility with the demands of historical documents. translation: no more "oops i clobbered your register" energy, you have zero excuses now π
π Man pages π
two full-service macro packages are specialized for formatting Unix reference manuals β they do not support features like footnotes or multiple columnation (sorry, no fancy).
anβ constructs man pages in a format introduced by Seventh Edition Unix (1979). its macro interface is small, and the package widely used; seegroff_man(7).docβ constructs man pages in a format introduced by 4.3BSD-Reno (1990). it provides many more features thanan, but is also larger, more complex, and not as widely adopted; seegroff_mdoc(7).
because readers of man pages often do not know in advance which macros are used to format a given document, a wrapper is available:
andocβ recognizes a document's use ofanordocand loads the corresponding macro package. multiple man pages, in either format, can be handled;andocreloads each macro package as necessary. lowkey the thoughtful friend who reads the room π«Ά
π General full-service packages π
the following packages each support composition of documents of any kind, from single-page memos to lengthy monographs. they are similar in functionality; select one that suits your taste. choose your fighter:
meβ originates in 2BSD (1978); seegroff_me(7).mmβ originates in Programmer's Workbench (PWB) Unix 1.0 (1977); seegroff_mm(7).momβ was contributed to groff in 2002, and freely exercises its many extended features. seegroff_mom(7).msβ originates in Sixth Edition Unix (1975); seegroff_ms(7).
π Localization packages π
for Western languages, an auxiliary package for localization sets the hyphenation mode and loads hyphenation patterns and exceptions. localization files can also adjust the date format and provide translations of strings used by some of the full-service macro packages; alter the input encoding (see the next section); and change the amount of supplemental inter-sentence space. for Eastern languages, the localization file defines character classes and sets flags on them. by default, troffrc loads the localization file for English.
transβ loads localized strings used by various macro packages after their localized forms have been prepared by a localization macro file.
groff provides the following localization files β here's the whole roster π:
csβ Czech; localizesman,me,mm,mom, andms. sets the input encoding to Latin-2 by loadinglatin2.tmac.de,denβ German; localizesman,me,mm,mom, andms. sets the input encoding to Latin-1 by loadinglatin1.tmac.de.tmacselects hyphenation patterns for traditional orthography, andden.tmacdoes the same for the new orthography ("Rechtschreibreform").
enβ English. sets the input encoding to Latin-1 by loadinglatin1.tmac.esβ Spanish; localizesman,me,mm,mom, andms. sets the input encoding to Latin-9 by loadinglatin9.tmac.frβ French; localizesman,me,mm,mom, andms. sets the input encoding to Latin-9 by loadinglatin9.tmac.itβ Italian; localizesman,me,mm,mom, andms. sets the input encoding to Latin-1 by loadinglatin1.tmac.jaβ Japanese.plβ Polish; localizesman,me,mm,mom, andms. sets the input encoding to Latin-2 by loadinglatin2.tmac.ruβ Russian; localizesman,me,mm,mom, andms. sets the input encoding to KOI8-R by loadingkoi8-r.tmac.svβ Swedish; localizesman,me,mm,mom, andms. sets the input encoding to Latin-1 by loadinglatin1.tmac. some of the localization of themmpackage is handled separately; seegroff_mmse(7).zhβ Chinese.
π§ Input encodings π§
localization influences automatic hyphenation in two distinct but related respects. a macro file specific to a character coding identifies which character codes correspond to letters expected in the language's hyphenation pattern files and sets up case equivalences for those letters. a language's macro file determines which of these letters are equivalent to other letters for hyphenation purposes. the way these two layers stack β it's giving teamwork, it's giving collab πβ¨
for example, in English, the letter "Γ±" occurs in loan words. the latin1.tmac and latin9.tmac macro files define a hyphenation code for "Γ±" and make "Γ" equivalent to it. the English localization file en.tmac furthermore makes "Γ±" equivalent to "n". in Spanish (es.tmac), however, "Γ±" and "n" are not equivalent. the language localization file loads an appropriate encoding localization file; a document need not do so directly. so like, don't @ me, it's handled π
latin1,latin2,latin5,latin9β support the ISO Latin-1, Latin-2, Latin-5, and Latin-9 encodings (8859-1,8859-2,8859-9, and8859-15, respectively).koi8-rβ supports the KOI8-R encoding. KOI8-R code points in the range0x80β0x9Fare not valid input to GNU troff; see section "Identifiers" ingroff(7). this should be no impediment to practical documents, as these KOI8-R code points do not encode letters, but box-drawing symbols and characters that are better obtained via special character escape sequences; seegroff_char(7).
π¦ General auxiliary packages π¦
the macro packages in this section are not intended for stand-alone use, but can add functionality to any other macro package or to plain ("raw") groff documents. they're the accessory, not the outfit π
62bitβ provides macros for addition, multiplication, and division of 62-bit integers (allowing safe multiplication of signed 31-bit integers, for example). math girlies rise π₯hdtblβ allows the generation of tables using a syntax similar to the HTML table model. this Heidelberger table macro package is not a preprocessor, which can be useful if the contents of table entries are determined by macro calls or string interpolations. compare totbl(1). it works only with thepsandpdfoutput devices. seegroff_hdtbl(7).papersizeβ enables the paper format to be set on the command line with the-d paper=fmtoption to troff. valid fmts are the ISO and DIN formats "A0βA6", "B0βB6", "C0βC6", and "D0βD6"; the U.S. formats "letter", "legal", "tabloid", "ledger", "statement", and "executive"; and the envelope formats "com10", "monarch", and "DL". all formats, even those for envelopes, are in portrait orientation: the longer measurement is vertical. appending "l" (ell) to any of these denotes landscape orientation instead. this macro file assumes one-inch horizontal margins, and sets registers recognized by the groffman,mdoc,mm,mom, andmspackages to configure them accordingly. if you want different margins, you will need to use those packages' facilities, or trofflland/orporequests, to adjust them. an output device typically requires command-line options-pand-lto override the paper dimensions and orientation, respectively, defined in itsDESCfile; see subsection "Paper format" ofgroff(1). this macro file is normally loaded at startup by thetroffrcfile when formatting for a typesetter (but not a terminal). ok that was a lot but you got this πͺpdfpicβ provides a single macro,PDFPIC, that operates in two modes. if it is not used withgropdf, the given file must be a PDF;PDFPICthen relies on the external programpdftops(1)to convert the PDF to an encapsulated PostScript (EPS) file and calls thePSPICmacro with which it shares an interface. if output is to a PDF document,PDFPICuses the "pdf: pdfpic" device extension command (seegropdf(1)); the given file can then be a PDF or any graphic file format supported bygropdf.
since PDFPIC needs to discover the width and height of the image (to check if sufficient room exists to place it on the page), it has dependencies on external programs as shown below. πΈ
okay so for gropdf's image-detective era, here's the vibe check table β no cap, this was a whole box-drawing situation in the original, now in bullet form because we're not doing tables:
.pdfβpdfinfo(1)β,file(1)β,identify(1)β.jpgβpdfinfo(1)β,file(1)β,identify(1)β.jp2βpdfinfo(1)β,file(1)β,identify(1)βotherβpdfinfo(1)β,file(1)β,identify(1)β
To include image formats such as PNG, PAM, and GIF, gropdf relies upon PerlMagick modules to embed the graphic. They are not needed for the types listed in the table above.
If the required programs are not available, the file is treated as a PDF; failure is likely if it is not one β fr fr, that's the warning.
pic β supplies definitions of the macros PS, PE, PF, and PY, used with the pic(1) preprocessor. They center each picture. Use it if your document does not use a full-service macro package, or that package does not supply working pic macro definitions β lowkey a fallback moment. Except for man and mdoc, those provided with groff already do so (exception: mm employs the name PF for a different purpose).
pspic β provides a macro, PSPIC, that includes a PostScript graphic in a document. It's giving PostScript main character energy. The ps, dvi, html, and xhtml output devices support such inclusions; for all other drivers, the image is replaced with a rectangular border of the same size β yes, a rectangle, that's the vibe. pspic.tmac is loaded at startup by the troffrc file.
Its syntax is as follows.
.PSPIC [-L|-R|-C|-I n] file [width [height]]
file is the name of the PostScript file; width and height give the desired width and height of the image. If neither a width nor a height argument is specified, the image's natural width (as given in the file's bounding box) or the current line length is used as the width, whatever is smaller. The width and height arguments may have scaling units attached; the default scaling unit is i. PSPIC scales the graphic uniformly in the horizontal and vertical directions so that it is no more than width wide and height high. Option -C centers the graphic horizontally; this is the default. -L and -R left- and right-align the graphic, respectively. -I indents the graphic by n (with a default scaling unit of m).
To use PSPIC within a diversion, we recommend extending it with the following code, assuring that the diversion's width completely covers the image's width.
.am PSPIC
. vpt 0
\h'(\\n[ps-offset]u + \\n[ps-deswid]u)'
. sp -1
. vpt 1
..
Failure to load PSPIC's image argument is not an error. (The psbb request does issue an error diagnostic.) To make such a failure fatal, append to the pspic*error-hook macro.
.am pspic*error-hook
. ab
..
ptx β provides a macro, xx, to format permuted index entries as produced by the GNU ptx(1) program. If your formatting needs differ, copy the macro into your document and adapt it β main character energy, adapt it to your needs.
rfc1345 β defines special character escape sequences named for the glyph mnemonics specified in RFC 1345 and the digraph table of the Vim text editor. See groff_rfc1345(7) β iykyk.
sboxes β this one is the interface to the pdf: background device extension command supported by gropdf(1). Using this package, groff ms documents can draw colored rectangles beneath any output. It's giving arts-and-crafts but make it PDF π¨ β obsessed.
Here's the macro that starts a box:
.BOXSTART SHADED color OUTLINED color INDENT size WEIGHT size
It begins a box, where the argument after SHADED gives the fill color and that after OUTLINED the border color. Omit the former to get a borderless filled box and the latter for a border with no fill. The specified WEIGHT is used if the box is OUTLINED.
INDENT precedes a value that leaves a gap between the border and the contents inside the box.
Each color must be a defined groff color name, and each size a valid groff numeric expression. The keyword/value pairs can be specified in any order.
Boxes can be stacked, so you can start a box within another box; usually the later boxes would be smaller than the containing box, but this is not enforced. When using BOXSTART, the left position is the current indent minus the INDENT in the command, and the right position is the left position (calculated above) plus the current line length and twice the indent.
.BOXSTOP
takes no parameters. It closes the most recently started box at the current vertical position after adding its INDENT spacing.
Your groff documents can conditionally exercise the sboxes macros. The register GSBOX is defined if the package is loaded, and interpolates a true value if the pdf output device is in use.
sboxes furthermore hooks into the groff_ms(7) package to receive notifications when footnotes are growing, so that it can close boxes on a page before footnotes are printed. When that condition obtains, sboxes will close open boxes two points above the footnote separator and re-open them on the next page. (This amount probably will not match the box's INDENT.)
See βUsing PDF boxes with groff and the ms macrosβ for a demonstration.
trace β aids the debugging of groff documents by tracing macro calls. See groff_trace(7) β debugging slay.
www β defines macros corresponding to HTML elements. See groff_www(7) β HTML era.
Naming π
okay so this is a little history lesson, and it's honestly so real. ngl, AT&T nroff and troff were implemented before the conventions of the modern C getopt(3) call evolved, and used a naming scheme for macro packages that looks oddly terse to modern eyes. The formatter's -m option was the main means of loading a macro package, and its argument had to follow immediately without intervening space. This looked like a long option name preceded by a single minusβa sensation in the computer stone age. Macro packages therefore came to be known by names that started with the letter βmβ, which was omitted from the name of the macro file as stored on disk. For example, the manuscript macro package was stored as tmac.s and loaded with the option -ms. It has since become conventional in operating systems to use a suffixed file name extension to suggest a file type or format, thus we see roff documents with names ending in .man, .me, and so on.
groff commands permit space between an option and its argument. The syntax βgroff -m sβ makes the macro file name more clear but may surprise users familiar with the original convention, unaware that the package's βrealβ name was βsβ all along. For such packages of long pedigree, groff accommodates different users' expectations by supplying wrapper macro files that load the desired file with mso requests. Thus, all of βgroff -m sβ, βgroff -m msβ, βgroff -msβ, and βgroff -mmsβ serve to load the manuscript macros.
Inclusion π
bestie, the traditional method of employing a macro package is to specify the β-m packageβ option to the formatter, which then reads package's macro file prior to any input. Historically, package was sought in a file named tmac.package (that is, with a βtmac.β prefix). GNU troff searches for package.tmac in the macro path; if not found, it looks for tmac.package instead, and vice versa.
Alternatively, one could include a macro file with the request βso file-nameβ; the argument is resolved as fopen(3) would, from the current working directory of the formatter. This approach was inadequate to locate macro packages, since systems stored them in varying locations. GNU troff offers an improved feature in the similar request βmso package-file-nameβ, which searches the macro path for package-file-name. Because its argument is a file name, its β.tmacβ component must be included for the file to be found.
If a sourced file requires preprocessing, for example if it includes tbl tables or eqn equations, the preprocessor soelim(1) must be used. This can be achieved with a pipeline or by specifying the -s option to groff(1). man(1) librarian programs typically run soelim automatically β no cap. (As a rule, macro packages themselves do not require preprocessing.)
β¨ Writing macros β¨
Okay bestie, so a roff(7) document is literally just a text file that's been glowed up with predefined formatting constructs β requests, escape sequences, strings, numeric registers, and macros from a macro package. roff(7) is where all those elements get described, iykyk.
To give a document its own personal style, the most useful thing you can do is extend the existing elements by defining some macros for the repeating tasks. The best place to put them? Near the beginning of the document, or in a whole separate file. Main character energy for your boilerplate, honestly.
Macros without arguments are basically just strings β cute, simple. But the full power of macros hits when you pass arguments with a macro call. Inside the macro definition, the arguments are available as the escape sequences \$1, ..., \$9, \$[...], \$*, and \$@. The name the macro was called under lives in \$0, and the number of arguments is in register \n[.$]. See groff(7) for the deets. π
π Drafting macros
So one approach is to temporarily disable escape sequences by bracketing a macro definition with eo and ec requests. Iconic little sandwich:
.eo
.ds midpart was called with the following
.de print_args
\f[I]\$0\f[] \*[midpart] \n[.$] arguments: \$*
..
.ec
Heads up though β the above has limitations. It's unsuitable for a macro that needs certain interpolations at the time it's defined, or for indirect definitions of identifiers. See the section "Copy mode" of groff(7).
In those cases, you might define and test the macro with the escape character doubled before escape sequences that get interpreted even in copy mode, then bracket it with eo and ec requests, un-double the escape characters, then test again. Annoying? Maybe. Worth it? Absolutely. π¦
π Tips for macro definitions
- Use only control lines in macro definitions β like, start every input line with a control character.
groff'snoprequest makes text lines unnecessary, so you don't even need them:
.de Text
. if (\\n[.$] == 0) \
. return
. nop \&\\$*\&
..
- Write a comment macro that works in both draft and non-draft modes. Since the escape character is disabled in draft mode, trouble might occur when comment escape sequences are used. Not the vibe we want:
.de c
..
.c This is my comment.
- Comment lengthy macro definitions. Future you will literally thank present you. π«Ά
- Use empty requests, and indentation after control characters, to clarify a macro's structure. It's giving organized. It's giving readable. Periodt.
π Authors
This document was written by Werner Lemberg and G. Branden Robinson. Legends, honestly. π
β See also
Groff: The GNU Implementation of troff, by Trent A. Fisher and Werner Lemberg, is the primary groff manual. You can browse it interactively with info groff.
groff(1)β an overview of the groff system.groff_man(7),groff_mdoc(7),groff_me(7),groff_mm(7),groff_mom(7),groff_ms(7),groff_rfc1345(7),groff_trace(7), andgroff_www(7)β these are groff macro packages. A whole squad. πgroff(7)β summarizes the language recognized by GNU troff.troff(1)β documents the default macro file search path.
And that's a wrap, bestie! This lil masterpiece is from groff 1.24.2, dated 2026-10-01 β go forth and macro responsibly. πβ¨π
π¦ where this page comes from
- alpine 3.24: groff-doc 1.24.2-r0 Β· GPL-3.0-or-later
- Copyright 2000-2024 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms