Skip to content

Latest commit

 

History

History
93 lines (59 loc) · 4.06 KB

README.rst

File metadata and controls

93 lines (59 loc) · 4.06 KB

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.

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.

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.