troff reads text files (written using an instream formatting language, see nroff) and formats the text for typesetting or laser printing.
The connection to Tcl is that the Tcl man pages - the only documentation that comes with the source - uses the *roff markup formatting language.
set filename [file normalize .../path/to/namespace.n]; # namespace.n for example purposes only cd [file dirname $filename] exec groff -Tpdf -man [file tail $filename] >output.pdf
Note that you only need to be in the same directory if you are using the documentation in the Tcl/Tk source checkouts. It's not necessary with the official source distributions as those have references to external files resolved during the build of the distribution.
Firstly, always remember to look at other manual pages to see what sort of things belong! (And note that the purpose of this tutorial is writing a manual page that renders nicely and which Tcl can properly convert to nice HTML pages like you see on https://www.tcl-lang.org/man/ and not general manual page writing.)
Tcl manual pages start with:
.so man.macros .TH name section version Tcl "Tcl Built-In Commands" .BS .SH NAME names \- description .SH SYNOPSIS .nf summary of commands/functions .fi .BE
The name is the name of the manual page.
The section is (typically) n for commands (e.g. lsearch), 3 for C API functions (e.g. Tcl_SetObjResult), or 1 for programs/shells (e.g. tclsh).
The version is the version of Tcl/extension where the page last had substantive changes.
The names is a comma-separated list of all the commands or functions documented on the page, and must (along with the description) be on a single line.
The description is a very short description of what the commands/functions do (e.g. lsearch's page says "See if a list contains a particular element"), and must be on a single line (along with the names).
The summary of commands/functions is what it says; check some examples for how to write them.
Sections start with a:
.SH "title of section in caps"
The quotes can be omitted if the title is a single word. If you want a subsection instead, use .SS instead of .SH
The following sections are normal for a Tcl manual page (and in this order):
Other sections may be added between DESCRIPTION and EXAMPLES, and many pages omit the EXAMPLES still.
Note that widget manual pages have additional sections.
Paragraphs (normally) start with a .PP directive (.LP and .P are equivalent). You indent a section of paragraphs by putting .RS before them and .RE afterwards.
To do a bulleted list, start each item in the list with:
.IP \(bu 3
To do a descriptive list item (like <DT><DD> in HTML) do this:
one line text that is the "name" of the item
rest of paragraph describing the item
The dot on a line by its own is optional, but makes things much more readable for you.
To do a table, start with .DS, finish with .DE, use a single line per row, and use real tab characters to separate the columns. (You might also need to use a .ta directive after the .DS to make things look right, but this is best tuned if you've got nroff or groff to hand!)
You can make a sequence of letters bold (used for literal parts of commands) by wrapping in \fB...\fR sequences, and you can make a sequence of letters italic (used for varying parts of commands) by wrapping in \fI...\fR sequences. Put a literal backslash in by using \e and any dash that isn't an inter-word hyphen (such as just used there) should be written as \- so that it is of a better length. (There are other hyphens available for advanced users; consult your *roff format documentation for details.)
Put a sequence of characters in (appropriate) quotes using the .QW directive, like this:
This is some text with some .QW "quoted bits" in the middle.
which renders like: