Sphinx "matlabdomain" extension
Project description
Github Actions |
|
sphinxcontrib-matlabdomain – Sphinx domain for auto-documenting MATLAB
This extension provides a Sphinx domain for automatically generating doumentation from MATLAB source files. It is modelled after the Python autodoc.
The extension allows you to have your documentation and source files together and use the powerful Sphinx documentation tool. All your MATLAB file help text can be automatically included in the your documentation and output as for instance HTML.
The extension works really well with sphinx.ext.napoleon.
Recent Changes.
Usage
The Python package must be installed with:
pip install sphinxcontrib-matlabdomain
In general, the usage is the same as for documenting Python code. The package is tested with Python >= 3.8 and Sphinx >= 4.5.0.
For a Python 2 compatible version the package must be installed with:
pip install sphinxcontrib-matlabdomain==0.11.8
Configuration
In your Sphinx conf.py file add sphinxcontrib.matlab to the list of extensions.
extensions = ['sphinxcontrib.matlab', 'sphinx.ext.autodoc']
For convenience the primary domain can be set to mat with.:
primary_domain = "mat"
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 an absolute path or a path relative to the source directory. Currently only one MATLAB path can be specified, but that folder and all the subfolders in that tree will be searched.
- matlab_short_links
Shorten all class, package and functions to the minimum length. This assumes that everything is in the path as we would expect it in MATLAB. This will resemble a more MATLAB-like presentation. If it is True is forces matlab_keep_package_prefix = False. Further, it allows for much shorter and cleaner references. Example, given a path to classes like target.subfolder.ClassFoo and target.@ClassFolder.Classfolder
With False:
:class:`target.subfolder.ClassFoo` :class:`target.@ClassFolder.Classfolder`
With True:
:class:`ClassFoo` :class:`ClassFolder`
Default is False. Added in Version 0.19.0.
- matlab_auto_link
Automatically convert the names of known entities (e.g. classes, functions, properties, methods) to links. Valid values are "basic" and "all".
"basic" - Auto-links (1) known classes, functions, properties, or methods that appear in docstring lines that begin with “See also” and any subsequent lines before the next blank line (unknown names are wrapped in double-backquotes), and (2) property and method names that appear in lists under “<MyClass> Properties:” and “<MyClass> Methods:” headings in class docstrings.
"all" - Auto-links everything included with "basic", plus all known classes and functions everywhere else they appear in any docstring, any fully qualified (including class name) property or method names, any names ending with “()” within class, property, or method docstrings that match a method of the corresponding class, and any property or method names in their own docstrings. Note that a non-breaking space before or after a name will prevent auto-linking.
Default is None. Added in Version 0.20.0.
- matlab_show_property_default_value
Show property default values in the rendered document. Default is False, which is what MathWorks does in their documentation. Added in Version 0.16.0.
- matlab_show_property_specs
Show property specifiers, the size, class and validators, in the rendered document. Default is False, which is what MathWorks does in their documentation. Added in Version 0.22.0.
- matlab_class_signature
Shows the constructor argument list in the class signature if True. Default is False. Added in Version 0.20.0.
- matlab_keep_package_prefix
Determines if the MATLAB package prefix + is displayed in the generated documentation. Default is False. When False, packages are still referred to in ReST using +pakage.+subpkg.func but the output will be pakage.subpkg.func(). Forced to False if matlab_short_links is True. Added in Version 0.11.0.
- 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. Added in Version 0.9.0.
If you want the closest to MATLAB documentation style, use matlab_short_links = True and matlab_auto_link = "basic" or matlab_auto_link = "all" in your conf.py file.
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 |
|
.. automodule:: foldername |
|
:mod:`foldername` |
|
.. function:: funcname |
function definition and signature |
.. autofunction:: funcname() |
|
:func:`funcname` |
|
.. script:: scriptname |
script definition |
.. autoscript:: scriptname |
|
:scpt:`scriptname` |
|
.. class:: classname() |
class definition and optional signature |
.. autoclass:: classname |
|
:class:`classname` |
|
.. method:: methname() |
method definition and signature |
.. automethod:: methname |
|
:meth:`methname` |
|
.. staticmethod:: statmethname() |
static method definition and signature |
.. automethod:: statmethname |
|
:meth:`methname` |
|
.. attribute:: attrname |
property definition |
.. autoattribute:: attrname |
|
:attr:`attrname` |
|
.. application:: appname |
application definition |
.. autoapplication:: appname |
|
:app:`appname` |
|
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 % Multiple lines before a % property can also be used y 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:
In version 0.19.0 the .. automodule:: directive can also take a . as argument, which allows you to document classes or functions in the root of matlab_src_dir.
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
Citation
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
Built Distribution
File details
Details for the file sphinxcontrib-matlabdomain-0.22.1.tar.gz
.
File metadata
- Download URL: sphinxcontrib-matlabdomain-0.22.1.tar.gz
- Upload date:
- Size: 219.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f70d4160b6f7d3dba7d77a614416a4e3a421f864ed5258bbf750796ee1804ac1 |
|
MD5 | 34699cb10ced9db485ecfccb3823559e |
|
BLAKE2b-256 | a8da5417e22c1da79e7187d7976673b408f1720b5a54c2b8d0496edf408889a1 |
File details
Details for the file sphinxcontrib_matlabdomain-0.22.1-py3-none-any.whl
.
File metadata
- Download URL: sphinxcontrib_matlabdomain-0.22.1-py3-none-any.whl
- Upload date:
- Size: 48.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2814c4447e2a58c3db44b169999f625544a92ac9c7f43ca5ed285f081fbad5de |
|
MD5 | 51f26a21178ff7277e0e77ac54235263 |
|
BLAKE2b-256 | ac6c5979a354e8aad6a27855ee8a6b9932d77a19d7f55c533f490ab009f1ac7e |