pythonpython-3.x

How to display a mathematical equation in a pretty way in Python 3


I am trying to display a vector equation in a pretty way in a Jupyter Notebook. I am trying to achieve something like this:

Vector equation

Using the IPython.display module, I'm able to print the matrix in a pretty way. The problem is displaying "(2 * the matrix) - (1 * another submatrix) ..." inline.

Is this possible?


Solution

  • from IPython.display import display, Math, Latex
    display(Math(r'2 \cdot  \begin{bmatrix} 1 \\ -2 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 2 \\ -3 \\ \end{bmatrix} +1 \cdot \begin{bmatrix} -3 \\ 1 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}= \begin{bmatrix} -4 \\ 1 \\ \end{bmatrix}'))
    

    enter image description here

    for thicker .'s you can use \bullet instead of \cdot