在 matplotlib 标签中使用 mathfrak 返回未定义的控制序列

问题描述

当我在 matplotlibrc 中设置 text.usetex : True 然后尝试添加带有 \mathfrak{} 的文本或标签时,我收到一个错误(未定义的控制序列)

RuntimeError: latex was not able to process the following string:
b'$\\\\mathfrak{F}$'
...
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<recently read> \mathfrak 
                          
l.19 {\rmfamily $\mathfrak
                          {F}$}
No pages of output.

其他字体样式(例如 \mathcal{})可以正常工作。

我尝试的另一件事是设置 text.usetex : False,然后指定我想使用 Computer Modern 作为认字体,但似乎 matplotlib 无法找到 serifsans-serif 和回到 DejaVu Sans:

findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.

尽管在最后一种情况下,我可以毫无问题地使用 \mathfrak{}

任何想法如何解决这个问题?谢谢。

解决方法

@samcarter_is_at_topanswers.xyz 给出了解决这个问题的答案。

text.latex.preamble : \usepackage{amssymb} \usepackage{amsmath} 添加到您的 .matplotlibrc 中即可。