I would like to preserve latex annotations format in .svg in a matplotlib plot.
I have the following example:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'
plt.rc('text', usetex=True)
my_str = r"$\begin{bmatrix} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \\ \end{bmatrix}$"
plt.plot(np.arange(10), np.arange(10))
plt.text(0.5,0.5, s=my_str)
which plots:
When I save the image as .svg the matrix gets "squished":
How can I fix that? If I save to .pdf, png I have no problem with the annotation.