To first answer your question you need to understand the difference between a font-family and a actual font: A font family is a collection of related fonts, like sans-serif, and a font is a specific member of that family, such as Helvetica, Arial, Calibri and the font you are trying to use, Algerian. The font family is the overall design, while the font is the specific variation in weight, style, and size within that design.
Furthermore I spotted this errors in your code:
as said you shouldn't change the parameter 'font-family' because the default, sans-serif, aldo includes Algerian.
as of today by matplotlib docs the keyword argument to change the font in math formulas from the default ('dejavusans') is math_fontfamily not fontfamily like you use
With this corrections I was able to correct the code to get what I hope is the inted output (didn't understand perfectly the LaTeX issue):
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Algerian']
plt.rcParams['font.weight'] = 'bold'
plt.rcParams['font.size'] = 10
plt.figure()
plt.text(0.1, 0.5, r"$a*ln(x)*x^2+2$", math_fontfamily='custom')
plt.show()
I found that it needs to be told to use a custom family font to enable a esternal font to be used, the other accepted values are:
'dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'
this gives in output:enter image description here
which I understand is the one you need.
Some notes:
make sure to have installed in your system the Algerian font (in Windows 11 is preinstalled)
you can check the font asigned to a specific font family with
print(plt.rcParams["font.sans-serif"][0])
which should print Algerian in this case.
To further understand how to customise matplotlib refer to the text, labe and annotation docs.