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

标签 python jupyter-notebook latex tex

我正在使用 Getdist 绘制曲线在 jupyter 中。对于标记参数我有问题。 我写 \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() 进行检查,该函数返回所提供字符的相应 ASCII 表索引 - 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'

关于python - 在 jupyter 中写\alpha 和\beta 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55181628/

相关文章:

latex - 全新安装 PGF/TikZ 崩溃,为什么?

python - 随机化数字时如何防止重复?

python - Django:无效的 block 标记: 'static',预期为 'endif'

python - Unicode编码错误: 'ascii' codec can't encode character u'\u2013' in position 7

python - 你如何在 Jupyter notebook 中换行?

jupyter-notebook - 设置 Ctrl+L 在 VS Code Jupyter 笔记本中选择行

python - Matplotlib:如何防止 Jupyter 将大图压缩到单个单元格中?

intellij-idea - 预览 Latex 文件 IntelliJ(Idea、PyCharm ..)

LaTeX 列表包 : copy-pastable listings

python - 如何将值合并到 discord.py 中的一条消息中