mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-09 10:40:34 -05:00
New Post
This commit is contained in:
parent
a19d1ef484
commit
0ed8813dd7
1 changed files with 33 additions and 0 deletions
33
content/blog/sphinxmathjax.md
Normal file
33
content/blog/sphinxmathjax.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
title: "Sphinx & MathJax"
|
||||||
|
date: 2020-03-20T18:59:40-04:00
|
||||||
|
draft: false
|
||||||
|
tags: ["Documentation", "python", "LaTex"]
|
||||||
|
---
|
||||||
|
|
||||||
|
To include mathematical notation in Python docs generated by Sphinx, it should look like the following:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Line:
|
||||||
|
r"""
|
||||||
|
Holds the equation for a line.
|
||||||
|
|
||||||
|
:math:`y = mx + \frac{b}{1}`
|
||||||
|
|
||||||
|
In this equation, :math:`m` is the slope and :math:`b` is the y-intercept.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
The content after `:math:` and inside the backticks is treated as inline math. The `r` in front of the triple quotes is used to make it a raw string and so that LaTex commands such as `\frac{}{}` operate as intended. There also cannot be a space between `:math:` and the backtick.
|
||||||
|
|
||||||
|
The Sphinx configuration needs to have the `mathjax` extension loaded as well.
|
||||||
|
|
||||||
|
```python
|
||||||
|
extensions = [
|
||||||
|
# ....
|
||||||
|
"sphinx.ext.mathjax",
|
||||||
|
# ....
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue