7

I'm making my first 'man' page and I'm using groff to do it. However, when I "compile" it and view it, it only takes up a certain amount of columns in my terminal. I've tried viewing other man pages just in case and they stretch with the width of my terminal. For a visual exmaple:

---------------------------------------
| stuff(1)             stuff(1)         |
|                                       |
| NAME                                  |
|       a tool to do stuff but          |
|       it isn't really working         |
|                                       |
| DESCRIPTION                           |
|       yadadyadyadyadyadyadydy         |
|       segfwefwefwefwe                 |
|                                       |
|       srgswrgwrg                      |
 ---------------------------------------

... and so on, hopefully you get the idea. Most man pages take the full width.

Right now, after writing my man page in a text file (using the groff/nroff "syntax"), I make it like this:

groff -Tascii -man ./path/to/man | more
n0pe
  • 9,411
  • 13
  • 60
  • 108
  • You should include the exact steps you're using to "compile" your man page. – wfaulk Aug 10 '11 at 13:58
  • @wfaulk, My bad I thought I had added it – n0pe Aug 10 '11 at 14:00
  • hm, btw, what about changing the heading of this question into a real question? For example: 'How to change the width of a man page using groff?' Or something like this ... – maxschlepzig Aug 10 '11 at 18:26
  • It doesn't really address your actual question, but I think it's worth pointing out that you can get real *nix `man` pages without all the pain of the old toolchain using something like [`ronn`](http://rtomayko.github.com/ronn/ronn.1.html). Also, I seem to recall hearing that the OpenBSD toolchain for `man` pages is different (I have no real basis for comparison, though). Here's [`man mdoc`](http://www.openbsd.org/cgi-bin/man.cgi?query=mdoc&sektion=7) – Hank Gay Aug 10 '11 at 19:27

2 Answers2

10

I checked what groff call is executed when I invoke man man (which uses the full width):

$ strace -o log -f -v -s 1024 -e trace=process man man

Looking for the groff call results in the following:

$ grep groff log | sed 's/\], \[.*//' 
28721 execve("/usr/bin/groff", ["groff", "-mtty-char", "-Tutf8", "-mandoc",
                                         "-rLL=171n", "-rLT=171n"

Now I resize my xterm:

$ strace -o log2 -f -v -s 1024 -e trace=process  man man
$ grep groff log2 | sed 's/\], \[.*//'
28852 execve("/usr/bin/groff", ["groff", "-mtty-char", "-Tutf8", "-mandoc",
                                         "-rLL=119n", "-rLT=119n"

Thus, I assume that the -rLL and -rLT arguments influence what terminal width is used by groff during compiling.

maxschlepzig
  • 56,316
  • 50
  • 205
  • 279
  • Interesting, I looked through `groff`'s manpage and it doesnt mention anything about `-rLL` or `-rLT`. I checked `troff` just in case because I know `groff` calls it. Then I just tried adding the flags with `119n` and it did work, however there is still some space and it doesn't seem to "stretch" and conform to the terminal size, more like a static setting. – n0pe Aug 10 '11 at 14:53
  • Thanks for outlining what you did by the way, very interesting – n0pe Aug 10 '11 at 14:53
  • @MaxMackie, yes, it is static - `man` just 'dynamically' determines the current terminal width and supplies it - i.e. in my first call my terminal was 171 columns wide and in the 2nd call it was 119 columns wide. – maxschlepzig Aug 10 '11 at 15:02
  • Alright I think my understanding of what groff actually does is flawed then. My "source" file (plaintext with macros) is the man file? Or does groff create a new file for me? If I were to create a man page and install it on my system, could groff help me do this, or does it only handle the formatting? For example, could I `groff -Tascii -man ./path > /man/file`? – n0pe Aug 10 '11 at 15:11
  • 1
    @MaxMackie, the man pages installed on my system are troff markup files, e.g. `gunzip -c /usr/share/man/man1/man.1.gz > man.1`, `file man.1` `man.1: troff or preprocessor input text`. Meaning that the `groff` command is called on-the-fly by the `man` command every time it is invoked. Perhaps there are systems which do some caching of the troff output (and perhaps only support 80 column output ...). – maxschlepzig Aug 10 '11 at 18:21
  • Ahhh thanks, that clears a lot up. Thanks for your help. – n0pe Aug 10 '11 at 19:12
  • @maxschlepzig: "Perhaps there are systems which do some caching of the troff output": There are. Look at [catman](http://www.unix.com/man-page/Linux/8/catman/). – wfaulk Aug 11 '11 at 04:37
  • THANK YOU !!! I ***SCOURED*** the web and couldn't find any answer like this! I was trying to get plain-text non-wrapped output of `man` pages *without* using `col -b`, because I didn't want it messing with spaces and tabs. After finally finding the right `groff` command, to my dismay, it didn't respect the COLUMNS variable. Using your solution, this works: `man2txt() { groff -t -e -mandoc -Tascii -a -rLL=9999 -rLT=9999 "$(man -w "${1}")"; }` -- test via `man2txt man | cat -v`. Hope this helps somebody down the line! – Sean Aug 03 '21 at 05:34
1

I believe most current versions of man will DoTheRightThing™ if you specify your man page as an argument containing a slash:

man ./stuff.1

wfaulk
  • 209
  • 2
  • 8