Skip to content

tillahoffmann/sphinx-stan

Repository files navigation

sphinx-stan

image

image

image

sphinx-stan is a Sphinx extension for documenting Stan code. It supports both standard Sphinx fields as well as the doxygen syntax recommended by the Stan user guide.

Warning

sphinx-stan is an early release; use it at your own risk. Bugs and feature requests can be filed on GitHub.

Explicit documentation of functions

Functions can be documented explicitly using the :stan:function:: ... directive. For example, the following statements generate the documentation shown below.

.. stan:function:: real log(real x, real y)

    Evaluate the logarithm of :math:`x` with base :math:`y`.

    :param x: Value to take the logarithm of.
    :param y: Base of the logarithm.
    :return: :math:`\log_y\left(x\right)`.
    :throws: If :math:`x` or :math:`y` are negative.

Stan supports overloading, and so does the documentation. For example, the following function evaluates the natural logarithm, implicitly setting y = e.

Using the :stan:func:\`...\` role, we can reference specific overloaded implementations (such as :stanlog(real, real) or :stanlog(real)) by specifying the argument types.

Note

sphinx-stan will try to resolve unqualified function references (such as :stan:func:\`log\`). A warning will be issued if the unqualified reference is ambiguous and the reference may point to any of the overloaded functions.

Automatic documentation

Functions can also be documented by loading them from a *.stan file. For example, the following statements document two functions stored in example.stan.

.. stan:autodoc:: example.stan
    :members: mat_pow; log1p_series(real, int)

Documentation for each function must preceed it and be wrapped in /** ... */ comments. The content of the example file is:

example.stan

Syntax

.. stan:function:: <signature of the function>

    <general documentation that supports any reST syntax>

    :param <parameter name>: <parameter description>
    :param <parameter name>: <parameter description>
    :return: <return value description>
    :throws:

      - <first error condition>
      - <second error condition>

Alternatively, functions may also be documented using the doxygen syntax (see the Stan user guide for details).

.. stan:autodoc:: <path to stan file>
    :members: <semi-colon separated list of functions to document>

If :members: is omitted, all functions in the file are documented in the order they appear. Function names are matched using the same logic as for the :stan:func:\`...\` cross-referencing logic. If the file contains overloaded functions and only an unqualified name is provided (i.e., without argument types), all overloaded functions with the given identifier will be documented in the order they appear.

Installation

The extension can be installed in two steps:

  1. Run pip install sphinx-stan from the command line to install the package.
  2. Add "sphinxcontrib.stan" to the list of extensions in your Sphinx configuration, typically conf.py. You can view the configuration used to build this documentation here.

About

Sphinx domain for Stan, the probabilistic programming language

Resources

License

Stars

Watchers

Forks

Packages

No packages published