1

I want to display the D-stroke symbol (\DJ) using the following code, but I failed. Could anyone tell me how to make it correct?

As shown in the figure, the symbol $\mu$ works well but the $\DJ$ symbol doesn't appear.

Any advice and suggestions will be greatly appreciated! enter image description here

import matplotlib as mpl
mpl.use("pgf")
pgf_with_custom_preamble = {
    "text.usetex": True,    # use inline math for ticks
    "pgf.rcfonts": False,   # don't setup fonts from rc parameters
    "pgf.preamble": [
        '\\usepackage[utf8]{inputenc}'
        '\\usepackage[T1]{fontenc}'
        '\\usepackage{tgtermes}'
     ]
}
mpl.rcParams.update(pgf_with_custom_preamble)
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [10, 20, 30, 40, 50]
plt.plot(x,y)
plt.xlabel('$\mu$')
plt.title('$\DJ$')
Heiko Oberdiek
  • 271,626
Zidan
  • 11
  • Welcome to TeX.SX! I think this is marginally on topic, because it's not specified how the translation to TeX is done. – egreg Feb 25 '17 at 18:13

1 Answers1

1

The symbol \DJ belongs to text mode and creates a warning in math mode:

LaTeX Warning: Command \DJ invalid in math mode ...

Solution is using text mode for the symbol (\mbox{\DJ} inside math or \text{\DJ} if package amstext or amsmath is loaded):

...
plt.xlabel(r'$\mu$')
plt.title(r'\DJ')
plt.savefig('test.pdf')

Result

Heiko Oberdiek
  • 271,626