Skip to main content

Sphinx "matlabdomain" extension

Project description

https://travis-ci.org/sphinx-contrib/matlabdomain.svg?branch=master

sphinxcontrib-matlabdomain – Sphinx domain for auto-documenting MATLAB

This Sphinx contrib extension provides a Sphinx domain for auto-documenting MATLAB source files, in similar manner as sphinx.ext.autodoc. It works really well with sphinx.ext.napoleon.

Recent Changes.

Usage

The Python package must be installed with:

pip install -U sphinxcontrib-matlabdomain

In general, the usage is the same as for documenting Python code.

Configuration

In your Sphinx conf.py file add sphinxcontrib.matlab to the list of extensions.

extensions = ['sphinxcontrib.matlab', 'sphinx.ext.autodoc']

Additional Configuration

matlab_src_dir

In order for the Sphinx MATLAB domain to auto-document MATLAB source code, set the config value of matlab_src_dir to the absolute path. Currently only one MATLAB path can be specified, but all subfolders in that tree will be searched.

matlab_src_encoding

The encoding of the MATLAB files. By default, the files will be read as utf-8 and parsing errors will be replaced using ? chars.

matlab_keep_package_prefix

Determines if the MATLAB package prefix + is displayed in the generated documentation. Default is true. When false, packages are still referred to in ReST using +pakage.+subpkg.func but the output will be pakage.other.func().

For convenience the primary domain can be set to mat.

Roles and Directives

Please see Sphinx Domains and sphinx.ext.autodoc for documentation on the use of roles and directives. MATLAB code can be documented using the following roles and directives:

Directive

MATLAB object

.. module:: foldername

folders, packages and namespaces

.. currentmodule:: foldername

  • set folder but do not link

.. automodule:: foldername

  • auto-document

:mod:`foldername`

  • reference

.. function:: funcname

function definition and signature

.. autofunction:: funcname()

  • auto-document

:func:`funcname`

  • reference

.. script:: scriptname

script definition

.. autoscript:: scriptname

  • auto-document

:scpt:`scriptname`

  • reference

.. class:: classname()

class definition and optional signature

.. autoclass:: classname

  • auto-document

:class:`classname`

  • reference

.. method:: methname()

method definition and signature

.. automethod:: methname

  • auto-document

:meth:`methname`

  • reference

.. staticmethod:: statmethname()

static method definition and signature

.. automethod:: statmethname

  • auto-document

:meth:`methname`

  • reference

.. attribute:: attrname

property definition

.. autoattribute:: attrname

  • auto-document

:attr:`attrname`

  • reference

.. application:: appname

application definition

.. autoapplication:: appname

  • auto-document

:app:`appname`

  • reference

Several options are available for auto-directives.

  • :members: auto-document public members

  • :show-inheritance: list bases

  • :undoc-members: document members without docstrings

  • :annotation: specifies attribute annotation instead of default

There are also several config values that can be set in conf.py that will affect auto-docementation.

  • autoclass_content can be set to class, both or init, which determines which docstring is used for classes. The constructor docstring is used when this is set to init.

  • autodoc_member_order can be set to alphabetical, groupwise or bysource.

  • autodoc_default_flags can be set to a list of options to apply. Use the no-flag directive option to disable this config value once.

Example: given the following MATLAB source in folder test_data:

classdef MyHandleClass < handle & my.super.Class
    % a handle class
    %
    % :param x: a variable

    %% some comments
    properties
        x % a property
    end
    methods
        function h = MyHandleClass(x)
            h.x = x
        end
        function x = get.x(obj)
        % how is this displayed?
            x = obj.x
        end
    end
    methods (Static)
        function w = my_static_function(z)
        % A static function in :class:`MyHandleClass`.
        %
        % :param z: input z
        % :returns: w

            w = z
        end
    end
end

Use the following to document:

Test Data
=========
This is the test data module.

.. automodule:: test_data

:mod:`test_data` is a really cool module.

My Handle Class
---------------
This is the handle class definition.

.. autoclass:: MyHandleClass
    :show-inheritance:
    :members:

Module Index

Since version 0.10.0 the MATLAB Module Index should be linked to with:

`MATLAB Module Index <mat-modindex.html>`_

Older versions, used the Python Module Index, which was linked to with:

:ref:`modindex`

Documenting Python and MATLAB sources together

Since version 0.10.0 MATLAB and Python sources can be (auto-)documented in the same Sphinx documentation. For this to work, do not set the primary domain.

Instead use the mat: prefix before the desired directives:

.. automodule:: func
.. autofunction:: func.main

.. mat:automodule:: matsrc
.. mat:autofunction:: matsrc.func

Online Demo

The test docs in the repository are online here: http://bwanamarko.alwaysdata.net/matlabdomain/

Users

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib-matlabdomain-0.11.0.tar.gz (76.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sphinxcontrib_matlabdomain-0.11.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

sphinxcontrib_matlabdomain-0.11.0-py2-none-any.whl (39.2 kB view details)

Uploaded Python 2

File details

Details for the file sphinxcontrib-matlabdomain-0.11.0.tar.gz.

File metadata

  • Download URL: sphinxcontrib-matlabdomain-0.11.0.tar.gz
  • Upload date:
  • Size: 76.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15

File hashes

Hashes for sphinxcontrib-matlabdomain-0.11.0.tar.gz
Algorithm Hash digest
SHA256 b95531d177ead2a24f730546f97a0adeb9cb949de1e795f3a2bec9370e2ed7c6
MD5 c714b8151b5ea16c9ddf3681ce76a012
BLAKE2b-256 4b92b1ffa7d79f9fed516c629b211f7e4d89508c7ed08e405b4f521d2e8e2a7d

See more details on using hashes here.

File details

Details for the file sphinxcontrib_matlabdomain-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: sphinxcontrib_matlabdomain-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for sphinxcontrib_matlabdomain-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03b222406dbc1eee3c638524dec97e3a36e1d47fda2045e016379292246d7c4d
MD5 cff3becb7ad9d3fd6b807352e5643702
BLAKE2b-256 dff1e12367e8bb7a7429027f025bac4e65affb6c3c9158cbf6ed58bced89a39c

See more details on using hashes here.

File details

Details for the file sphinxcontrib_matlabdomain-0.11.0-py2-none-any.whl.

File metadata

  • Download URL: sphinxcontrib_matlabdomain-0.11.0-py2-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15

File hashes

Hashes for sphinxcontrib_matlabdomain-0.11.0-py2-none-any.whl
Algorithm Hash digest
SHA256 c6cf713a7f380dea63d54c8d505a0cb4f8c876346d1ac182dbf364c45573e737
MD5 61216385421eb747b58c0398e2f5c9a5
BLAKE2b-256 d216fd4d7d00821e3d467ea27e87c02e31effdd6cf66b9071d3b79f76a80fa8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page