r/linuxquestions • • Oct 20 '26

Manpages for multiple commands

Any recommendations for learning how to use the various macros for formatting? Ideally I'd be looking for something compatible across multiple OSes (Linux, NetBSD, OSX, and Haiku).

I written a couple of smaller pages by hacking small manpages but don't understand the formatting.

I also need to learn how the man system knows to find multiple commands in one page (man -w strncpy -> /usr/share/man/man3/strcpy.3.gz). I've written several small tools, primarily for working with acme, that I'd like to keep together in one page.

2 Upvotes

13 comments sorted by

2

u/aioeu Oct 20 '26 edited Oct 20 '26

There's a couple of roff macro packages for man pages. Take a look at groff_man (+ groff_man_style) and groff_mdoc. I would probably go with the former as it's older and probably more widely supported, but at least on Linux you can generally use either: man is usually set up to automatically detect which one you've used via the mandoc package — this switches its behaviour on whether you've used .TH or .Dd at the top of your document.

1

u/mcsuper5 Oct 20 '26

Thanks. - man groff_man looks like a really good start.

2

u/stevevdvkpe Oct 20 '26

UNIX man pages are formatted using the troff typesetting formatter (the "roff" part is short for "runoff", an earlier formatter that originated the convention of embedding formatting commands in text starting with a '.' at the beginning of a line). Man pages are designed to be capable of producing both nicely typeset output or output suitable for reading with a fixed-width font on a terminal or in line printer output using a variant called nroff. Specifically a macro package "man" or "mandoc" is used to help generate the conventional man page formatting (the standard sections like "NAME", "SYNOPSIS", "DESCRIPTION", etc.; paragraphs and margins, and so on). On most Linux systems the GNU groff package replaces the traditional troff/nroff programs.

When a man page documents mulitple functions, generally there are symbolic links from the alternate function names to the base copy of the man page. In the case of strncpy(), there is a symbolic link:

/usr/share/man/man3/strncpy.3.gz -> stpncpy.3.gz

and the man page source in stpcpy.3.gz documents both strncpy() and stpncpy().

1

u/mcsuper5 Oct 20 '26

Thanks. I was hoping to avoid a nest of symbolic links, but ...

2

u/calrogman Oct 20 '26
  1. New manuals should be written using mdoc. Refer to groff_mdoc(7) or mdoc(7).
  2. If your several utilities are so closely related that it makes sense to document them together, you can do so. Here's a short example: https://mandoc.bsd.lv/mdoc/style/multiple.html
  3. DO NOT create symlinks to manpages. Rely on the manpage database to index the pages.

1

u/mcsuper5 Oct 20 '26

Thank you.

1

u/Away_Combination6977 Oct 20 '26

I have read over this post 5 times... And I still have zero idea what you're asking.

And, I'll admit, I probably don't want to. 😂

1

u/SensoredHacker Oct 20 '26

ever read a manpage?
ever use manpage navigational macros?
ever wonder how you could write a manpage?
stay tuned....

1

u/SensoredHacker Oct 20 '26

its raining man!
hallelujah its raining manpages!

0

u/mcsuper5 Oct 20 '26

Not looking at navigational macros, I actively dislike info. Just looking at formatting and indenting properly.

1

u/MilkThin2930 Oct 20 '26

man man should explain the macros. makewhatis or man-db look for a series of comma-separated names in the NAME section of a man page when building the index.

1

u/Typical-Employment41 Oct 20 '26

Doesn't it make it much harder to find (with / shortcut) what different flags do for one command? How about using terminal multiplexer, like screen or tmux, to view them side by side?

1

u/SensoredHacker Oct 20 '26

troff.
I can always spot a manpage made properly,
Kudos, for investigating how to do it proper.