Index: doc/Makefile
===================================================================
--- doc/Makefile	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/Makefile	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,132 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+PYTHON       ?= python
+SPHINXOPTS    =
+SPHINXBUILD   = $(PYTHON) -m  sphinx.__init__
+PAPER        ?= letter
+BUILDDIR      = _build
+ifdef ComSpec
+    RMDIR   = del /s/q/f
+    CPDIR   = xcopy /q/e/i
+    MKDIR   = mkdir
+    PATHSEP = $(strip \)
+    COPY    = copy
+else
+    RMDIR   = rm -rf
+    CPDIR   = cp -rp
+    MKDIR   = mkdir -p
+    PATHSEP = $(strip /)
+    COPY    = cp
+endif
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+IMG_SOURCE = $(wildcard ../sasmodels/models/img/*)
+IMG_DEST = $(patsubst ../sasmodels/models/img/%,model/img/%,$(IMG_SOURCE))
+MODELS_PY = $(wildcard ../sasmodels/models/[a-z]*.py)
+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"
+	@echo "  html      to make standalone HTML files"
+	@echo "  dirhtml   to make HTML files named index.html in directories"
+	@echo "  pickle    to make pickle files"
+	@echo "  json      to make JSON files"
+	@echo "  htmlhelp  to make HTML files and a HTML help project"
+	@echo "  qthelp    to make HTML files and a qthelp project"
+	@echo "  latex     to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  changes   to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck to check all external links for integrity"
+	@echo "  doctest   to run all doctests embedded in the documentation (if enabled)"
+
+api: genapi.py
+	$(RMDIR) api
+	$(PYTHON) genapi.py
+
+model:
+	$(MKDIR) model
+	$(MKDIR) model/img
+
+build: model $(MODELS_RST) $(IMG_DEST) api
+	#cd ../.. && python setup.py build
+
+upload:
+	scp -r _build/html/* reflectometry.org:web/danse/docs/sasmodels
+	scp _build/latex/SASModels.pdf reflectometry.org:web/danse/download
+
+clean:
+	-rm -rf _build model api
+
+html: build
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html
+	@echo
+	@echo "Build finished. The HTML pages are in _build/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in _build/dirhtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in _build/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in _build/qthelp, like this:"
+	@echo "# qcollectiongenerator _build/qthelp/Periodic Table.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile _build/qthelp/Periodic Table.qhc"
+
+latex: build
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in _build/latex."
+	@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
+	      "run these through (pdf)latex."
+
+pdf: latex
+	$(MAKE) -C _build/latex all-pdf
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes
+	@echo
+	@echo "The overview file is in _build/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in _build/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in _build/doctest/output.txt."
Index: doc/README.txt
===================================================================
--- doc/README.txt	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/README.txt	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,23 @@
+This is the top level build direcgtory for the periodictable
+documentation.  All of the documentation is written using
+sphinx, a python documentation system using restructured text.
+
+See the User Guide section "Contributing Changes" for details
+on how to build the documentation.
+
+Manifest:
+
+    Makefile    use "make clean html pdf" to build the docs
+    guide       user documentation
+    api         auto-generated interface documentation
+    plots       programs to generate figures
+    index.rst   top level include document
+    genmods.py  creates the module index files
+    conf.py     sphinx configuration
+    rst_prolog  restructured text macros (for units)
+    discoverer, 
+    shelltable  sample extensions
+    _static     images and style sheets
+    _templates  page layouts
+    _extensions sphinx extensions
+    _build      output directory
Index: doc/_extensions/dollarmath.py
===================================================================
--- doc/_extensions/dollarmath.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/_extensions/dollarmath.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,59 @@
+# This program is public domain
+# Author: Paul Kienzle
+r"""
+Allow $math$ markup in text and docstrings, ignoring \$.
+
+The $math$ markup should be separated from the surrounding text by spaces.  To
+embed markup within a word, place backslash-space before and after.  For
+convenience, the final $ can be followed by punctuation (period, comma or
+semicolon).
+"""
+
+import re
+
+_dollar = re.compile(r"(?:^|(?<=\s))[$]([^\n]*?)(?<![\\])[$](?:$|(?=\s|[.,;\\]))")
+_notdollar = re.compile(r"\\[$]")
+
+def replace_dollar(content):
+    original = content
+    content = _dollar.sub(r":math:`\1`",content)
+    content = _notdollar.sub("$", content)
+    #if '$' in content:
+    #    import sys
+    #    sys.stdout.write("\n========> not converted\n")
+    #    sys.stdout.write(content)
+    #    sys.stdout.write("\n")
+    #elif '$' in original:
+    #    import sys
+    #    sys.stdout.write("\n========> converted\n")
+    #    sys.stdout.write(content)
+    #    sys.stdout.write("\n")
+    return content
+
+def rewrite_rst(app, docname, source):
+    source[0] = replace_dollar(source[0])
+
+def rewrite_autodoc(app, what, name, obj, options, lines):
+    lines[:] = [replace_dollar(L) for L in lines]
+
+def setup(app):
+    app.connect('source-read', rewrite_rst)
+    app.connect('autodoc-process-docstring', rewrite_autodoc)
+
+
+def test_dollar():
+    assert replace_dollar(u"no dollar")==u"no dollar"
+    assert replace_dollar(u"$only$")==u":math:`only`"
+    assert replace_dollar(u"$first$ is good")==u":math:`first` is good"
+    assert replace_dollar(u"so is $last$")==u"so is :math:`last`"
+    assert replace_dollar(u"and $mid$ too")==u"and :math:`mid` too"
+    assert replace_dollar(u"$first$, $mid$, $last$")==u":math:`first`, :math:`mid`, :math:`last`"
+    assert replace_dollar(u"dollar\$ escape")==u"dollar$ escape"
+    assert replace_dollar(u"dollar \$escape\$ too")==u"dollar $escape$ too"
+    assert replace_dollar(u"emb\ $ed$\ ed")==u"emb\ :math:`ed`\ ed"
+    assert replace_dollar(u"$first$a")==u"$first$a"
+    assert replace_dollar(u"a$last$")==u"a$last$"
+    assert replace_dollar(u"a $mid$dle a")==u"a $mid$dle a"
+
+if __name__ == "__main__":
+    test_dollar()
Index: doc/_extensions/numfig.py
===================================================================
--- doc/_extensions/numfig.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/_extensions/numfig.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,111 @@
+from docutils.nodes import figure, caption, Text, reference, raw, SkipNode, Element
+from sphinx.roles import XRefRole
+
+
+# Element classes
+
+class page_ref(reference):
+    pass
+
+class num_ref(reference):
+    pass
+
+
+# Visit/depart functions
+
+def skip_num_ref(self, node):
+    raise SkipNode
+
+def skip_page_ref(self, node):
+    raise SkipNode
+
+def latex_visit_page_ref(self, node):
+    self.body.append("\\pageref{%s:%s}" % (node['refdoc'], node['reftarget']))
+    raise SkipNode
+
+def latex_visit_num_ref(self, node):
+    fields = node['reftarget'].split('#')
+    if len(fields) > 1:
+        label, target = fields
+        ref_link = '%s:%s' % (node['refdoc'], target)
+        latex = "\\hyperref[%s]{%s \\ref*{%s}}" % (ref_link, label, ref_link)
+        self.body.append(latex)
+    else:
+        self.body.append('\\ref{%s:%s}' % (node['refdoc'], fields[0]))
+
+    raise SkipNode
+
+
+def doctree_read(app, doctree):
+    # first generate figure numbers for each figure
+    env = app.builder.env
+    figid_docname_map = getattr(env, 'figid_docname_map', {})
+
+    for figure_info in doctree.traverse(figure):
+        for id in figure_info['ids']:
+            figid_docname_map[id] = env.docname
+
+    env.figid_docname_map = figid_docname_map
+
+
+def doctree_resolved(app, doctree, docname):
+    i = 1
+    figids = {}
+    for figure_info in doctree.traverse(figure):
+        if app.builder.name != 'latex' and app.config.number_figures:
+            for cap in figure_info.traverse(caption):
+                cap[0] = Text("%s %d: %s" % (app.config.figure_caption_prefix, i, cap[0]))
+
+        for id in figure_info['ids']:
+            figids[id] = i
+
+        i += 1
+
+
+    # replace numfig nodes with links
+    if app.builder.name != 'latex':
+        for ref_info in doctree.traverse(num_ref):
+            if '#' in ref_info['reftarget']:
+                label, target = ref_info['reftarget'].split('#')
+                labelfmt = label + " %d"
+            else:
+                labelfmt = '%d'
+                target = ref_info['reftarget']
+
+            if target not in figids:
+                continue
+
+            if app.builder.name == 'html':
+                target_doc = app.builder.env.figid_docname_map[target]
+                link = "%s#%s" % (app.builder.get_relative_uri(docname, target_doc),
+                                  target)
+                html = '<a class="pageref" href="%s">%s</a>' % (link, labelfmt %(figids[target]))
+                ref_info.replace_self(raw(html, html, format='html'))
+            else:
+                ref_info.replace_self(Text(labelfmt % (figids[target])))
+
+
+def clean_env(app):
+    app.builder.env.i=1
+    app.builder.env.figid_docname_map = {}
+
+def setup(app):
+    app.add_config_value('number_figures', True, True)
+    app.add_config_value('figure_caption_prefix', "Figure", True)
+
+    app.add_node(page_ref,
+                 text=(skip_page_ref, None),
+                 html=(skip_page_ref, None),
+                 latex=(latex_visit_page_ref, None))
+
+    app.add_role('page', XRefRole(nodeclass=page_ref))
+
+    app.add_node(num_ref,
+                 latex=(latex_visit_num_ref, None),
+                 html=(skip_num_ref, None))
+
+    app.add_role('num', XRefRole(nodeclass=num_ref))
+
+    app.connect("builder-inited", clean_env)
+    app.connect('doctree-read', doctree_read)
+    app.connect('doctree-resolved', doctree_resolved)
Index: doc/conf.py
===================================================================
--- doc/conf.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/conf.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,245 @@
+# -*- coding: utf-8 -*-
+#
+# Periodic Table documentation build configuration file, created by
+# sphinx-quickstart on Tue Jun  2 11:16:08 2009.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.append(os.path.abspath('_extensions'+(os.path.dirname('../../periodictable'))))
+
+sys.path.insert(0, os.path.abspath('..'))
+sys.path.insert(0, os.path.abspath('_extensions'))
+sys.path.insert(0, os.path.abspath('.')) # needed for extension tests
+print "\n".join(sys.path)
+import sasmodels
+
+
+# -- General configuration -----------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
+              'sphinx.ext.coverage',
+              #'sphinx.ext.pngmath',
+              'sphinx.ext.mathjax',
+              #'only_directives',
+              #'matplotlib.sphinxext.mathmpl',
+              'matplotlib.sphinxext.only_directives',
+              'matplotlib.sphinxext.plot_directive',
+              'dollarmath',
+              'numfig',
+             ]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = 'SAS Models'
+copyright = '2014, sasview team'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = sasmodels.__version__
+# The full version, including alpha/beta/rc tags.
+release = version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of documents that shouldn't be included in the build.
+#unused_docs = []
+
+# List of directories, relative to source directory, that shouldn't be searched
+# for source files.
+exclude_trees = ['_*','build','plots']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  Major themes that come with
+# Sphinx are currently 'default' and 'sphinxdoc'.
+html_theme = 'default'
+html_theme_options = {
+    "rightsidebar":"False",
+    "relbarbgcolor": "Gainsboro",
+    #"codebgcolor": "Beige",
+    "footertextcolor": "orange",
+    "relbartextcolor": "Blue",
+    "sidebarbgcolor": "white",
+    "sidebarlinkcolor": "OrangeRed",
+    "sidebartextcolor": "Navy",
+    "linkcolor": "Blue",
+    "relbarlinkcolor": "Blue"
+    #"headtextcolor": "Teal"
+    #"headbgcolor": "Oldlace",
+}
+
+html_style = 'site.css'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation PaleTurquoise.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+html_title = "Sasmodels"
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+html_short_title = "Home"
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = '_static/periodic_logo.png'
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_use_modindex = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+html_show_sourcelink = False
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = ''
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'sasmodelsdoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+# The paper size ('letter' or 'a4').
+#latex_paper_size = 'letter'
+
+# The font size ('10pt', '11pt' or '12pt').
+#latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'SASModels.tex', 'SAS Models Documentation',
+   'sasview team', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# Additional stuff for the LaTeX preamble.
+#latex_preamble = ''
+LATEX_PREAMBLE=r"""
+\renewcommand{\AA}{\text{\r{A}}} % Allow \AA in math mode
+\usepackage[utf8]{inputenc}      % Allow unicode symbols in text
+\DeclareUnicodeCharacter {00B7} {\ensuremath{\cdot}}   % cdot
+\DeclareUnicodeCharacter {00B0} {\ensuremath{^\circ}}  % degrees
+\DeclareUnicodeCharacter {212B} {\AA}                  % Angstrom
+"""
+latex_elements = {'preamble' : LATEX_PREAMBLE}
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_use_modindex = True
+
+# Which class/__init__ docstring to use: class, init, or both
+autoclass_content = 'both'
+
+# Autodoc member sort order: by class or by type
+autodoc_member_order = 'groupwise'
+
+if os.path.exists('rst_prolog'):
+    with open('rst_prolog') as fid:
+        rst_prolog = fid.read()
Index: doc/genapi.py
===================================================================
--- doc/genapi.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/genapi.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,70 @@
+from __future__ import with_statement
+import os.path
+
+MODULE_TEMPLATE=""".. Autogenerated by genmods.py
+
+******************************************************************************
+%(name)s
+******************************************************************************
+
+:mod:`%(package)s.%(module)s`
+==============================================================================
+
+.. automodule:: %(package)s.%(module)s
+   :members:
+   :undoc-members:
+   :inherited-members:
+   :show-inheritance:
+
+"""
+
+INDEX_TEMPLATE=""".. Autogenerated by genmods.py
+
+.. _api-index:
+
+##############################################################################
+   %(package_name)s
+##############################################################################
+
+.. only:: html
+
+   :Release: |version|
+   :Date: |today|
+
+.. toctree::
+   :titlesonly:
+   :numbered: 1
+   :maxdepth: 2
+
+   %(rsts)s
+"""
+
+
+def genfiles(package, package_name, modules, dir='api'):
+
+    if not os.path.exists(dir):
+        os.makedirs(dir)
+
+    for module,name in modules:
+        with open(os.path.join(dir,module+'.rst'), 'w') as f:
+            f.write(MODULE_TEMPLATE%locals())
+
+    rsts = "\n   ".join(module+'.rst' for module,name in modules)
+    with open(os.path.join(dir,'index.rst'),'w') as f:
+        f.write(INDEX_TEMPLATE%locals())
+
+
+modules=[
+    #('__init__', 'Top level namespace'),
+    ('bumps_model', 'Bumps interface'),
+    ('sasview_model', 'Sasview interface'),
+    ('weights', 'Distribution functions'),
+    ('gen', 'Model generator'),
+    ('convert', 'Model parameter converter'),
+    ('gpu', 'OpenCL model loader'),
+    ('dll', 'Ctypes model loader'),
+    #('transition', 'Model stepper for automatic model selection'),
+]
+package='sasmodels'
+package_name='Reference'
+genfiles(package, package_name, modules)
Index: doc/genmodel.py
===================================================================
--- doc/genmodel.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/genmodel.py	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,16 @@
+import sys
+import os
+sys.path.insert(0,'..')
+
+# Convert ../sasmodels/models.name.py to sasmodels.models.name
+module_name = sys.argv[1][3:-3].replace('/','.').replace('\\','.')
+print module_name
+module = __import__(module_name)
+for part in module_name.split('.')[1:]:
+    module = getattr(module, part)
+print module
+
+# Load the doc string from the module definition file and store it in rst
+from sasmodels import gen
+docstr = gen.doc(module)
+open(sys.argv[2],'w').write(docstr)
Index: doc/guide/index.rst
===================================================================
--- doc/guide/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/guide/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,28 @@
+**********************
+SAS Model Organization
+**********************
+
+Models have certain features in common.
+
+Every model has a *scale* and a *background*.
+
+Talk about orientation, with diagrams for orientation so that we don't need
+a link on every model page?
+
+.. _orientation:
+
+.. figure: img/orientation1.jpg
+
+    Orientation in 3D
+
+.. figure: img/orientation2.jpg
+
+    Orientation cross sections
+
+Talk about polydispersity.
+
+Talk about magnetism, converting the magnetism help file to inline text here,
+with links so that models can point back to it.
+
+Need to talk about structure factors even though we don't have any
+implemented yet.
Index: doc/index.rst
===================================================================
--- doc/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,33 @@
+Introduction
+============
+The sasmodels package provides theory functions for small angle scattering
+calculations.
+
+.. htmlonly::
+   :Release: |version|
+   :Date:    |today|
+
+   Download pdf version `here <SASModels.pdf>`_
+
+.. toctree::
+   :numbered:
+   :maxdepth: 5
+
+   guide/index.rst
+   models/index.rst
+   api/index.rst
+
+Indices and Tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+
+.. htmlonly::
+  * :ref:`search`
+
+
+
+
+  
+
Index: doc/make.bat
===================================================================
--- doc/make.bat	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/make.bat	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,112 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+set SPHINXBUILD=sphinx-build
+set ALLSPHINXOPTS=-d _build/doctrees %SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html      to make standalone HTML files
+	echo.  dirhtml   to make HTML files named index.html in directories
+	echo.  pickle    to make pickle files
+	echo.  json      to make JSON files
+	echo.  htmlhelp  to make HTML files and a HTML help project
+	echo.  qthelp    to make HTML files and a qthelp project
+	echo.  latex     to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  changes   to make an overview over all changed/added/deprecated items
+	echo.  linkcheck to check all external links for integrity
+	echo.  doctest   to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (_build\*) do rmdir /q /s %%i
+	del /q /s _build\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% _build/html
+	echo.
+	echo.Build finished. The HTML pages are in _build/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% _build/dirhtml
+	echo.
+	echo.Build finished. The HTML pages are in _build/dirhtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% _build/pickle
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% _build/json
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% _build/htmlhelp
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in _build/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% _build/qthelp
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in _build/qthelp, like this:
+	echo.^> qcollectiongenerator _build\qthelp\Periodic Table.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile _build\qthelp\Periodic Table.ghc
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% _build/latex
+	echo.
+	echo.Build finished; the LaTeX files are in _build/latex.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% _build/changes
+	echo.
+	echo.The overview file is in _build/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% _build/linkcheck
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in _build/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% _build/doctest
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in _build/doctest/output.txt.
+	goto end
+)
+
+:end
Index: doc/models/cylinders.rst
===================================================================
--- doc/models/cylinders.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/models/cylinders.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,11 @@
+.. _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)
+++ doc/models/ellipsoids.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,10 @@
+.. _models-ellipsoids:
+
+***************
+Ellipsoid-based
+***************
+
+.. toctree::
+
+   ../model/ellipsoid.rst
+   ../model/triaxial_ellipsoid.rst
Index: doc/models/index.rst
===================================================================
--- doc/models/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/models/index.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,11 @@
+*******************
+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)
+++ doc/models/intro.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -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/models/lamellae.rst
===================================================================
--- doc/models/lamellae.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/models/lamellae.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,9 @@
+.. _models-lamellae:
+
+**************
+Lamellae-based
+**************
+
+.. toctree::
+
+   ../model/lamellar.rst
Index: doc/models/models.rst
===================================================================
--- doc/models/models.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/models/models.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,14 @@
+.. _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)
+++ doc/models/refs.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -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.**
Index: doc/models/shapes.rst
===================================================================
--- doc/models/shapes.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/models/shapes.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,15 @@
+.. _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)
+++ doc/models/spheres.rst	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,10 @@
+.. _models-spheres:
+
+***************
+Sphere-based
+***************
+
+.. toctree::
+
+   ../model/sphere.rst
+
Index: doc/rst_prolog
===================================================================
--- doc/rst_prolog	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
+++ doc/rst_prolog	(revision 19dcb93366741a275baa8ad855ce8a310dca78f8)
@@ -0,0 +1,61 @@
+.. Set up some substitutions to make life easier...
+.. Remove |biggamma|, etc. when they are no longer needed.
+
+.. |alpha| unicode:: U+03B1
+.. |beta| unicode:: U+03B2
+.. |gamma| unicode:: U+03B3
+.. |delta| unicode:: U+03B4
+.. |epsilon| unicode:: U+03B5
+.. |zeta| unicode:: U+03B6
+.. |eta| unicode:: U+03B7
+.. |theta| unicode:: U+03B8
+.. |iota| unicode:: U+03B9
+.. |kappa| unicode:: U+03BA
+.. |lambda| unicode:: U+03BB
+.. |mu| unicode:: U+03BC
+.. |nu| unicode:: U+03BD
+.. |xi| unicode:: U+03BE
+.. |omicron| unicode:: U+03BF
+.. |pi| unicode:: U+03C0
+.. |rho| unicode:: U+03C1
+.. |sigma| unicode:: U+03C3
+.. |tau| unicode:: U+03C4
+.. |upsilon| unicode:: U+03C5
+.. |phi| unicode:: U+03C6
+.. |chi| unicode:: U+03C7
+.. |psi| unicode:: U+03C8
+.. |omega| unicode:: U+03C9
+
+
+.. |biggamma| unicode:: U+0393
+.. |bigdelta| unicode:: U+0394
+.. |bigzeta| unicode:: U+039E
+.. |bigpsi| unicode:: U+03A8
+.. |Gamma| unicode:: U+0393
+.. |Delta| unicode:: U+0394
+.. |Zeta| unicode:: U+039E
+.. |Psi| unicode:: U+03A8
+
+.. |drho| replace:: |Delta|\ |rho|
+.. |Ang| unicode:: U+212B
+.. |Ang^-1| replace:: |Ang|\ :sup:`-1`
+.. |Ang^2| replace:: |Ang|\ :sup:`2`
+.. |Ang^-2| replace:: |Ang|\ :sup:`-2`
+.. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`
+.. |Ang^3| replace:: |Ang|\ :sup:`3`
+.. |Ang^-3| replace:: |Ang|\ :sup:`-3`
+.. |Ang^-4| replace:: |Ang|\ :sup:`-4`
+.. |cm^-1| replace:: cm\ :sup:`-1`
+.. |cm^2| replace:: cm\ :sup:`2`
+.. |cm^-2| replace:: cm\ :sup:`-2`
+.. |cm^3| replace:: cm\ :sup:`3`
+.. |cm^-3| replace:: cm\ :sup:`-3`
+.. |sr^-1| replace:: sr\ :sup:`-1`
+.. |P0| replace:: P\ :sub:`0`\
+.. |A2| replace:: A\ :sub:`2`\
+
+
+.. |cdot| unicode:: U+00B7
+.. |deg| unicode:: U+00B0
+.. |g/cm^3| replace:: g\ |cdot|\ cm\ :sup:`-3`
+.. |fm^2| replace:: fm\ :sup:`2`
