Create Your own Man Page

Step 1. Create a text file.

Create usual text file with information that you wont to see in your man page.
(In my case it is this.txt). We will make ready this file for "nroff" - document formatting tool. Two first line are mandatory. Keywords "NAME", "DESCRIPTION" must be in upper case. Put some symbols like 11111,22222,AAA... to mark out some blocks of text. You can put some "nroff" macroses .br,.TH,\If... (If you don't know something like 'sed' or 'perl' you have to put all macroses manually).

THIS C++ "May 18, 2001" "" "C++ Library"
this - pointer
The this pointer is a special pointer that exists for a class
while a nonstatic member function is executing. It is a pointer
to an object of the type of the class, and it points to the
object for which the member function currently is executing.

void Date::month_display()
	// These two statements do the same thing.
	cout << month;
	cout << this -> month;

One use of this pointer allows member functions to return
the invoking objet (or its address or a reference to it)
to the caller.
// Overloaded Date assignment.
Date& Date::operator=(const Date& dt)
    if (this != &dt)
        mo =;
        da = dt.da;
        yr = dt.yr;
        delete [] month;
        if (dt.month != 0)
            month = new char [strlen(dt.month)+1];
            strcpy(month, dt.month);
            month = 0;
    return *this;



Step 2. Create script

Create a sed script this.sed, that will put all macros into your this.txt file.

1s/^\(.*\)$/\.TH \1/
/NAME/s/^\(.*\)$/\.SH \1/
/DESCRIPTION/s/^\(.*\)$/\.SH \1/
/\<EXAMPLE\>/s/^\(.*\)$/\.SH \1/
/AUTHOR/s/^\(.*\)$/\.SH \1/


/^[a-z]/s/^\(.*\)$/\.BR \1/
s/(\([1-9]\))/ "(\1), "/g
s/(C++)/ "(C++), "/g
s/(C++)$/ "(C++)"/

   			  \\fIA\\fRnatoliy\ \\fIU\\fRrbanskiy


Step 3. Create temp file with nroff format.

sed -f this.sed this.txt | tee temp.txt | less

Step 4. Check how man page will look like

nroff -e -mandoc temp.txt | less -s

Step 5. Create zipped file

If everything is fine, rename your temp file. The extention is mandatory. It is a man section.
mv temp.txt this.3
Check, which zip format using your system for man pages ( ls /usr/share/man/man1/a* ). If extention is .bz2 - you should use bzip2 utility, if extention is .gz - use gzip instead.
bzip2 this.3 or gzip this.3
Your man page is ready!

Step 6. "Application tuning"

Create man directory.
mkdir $HOME/man
Create sub directory. Number is mandatory ( man section ).
mkdir $HOME/man/man3
Move your zipped file into this sub directory.
mv this.3.bz2 $HOME/man/man3/
mv this.3.gz $HOME/man/man3/
Check your $MANPATH variable.
If your man directory doesn't exists in path, you have to add two lines in your .profile or .bash_profile.
export MANPATH
and reread your profile (. .profile or source .profile)

If you have a root privileges, you can put this page into particular subman directory, or even create new one. If you create new sub directory ( like in my case, I created manC++ sub directory inside of /usr/share/man directory ), you have to add in MANSECT the name of your new section (in my case it is 'C++', without man!). The MANSECT is in file /etc/manpath.config or /etc/man.config ( depends from system ). After this, as root you should run
updatedb command.

man C++ this