Natural Docs
Organizing the Menu

Natural Docs creates a file called Menu.txt in the project directory that you can edit to organize the menu.  Natural Docs will take care of adding and deleting entries as necessary, and it will even attempt to organize them by directory, but you have the option of improving it manually.

Order and Titles

If you’ve never edited it before, the menu file will be some comments explaining how to edit it and a list like you see below.

File: ClassA  (ClassA.h)
File: ClassB  (ClassB.h)
File: Globals  (Globals.h)

The list gets turned into a menu that looks like this:

It should be obvious what everything on each line is.  When Natural Docs made the menu, it decided on its own what each item should be titled and then put them in alphabetical order.  However, suppose we don’t like this.  We want Globals above the classes and we want spaces in the menu titles.  So we edit the file.

File: Globals  (Globals.h)
File: Class A  (ClassA.h)
File: Class B  (ClassB.h)

Run Natural Docs again and the menu is updated.

However, open the menu file again and you’ll see something interesting.

File: Globals  (Globals.h)
File: Class A  (no auto-title, ClassA.h)
File: Class B  (no auto-title, ClassB.h)

Natural Docs detected that you edited a couple of the titles and added a no auto-title attribute to each one.  This tells it never to change the titles on those entries.  You don’t have to worry about adding this attribute, Natural Docs will do it automatically.  However, to go back to automatic titles you have to manually delete it.

Grouping

This menu is good for our example, but in the real world, they get much much longer.  We can add groups to organize them further.  Natural Docs will create its own groups by directory, but you can add your own manually if that’s not good enough.

You can manually add groups as shown below.

File: Globals  (Globals.h)
Group: Classes {
   File: Class A  (no auto-title, ClassA.h)
   File: Class B  (no auto-title, ClassB.h) }

You can also nest them inside each other.

File: Globals  (Globals.h)
Group: Classes {
   File: Class A  (no auto-title, ClassA.h)
   Group: Nested Group {
      File: Class B  (no auto-title, ClassB.h)  }
   }

Open up the menu file again and take a look.

File: Globals  (Globals.h)

Group: Classes  {

   File: Class A  (no auto-title, ClassA.h)
   File: Class B  (no auto-title, ClassB.h)
   }  # Group: Classes

Natural Docs reformatted it.  When you’re organizing the menu, you don’t have to worry about the indentation or otherwise keeping it neat.  The file is reformatted every time it changes, so you can make quick and dirty edits and Natural Docs will keep it readable.

Besides making the menu easier to read, groups also serve another purpose.  Clicking on a group’s name will make it expand and collapse on modern browsers.  Go ahead and try it in the examples.  When the menu gets too long, certain groups will start being collapsed by default  This allows Natural Docs to work with large projects, where showing the entire menu at once is impractical.  For compatibility, this only happens on browsers that support it.  If a browser can’t expand or collapse menus, it always defaults to being completely open.

Indexes

Natural Docs will automatically determine what indexes your project needs and add them to the menu.  The entries will look like this:

Group: Index {

   Index: Everything
   Class Index: Classes
   Function Index: Functions
   }  # Group: Index

Like file entries, you can rename them by editing the title and reorder them by cutting and pasting.  However, if you decide you don’t want a particular index to be generated, just delete its entry and it will go away.  Again, like file entries, Natural Docs will detect this and add something new:

Don't Index: Functions

Like no auto-title, you have to delete that to make it automatic again.

Automatic Changes

You already saw that file entries default to being auto-titled.  Natural Docs tries to guess what the title of each of these files should be.  For example, if the first documented topic is a class, it will use the class name.  If you want to override a file’s title in the file itself instead of in the menu, add a “Title: [title]” comment to the top of it.  This way the title is stays with the file.

When Natural Docs needs to add a file to the menu, it will look for the best group to put it in by directory.  If your grouping mirrors the source tree somewhat, this will be a lot more accurate.  Also, if the group it’s putting it in is alphabetized, Natural Docs will maintain that alphabetization.  If an auto-title changes, it will reorganize the group to maintain its previous alphabetization, if any.

The only exceptions in alphabetization are for the indexes.  If a group only contains indexes, it can be the last item on the menu or in its parent group without making it count as unsorted.  Also, within groups that only contain indexes, the general index can be first, also without making the group count as unsorted.

Finally, if Natural Docs adds some files to a group and causes it to become too long, it will attempt to sub-group it based on directory.  However, it will only do this when its adding files on its own, so you don’t have to worry about it constantly messing up your groups.  Since new files aren’t added to a project that often, if you change the menu manually, it should stay that way for quite some time.

Extras
Title and Subtitle

In addition to files and groups, you can add a title and subtitle to your menu.

Title: My Project
SubTitle: Something That Does Something

File: Globals  (Globals.h)
Group: Classes
   File: Class A  (no auto-title, ClassA.h)
   File: Class B  (no auto-title, ClassB.h)
My Project
Something That Does Something

In addition to adding the title to the menu, the Title tag will also change the HTML page titles from “file title” to “file title - menu title”, making bookmarks clearer.

Text and Web Links

You can also add arbitrary text and web links to your menu.

File: Globals  (Globals.h)
Group: Classes  {
   Text: I couldn't think of good names for these classes.
   File: Class A  (no auto-title, ClassA.h)
   File: Class B  (no auto-title, ClassB.h)
   }
Link: Built with Natural Docs  (http://www.naturaldocs.org)
Classes

Even though comments use the # character, adding an anchor to a link (such as “http://www.website.com/page.html#anchor”) will still work.

Footers

Finally, you can add a footer to all your pages, such as a copyright notice.  Natural Docs will change any (c)’s to real copyright symbols.

Footer: Copyright (C) 2003 Me

You can see an example of a footer on the Natural Docs web site.

Errors

If there’s ever an error in the menu file, Natural Docs will tell you when it’s run.  It follows the GNU standards, so if you’re running it as part of a build process in an IDE, they will be even easier to find.

NaturalDocs:Menu.txt:6: txet is not a valid keyword

Also, it adds a comment for each error in the menu file so that you can search for them in a text editor.

# There is an error in this file.  Search for ERROR to find it.

File: Globals  (Globals.h)
Group: Classes  {
# ERROR: Txet is not a valid keyword.
   Txet: I couldn't think of good names for these classes.
   File: Class A  (no auto-title, ClassA.h)
   File: Class B  (no auto-title, ClassB.h)
   }

Remember that Natural Docs reformats the menu file whenever it’s run, so you only need to correct the error.  Natural Docs will remove the error comments on its own.

Portability and Versioning Systems

If you only use one input directory, all the files in the menu will have relative paths.  However, if you have more, Natural Docs will use the absolute path instead.

This is not a problem.  The menu file can still be shared between machines even if they don’t keep the source tree in the exact same location.  As long as you have the same layout within the source tree and point to the same base directories in the command line, Natural Docs will be able to convert the paths automatically to the new machine.

However, if you’re putting the menu file in a versioning system like CVS or SourceSafe, it might be very desirable to only have relative paths so anybody can check it in and only the real changes show.  In that case, instead of using multiple input directories, see if it’s possible to only have one input directory and use the -xi command line option to exclude the subdirectories you don’t want scanned.

That’s It!

And we’re done.  The syntax to do all of this is included in the menu file itself, so you don’t need to memorize everything.  You shouldn’t need to organize the menu very often, just after a lot of new files have been added and if you don’t like the default.

Note that if you’re using the non-framed HTML output format, changing the menu does require every output file to be updated.  However, Natural Docs has a special process just for this so it won’t take nearly as long as if it were rebuilding them all from scratch.  Still, if you’re working on a large project, it may be worth considering the framed HTML output format.

Copyright © 2003-2005 Greg Valure