| 1 |
from docutils import nodes |
| 2 |
from docutils.parsers.rst import Directive |
| 3 |
|
| 4 |
extensions = ['sphinx.ext.mathjax'] |
| 5 |
|
| 6 |
|
| 7 |
def my_math_role(role, rawtext, text, lineno, inliner, options={}, content=[]): # NoQA: B006 |
| 8 |
text = 'E = mc^2' |
| 9 |
return [nodes.math(text, text)], [] |
| 10 |
|
| 11 |
|
| 12 |
class MyMathDirective(Directive): |
| 13 |
def run(self): |
| 14 |
text = 'E = mc^2' |
| 15 |
return [nodes.math_block(text, text)] |
| 16 |
|
| 17 |
|
| 18 |
def setup(app): |
| 19 |
app.add_role('my_math', my_math_role) |
| 20 |
app.add_directive('my-math', MyMathDirective) |