This guide will briefly demonstrate how to use Latex in the Jupyter Notebook.
What is MathJax?
MathJax is a JavaScript cross-browser library that displays mathematical or scientific notations in web browsers using Latex and MathML markup. You do not need to install or download extra plugins so that it helps you to write web documents and include mathematics using JavaScript.
Before preparing the document in the Latex syntax in the Jupyter notebook, make sure that MathJax should be included in your python environment. You can include the MathJax in your python environment by using the pip or npm package manager as follows:
Below, some Latex notations and their purpose are demonstrated that we will implement in Jupyter Notebook for writing mathematical equations:
Latex notations for writing Mathematical Equations
First, select the markdown cells in the jupyter notebook. Now, use dollar symbols $$, to start and end the mathematics mode in the Jupyter notebook.
Add basic Math equations
The following notations help you to write basic mathematical equations in Latex jupyter notebook:
- In math mode, use \, symbol to add a little spacing.
- For adding a new line, use \\
- For displaying fraction values, use \frac{value 1}{value 2}
- For superscripts or power, use ^{}
- For adding subscripts or indices, use _{}
- For taking square root of a value, use \sqrt{n}{value}
By using the above Latex notations, we have written the following mathematical equations:
\frac{a+b}{X+Y} , x^4, e^{i\pi} , X_i , Y_{ij}\\ \sqrt[4]{5}
$$
Output
Add Roman Letters
To add roman letters in Jupyter notebook, use the following symbols:
\sin(-\alpha)=-\sin(\alpha)\\
\arccos(x)=\arcsin(u)\\
\log_n(n)=1\\
\tan(x) = \frac{\sin(x)}{\cos(x)}
$$
Output
Add Greek Letters
To add greek letters in an equation, use \ and type the name of the Greek letter. Some greek letters are available in both capital and lowercase. To include the capital greek letter, type the first letter after \ symbol in uppercase as follows:
\sigma, \Sigma \\ |
\delta, \Delta \\ |
\omega, \Omega \\ |
\gamma, \Gamma \\ |
\Lamda, \Lambda \\ |
Output
See the following examples that will elaborate how to write Greek letters in Jupyter notebook using Latex:
\alpha = \frac{2\pi}{3}\, rad , \pi = 3.14
$$
Output
4\omega = 3\pi f ,
f = \frac{2c}{\lambda} ,
\Delta_\pi=\theta^3+\lambda ,
\Delta = \frac{1}{\lambda^3}
$$
Output
Add Sets and Logics
To add sets and logical symbols in jupyter notebook, use the following notations:
Output
Type the ‘\’ and then write the name of the notation as follows:
Add Derivatives and Integrals
To add integrals and derivatives using Latex in the jupyter notebook, use the following symbols:
f^{(k)}(x) \\
\frac{\partial f}{\partial x} \\
\frac{\partial^{k} f}{\partial x^k} $$
$$\int_{a}^b f(x)dx \\
\int_{a}^b\int_{c}^d f(x,y)\,dxdy \\
\iiint \\
\oint$$
Add Curly Braces
We can also add vertical and horizontal curly braces using Latex in the jupyter notebook. To start the left curly brace, use the following attribute:
To close the vertical curl brace use
$$
sign(y) = \left\{
\begin{array}\\
2 & \mbox{if } \ y \in \mathbf{Z}^* \\
0 & \mbox{if } \ y = 0 \\
-2 & \mbox{else.}
\end{array}
\right.
$$
\\
$$
\left.
\begin{array} \\
\beta^2 = \sqrt4 \\
\beta \geq 0
\end{array}
\right \} \beta = 5
$$
Output
For horizontal brace, use the following attributes:
\underbrace{\ln \left( \frac{3}{4} \right)}_{\simeq -0.1456}
< \overbrace{\exp (3)}^{\simeq 6.8390}
$$
Output
Add Matrix
We can add different types of matrices using Latex in the jupyter notebook.
For adding plain matrices:
5 & 4 & 3\\
x & y & z
\end{matrix}
For round brackets:
5 & 4 & 3\\
x & y & z
\end{pmatrix}
For pipes:
5 & 4 & 3\\
x & y & z
\end{vmatrix}
For curly brackets:
1 & 2 & 3\\
x & y & z
\end{Bmatrix}
Output
Add Function Limits
To apply a limit function, use the ‘\limit’ inside the dollar symbol. The following notations mostly used for writing function Limits:
$$\max_{y \in [a,b]}f(y)$$
$$\min_{y \in [\alpha,\beta]}f(y)$$
Output
Add Sum and Product
To add sum and product functions using Latex in jupyter notebook, use the following notations:
For Sum rule:
For adding Product rule
Output
Conclusion
We have explained how to use Latex in a Jupyter notebook. We have seen how different notations help us write the mathematical equations in a Jupyter notebook. We explored almost all attributes that are used in Latex for writing scientific and mathematical equations. Always select the markdown cells option to write all Latex notations in the Jupyter notebook.