latex_plot_format error with \mathdefault{}
The new @latex_plot_format
decorator, coming from the core.utils file, is very handy but it sometimes bugged some of my plots with the following error:
[...]
File "/anaconda3/envs/hmc/lib/python3.7/site-packages/matplotlib/texmanager.py", line 307, in _run_checked_subprocess
exc=exc.output.decode('utf-8')))
RuntimeError: latex was not able to process the following string:
b'$\\\\times\\\\mathdefault{10^{5}}\\\\mathdefault{}$'
[...]
! Undefined control sequence.
l.14 ...}{15.000000}{\sffamily $\times\mathdefault
{10^{5}}\mathdefault{}$}
[...]
This bit of latex string would appear at the top of an x/y-axis as shown in the image I attached.
I am not entirely sure whether this error is specific to my installation of python/latex but I don't think so. However I found a way around this thanks to this stackoverflow post. As explained there, "\mathdefault
is a command defined in python, and not as a base command of Latex.". Hence the solution is to define this command in matplotlib's rcParams with:
rcParams['text.latex.preamble'] = r'\newcommand{\mathdefault}[1][]{}'
So I would add this line to the latex_plot_format()
function.