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$')
  • 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

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

| improve this answer | |
  • Dear Heiko, thank you very much! It works now! – Zidan Feb 25 '17 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.