1

I followed this answer to Sans-serif math with latex in matplotlib to get my matplotlib to use Computer Modern Sans. That works splendidly, except I can't get upright mu's to work. There's a ton of questions that go into that, but somehow I can't make it consistent with the above code.

What I'm using now is

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True 
plt.rcParams['text.latex.preamble'] = [r'\usepackage[cm]{sfmath}']
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = 'cm'

But when I try to do something like

plt.figure()
plt.text(0,0.5,r'$50 \mathrm{\mu m}$', size=16, c='k')

I just end up with a slanted mu. If instead I use \textmu, the character completely disappears and I get 50 m.

I tried doing something like this and then using \micro, but it just results in errors saying that that's an unknown symbol. Even though my MikTeX tells me siunitx is installed.

I'm sure this is just a silly mistake on my end, and I apologise if that is the case, but for the past 4 hours I have not been able to make any progress so I figured I would ask here.

user129412
  • 765
  • 1
  • 6
  • 19

1 Answers1

1

With the upgreek package, you could use \upmu to get an upright mu.

Unrelated to the problem, but I recommend the siunitx package to get propper spacing between numbers and units

\documentclass{article}

\usepackage[cm]{sfmath}

\usepackage{upgreek}
\usepackage{siunitx}

\begin{document}

\SI{50}{\upmu m}

\end{document}

enter image description here

  • It seems that my problem was then somehow related to trying to get that \micro referenced in the second link I posted working. Upmu seems very well behaved. Thanks a lot! Also as a note for future readers, the upgreek package is part of a package called was. – user129412 Aug 06 '19 at 15:39