在 jupyter 中写 \alpha 和 \beta 的问题

Problem in writing \alpha and \beta in jupyter

我正在 jupyter 中使用 Getdist 绘制曲线。对于标记参数我有问题。 我写 \zeta\chi\gamma\Omega\omega 我没有问题,它们的符号形状毫无问题地出现,但是因为我想写 \beta\alpha 我得到了一些错误

这是太长错误的一部分

ValueError: 
$lpha$
^
Expected end of text (at char 0), (line:1, col:1)

这是相关代码的一部分:

g.triangle_plot([samples0],['H_0','\Omega_D','b','aa','\alpha','M','t']

这个问题实在是看不懂,一头雾水

这是因为 '\a' 是 ascii 字符 7 ascii table 的字符串文字,就像 '\t' 是制表符和 '\n' 是换行符一样。

我们可以使用内置函数 ord() 进行检查,其中 returns 所提供字符的相应 ASCII table 索引 - doc

>>> ord('\a')
7
>>> ord('\n')
10
>>> ord('\t')
9

另一方面,'\o'不对应任何字符。

>>> ord('\o')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found

要解决这个问题,只需在

这样的字符串之前添加 r(如 raw string

my_string_variable = r'alpha\omega'