Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Custom formatting options for man pages UNIX
There was a previous hint that mentioned using 'col -b' to convert a manpage to plain text. Unfortunately, plain text doesn't give nice fontification (underline, italics, etc).

You can convert manpages to much nicer looking html (or postscript) for pretty printing or perusing in a web browser by using groff. In fact, the man command uses the ASCII driver for groff (or maybe troff) to get the output that it displays. Try the following examples:
 % groff -Tascii -man /usr/share/man/man1/ls.1 > ls.txt
% groff -Thtml -man /usr/share/man/man1/ls.1 > ls.html
% groff -Tps -man /usr/share/man/man1/ls.1 > ls.ps
The '-man' option is required, as it tells groff to use the 'an' set of macros. Look at man groff for more output types (devices) and options.

[Editor's note: Another previous hint explained how to download and install the newest version of groff if you want to be current. The HTML output option given in this hint is quite nice; use it on the "tcsh" man pages to make them easier to browse.]
    •    
  • Currently 2.00 / 5
  You rated: 2 / 5 (1 vote cast)
 
[5,458 views]  

Custom formatting options for man pages | 10 comments | Create New Account
Click here to return to the 'Custom formatting options for man pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Nice and quick alias
Authored by: vasi on May 15, '02 10:04:51AM

Here's a tcsh alias so you can use this more easily (this should be on one line):

alias htman '(groff -Thtml -man `man -w \\!* | head -n1` > "/tmp/htman.`echo \\!* | sed -e s/\\W/_/g`.html") >& /dev/null && open "/tmp/htman.`echo \\!* | sed -e s/\\W/_/g`.html"'

Just put this in your .cshrc, and then you'll be able to type "htman ls" or "htman 2 open" and the appropriate manpage will launch in your default browser (well actually whichever browser you set to open .html files).



[ Reply to This | # ]
manThor already does this
Authored by: dzurn on May 15, '02 03:07:42PM

Or you can use the "manThor" application for OS X, which gives a very nice view of the manual pages of interest. Much nicer to read!



[ Reply to This | # ]
manThor already does this
Authored by: dzurn on May 15, '02 03:22:03PM
manThor already does this
Authored by: garbanzito on May 16, '02 05:15:35PM

unless manThor has been recently much improved, i'd recommend instead ManOpen, available on VersionTracker...

re this groff hack, the HTML rendering is interesting, but ManOpen has the advantage of live hotlinks for cross-refernces, and ManOpen also does apropos, and can be called from the shell (e.g. "openman ls").



[ Reply to This | # ]
Project Builder beats them all…
Authored by: Gwenhiver on May 22, '02 04:45:12PM

For those of us using the Developer Tools, Project Builder has an "open man page…" command in the Help menu. It outputs the best HTML formatting I've seen so far.
Try the man page for hdiutil, for example, which appears quite bad with groff.



[ Reply to This | # ]
Re: Project Builder beats them all…
Authored by: jiclark on May 23, '02 12:09:36AM

I have the December Developer Tools installed, but that command isn't in the Help menu... Is it in a newer release?

Thanks, John



[ Reply to This | # ]
Re: Project Builder beats them all…
Authored by: Gwenhiver on May 23, '02 02:46:42AM

I have the April 2002 release... It must be a new feature then, sorry...



[ Reply to This | # ]
Errors?
Authored by: jtsombakos on May 15, '02 09:35:40PM

I tried the html sample and I got

Calling `echo showpage | gs -q -dSAFER -sDEVICE=pnmraw -r80 -sOutputFile=/var/tmp/groff-page-000351/%d /var/tmp/groff-ps-000351 -' returned status 256
/usr/share/man/man1/ls.1:43: warning: can't find font `CB'
/usr/share/man/man1/ls.1:48: warning: can't find font `CI'
/usr/share/man/man1/ls.1:76: warning: can't find special character `oq'
/usr/share/man/man1/ls.1:76: warning: can't find special character `cq'
/usr/share/man/man1/ls.1:84: warning: can't find special character `**'

and the html file isn't too well formatted.



[ Reply to This | # ]
Best use
Authored by: geoffsaulnier on May 22, '02 08:21:33PM

The best use I find of this stuff is when installing an app, I want to look at its man page(s), but they are not in $MANPATH. I just use

groff -man manfilename | more

were manfilename is the name of the man file you want to examine.

Obviously, to complete the install, you want to add these pages into $MANPATH and rebuild the apropos databases (I do this so infrequently, though, that I keep forgetting where the command lives to do that!!!)



[ Reply to This | # ]
Custom formatting options for man pages
Authored by: kd4ttc on Oct 16, '05 03:38:31PM

The format is not exactly the same for ascii printed to the terminal by the man utility. The bold characters do not show bold. However, postscript output is correctly bolded and looks pretty good. HTML is also good, though a little CSS would help make it look sweet.



[ Reply to This | # ]