Sphinx:如何添加角色和指令别名

Sphinx: how to add a role and directive alias

我经常使用 :math: 角色和 .. math:: 指令,使用频率很高,所以我想为它们创建一个更短的别名 m。我怎样才能在 Sphinx 中实现它?

将以下代码片段添加到 conf.py。它定义了一个 m 指令和一个 m 角色,可以用作 math:

的别名
from sphinx.ext.mathbase import MathDirective, math_role

def setup(app):
    app.add_directive('m', MathDirective)
    app.add_role('m', math_role)

另请参阅: