xuhdev
xuhdev

Reputation: 9333

Sphinx: how to add a role and directive alias

I frequently use the :math: role and .. math:: directive, which is so frequent that I want to make a shorter alias m for them. How can I achieve it in Sphinx?

Upvotes: 3

Views: 778

Answers (1)

mzjn
mzjn

Reputation: 50957

Add the following code snippet to conf.py. It defines a m directive and a m role that can be used as aliases of math:

from sphinx.ext.mathbase import MathDirective, math_role

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

See also:

Upvotes: 4

Related Questions