Index: doc/Makefile
===================================================================
--- doc/Makefile	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/Makefile	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -32,12 +32,4 @@
 MODELS_RST = $(patsubst ../sasmodels/models/%.py,model/%.rst,$(MODELS_PY))
 
-model/img/%: ../sasmodels/models/img/%
-	$(COPY) $< $@
-
-model/%.rst: ../sasmodels/models/%.py
-	$(PYTHON) genmodel.py $< $@
-
-.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest build
-
 help:
 	@echo "Please use \`make <target>' where <target> is one of"
@@ -53,4 +45,15 @@
 	@echo "  doctest   to run all doctests embedded in the documentation (if enabled)"
 
+model/img/%: ../sasmodels/models/img/%
+	$(COPY) $< $@
+
+model/%.rst: ../sasmodels/models/%.py
+	$(PYTHON) genmodel.py $< $@
+
+ref/models/index.rst: gentoc.py $(MODELS_PY)
+	$(PYTHON) gentoc.py $(MODELS_PY)
+
+.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest build
+
 api: genapi.py
 	$(RMDIR) api
@@ -61,5 +64,5 @@
 	$(MKDIR) model/img
 
-build: model $(MODELS_RST) $(IMG_DEST) api
+build: model $(MODELS_RST) $(IMG_DEST) api ref/models/index.rst
 	#cd ../.. && python setup.py build
 
Index: doc/genmodel.py
===================================================================
--- doc/genmodel.py	(revision cb6ecf4c19ecd47d43632a230eb29c56fba61a7c)
+++ doc/genmodel.py	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -3,5 +3,5 @@
 sys.path.insert(0,'..')
 
-# Convert ../sasmodels/models.name.py to sasmodels.models.name
+# Convert ../sasmodels/models/name.py to sasmodels.models.name
 module_name = sys.argv[1][3:-3].replace('/','.').replace('\\','.')
 print module_name
Index: doc/gentoc.py
===================================================================
--- doc/gentoc.py	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
+++ doc/gentoc.py	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -0,0 +1,112 @@
+import sys
+# make sure sasmodels is on the path
+sys.path.append('..')
+
+from os import mkdir
+from os.path import basename, exists, join as joinpath
+from sasmodels.core import load_model_definition
+
+
+TEMPLATE="""\
+..
+    Generated from doc/gentoc.py -- DO NOT EDIT --
+
+.. %(label)s:
+
+%(bar)s
+%(title)s
+%(bar)s
+
+.. toctree::
+
+"""
+
+MODEL_TOC_PATH = "ref/models"
+
+def _make_category(category_name, label, title, parent=None):
+    file = open(joinpath(MODEL_TOC_PATH, category_name+".rst"), "w")
+    file.write(TEMPLATE%{'label':label, 'title':title, 'bar':'*'*len(title)})
+    if parent:
+        _add_subcategory(parent, category_name)
+    return file
+
+def _add_subcategory(file, category_name):
+    file.write("    %s.rst\n"%category_name)
+
+def _add_model(file, model_name):
+    file.write("    ../../model/%s.rst\n"%model_name)
+
+def generate_toc(model_files):
+    if not model_files:
+        print >>sys.stderr, "gentoc needs a list of model files"
+
+    # find all categories
+    category = {}
+    for item in model_files:
+        # assume model is in sasmodels/models/name.py, and ignore the full path
+        model_name = basename(item)[:-3]
+        if model_name.startswith('_'): continue
+        model_definition = load_model_definition(model_name)
+        if not hasattr(model_definition, 'category'):
+            print >>sys.stderr, "Missing category for",item
+        else:
+            category.setdefault(model_definition.category,[]).append(model_name)
+
+    # Check category names
+    for k,v in category.items():
+        if len(v) == 1:
+            print >>sys.stderr, "Category %s contains only %s"%(k,v[0])
+
+    # Generate category files
+    # Assume that top-level groups are:
+    #    shape, shape-independent, structure-factor and custom
+    # Supports a two-level category structure.
+
+    if not exists(MODEL_TOC_PATH): mkdir(MODEL_TOC_PATH)
+    model_toc = _make_category(
+        'index',  'Models', 'Model Functions')
+    shape_toc = _make_category(
+        'shape',  'Shapes', 'Shape Functions', model_toc)
+    free_toc = _make_category(
+        'shape-independent',  'Shape-independent',
+        'Shape-Independent Functions', model_toc)
+    struct_toc = _make_category(
+        'structure-factor',  'Structure-factor', 'Structure Factors', model_toc)
+    custom_toc = _make_category(
+        'custom-models',  'Custom-models', 'Custom Models', model_toc)
+    model_toc.close()
+
+    # remember to top level categories
+    cat_files = {
+        'shape':shape_toc,
+        'shape-independent':free_toc,
+        'structure-factor': struct_toc,
+        'custom': custom_toc,
+        }
+
+    # Process the model lists
+    for k,v in sorted(category.items()):
+        if ':' in k:
+            cat,subcat = k.split(':')
+            cat_file = cat_files[cat]
+            label = "-".join((cat,subcat))
+            filename = label
+            title = subcat.capitalize()+" Functions"
+            sub_toc = _make_category(filename, label, title, cat_file)
+            for model in sorted(v):
+                _add_model(sub_toc, model)
+            sub_toc.close()
+        else:
+            if k not in cat_files:
+                print >>sys.stderr, "Unknown category %s containing"%cat, v
+            else:
+                cat_file = cat_files[k]
+                for model in sorted(v):
+                    _add_model(cat_file, model)
+
+    # Close the top-level category files
+    for f in cat_files.values(): f.close()
+
+
+if __name__ == "__main__":
+    generate_toc(sys.argv[1:])
Index: doc/index.rst
===================================================================
--- doc/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/index.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -15,5 +15,5 @@
 
    guide/index.rst
-   models/index.rst
+   ref/index.rst
    api/index.rst
 
Index: doc/models/cylinders.rst
===================================================================
--- doc/models/cylinders.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.. _models-cylinders:
-
-**************
-Cylinder-based
-**************
-
-.. toctree::
-
-   ../model/cylinder.rst
-   ../model/capped_cylinder.rst
-   ../model/core_shell_cylinder.rst
Index: doc/models/ellipsoids.rst
===================================================================
--- doc/models/ellipsoids.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.. _models-ellipsoids:
-
-***************
-Ellipsoid-based
-***************
-
-.. toctree::
-
-   ../model/ellipsoid.rst
-   ../model/triaxial_ellipsoid.rst
Index: doc/models/index.rst
===================================================================
--- doc/models/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,11 +1,0 @@
-*******************
-SAS Model Reference
-*******************
-
-.. toctree::
-   :numbered: 4
-   :maxdepth: 4
-
-   intro.rst
-   models.rst
-   refs.rst
Index: doc/models/intro.rst
===================================================================
--- doc/models/intro.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,49 +1,0 @@
-
-.. _models-intro:
-
-************
-Introduction
-************
-
-Many of our models use the form factor calculations implemented in a c-library provided by the NIST Center for Neutron
-Research and thus some content and figures in this document are originated from or shared with the NIST SANS Igor-based
-analysis package.
-
-This software provides form factors for various particle shapes. After giving a mathematical definition of each model,
-we show the list of parameters available to the user. Validation plots for each model are also presented.
-
-Instructions on how to use SasView itself are available separately.
-
-To easily compare to the scattering intensity measured in experiments, we normalize the form factors by the volume of
-the particle
-
-.. math::
-
-    P(\vec q) = \frac{P_o(\vec q)}{V} = \frac{1}{V} F(\vec q) F^*(\vec q)
-
-with
-
-    F(\vec q) = \int\int\int dV\rho(\vec r) e^{-i\vec q \cdot \vec r}
-
-where $P_0(\vec q)$ is the un-normalized form factor, $\rho(\vec r)$ is the scattering length density at a given
-point in space and the integration is done over the volume $V$ of the scatterer.
-
-For systems without inter-particle interference, the form factors we provide can be related to the scattering intensity
-by the particle volume fraction
-
-.. math::
-
-    I(\vec q) = \Phi P(\vec q)
-
-Our so-called 1D scattering intensity functions provide $P(Q)$ for the case where the scatterer is randomly oriented. In
-that case, the scattering intensity only depends on the length of $Q$ . The intensity measured on the plane of the SAS
-detector will have an azimuthal symmetry around $Q=0$.
-
-Our so-called 2D scattering intensity functions provide $P(Q,\phi)$ for an oriented system as a function of a
-$q$ vector in the plane of the detector. We define the angle $\phi$ as the angle between the $q$ vector and the horizontal
-($x$) axis of the plane of the detector.
-
-For information about polarised and magnetic scattering, see here_.
-
-
-.. _here: polar_mag_help.html
Index: doc/models/lamellae.rst
===================================================================
--- doc/models/lamellae.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,9 +1,0 @@
-.. _models-lamellae:
-
-**************
-Lamellae-based
-**************
-
-.. toctree::
-
-   ../model/lamellar.rst
Index: doc/models/models.rst
===================================================================
--- doc/models/models.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,14 +1,0 @@
-.. _models:
-
-******
-Models
-******
-
-.. toctree::
-   :numbered:
-   :maxdepth: 4
-
-   shapes.rst
-   independent.rst
-   structures.rst
-   custom.rst
Index: doc/models/refs.rst
===================================================================
--- doc/models/refs.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,35 +1,0 @@
-.. _models-refs:
-
-**********
-References
-**********
-
-*Small-Angle Scattering of X-Rays*
-A Guinier and G Fournet
-John Wiley & Sons, New York (1955)
-
-P Stckel, R May, I Strell, Z Cejka, W Hoppe, H Heumann, W Zillig and H Crespi
-*Eur. J. Biochem.*, 112, (1980), 411-417
-
-G Porod
-in *Small Angle X-ray Scattering*
-(editors) O Glatter and O Kratky
-Academic Press (1982)
-
-*Structure Analysis by Small-Angle X-Ray and Neutron Scattering*
-L.A Feigin and D I Svergun
-Plenum Press, New York (1987)
-
-S Hansen
-*J. Appl. Cryst.* 23, (1990), 344-346
-
-S J Henderson
-*Biophys. J.* 70, (1996), 1618-1627
-
-B C McAlister and B P Grady
-*J. Appl. Cryst.* 31, (1998), 594-599
-
-S R Kline
-*J Appl. Cryst.* 39(6), (2006), 895
-
-**Also see the references at the end of the each model function descriptions.**
Index: doc/models/shapes.rst
===================================================================
--- doc/models/shapes.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,15 +1,0 @@
-.. _models-shapes:
-
-******************
-Shape-based Models
-******************
-
-.. toctree::
-
-    spheres.rst
-    cylinders.rst
-    ellipsoids.rst
-    lamellae.rst
-    paracrystals.rst
-    parallelpipeds.rst
-
Index: doc/models/spheres.rst
===================================================================
--- doc/models/spheres.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.. _models-spheres:
-
-***************
-Sphere-based
-***************
-
-.. toctree::
-
-   ../model/sphere.rst
-
Index: doc/ref/index.rst
===================================================================
--- doc/ref/index.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
+++ doc/ref/index.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -0,0 +1,11 @@
+*******************
+SAS Model Reference
+*******************
+
+.. toctree::
+   :numbered: 4
+   :maxdepth: 4
+
+   intro.rst
+   models/index.rst
+   refs.rst
Index: doc/ref/intro.rst
===================================================================
--- doc/ref/intro.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
+++ doc/ref/intro.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -0,0 +1,49 @@
+
+.. _models-intro:
+
+************
+Introduction
+************
+
+Many of our models use the form factor calculations implemented in a c-library provided by the NIST Center for Neutron
+Research and thus some content and figures in this document are originated from or shared with the NIST SANS Igor-based
+analysis package.
+
+This software provides form factors for various particle shapes. After giving a mathematical definition of each model,
+we show the list of parameters available to the user. Validation plots for each model are also presented.
+
+Instructions on how to use SasView itself are available separately.
+
+To easily compare to the scattering intensity measured in experiments, we normalize the form factors by the volume of
+the particle
+
+.. math::
+
+    P(\vec q) = \frac{P_o(\vec q)}{V} = \frac{1}{V} F(\vec q) F^*(\vec q)
+
+with
+
+    F(\vec q) = \int\int\int dV\rho(\vec r) e^{-i\vec q \cdot \vec r}
+
+where $P_0(\vec q)$ is the un-normalized form factor, $\rho(\vec r)$ is the scattering length density at a given
+point in space and the integration is done over the volume $V$ of the scatterer.
+
+For systems without inter-particle interference, the form factors we provide can be related to the scattering intensity
+by the particle volume fraction
+
+.. math::
+
+    I(\vec q) = \Phi P(\vec q)
+
+Our so-called 1D scattering intensity functions provide $P(Q)$ for the case where the scatterer is randomly oriented. In
+that case, the scattering intensity only depends on the length of $Q$ . The intensity measured on the plane of the SAS
+detector will have an azimuthal symmetry around $Q=0$.
+
+Our so-called 2D scattering intensity functions provide $P(Q,\phi)$ for an oriented system as a function of a
+$q$ vector in the plane of the detector. We define the angle $\phi$ as the angle between the $q$ vector and the horizontal
+($x$) axis of the plane of the detector.
+
+For information about polarised and magnetic scattering, see here_.
+
+
+.. _here: polar_mag_help.html
Index: doc/ref/refs.rst
===================================================================
--- doc/ref/refs.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
+++ doc/ref/refs.rst	(revision 61ba6233ec36e842d625c589deec77f689b2a9b6)
@@ -0,0 +1,35 @@
+.. _models-refs:
+
+**********
+References
+**********
+
+*Small-Angle Scattering of X-Rays*
+A Guinier and G Fournet
+John Wiley & Sons, New York (1955)
+
+P Stckel, R May, I Strell, Z Cejka, W Hoppe, H Heumann, W Zillig and H Crespi
+*Eur. J. Biochem.*, 112, (1980), 411-417
+
+G Porod
+in *Small Angle X-ray Scattering*
+(editors) O Glatter and O Kratky
+Academic Press (1982)
+
+*Structure Analysis by Small-Angle X-Ray and Neutron Scattering*
+L.A Feigin and D I Svergun
+Plenum Press, New York (1987)
+
+S Hansen
+*J. Appl. Cryst.* 23, (1990), 344-346
+
+S J Henderson
+*Biophys. J.* 70, (1996), 1618-1627
+
+B C McAlister and B P Grady
+*J. Appl. Cryst.* 31, (1998), 594-599
+
+S R Kline
+*J Appl. Cryst.* 39(6), (2006), 895
+
+**Also see the references at the end of the each model function descriptions.**
