python - 如何让 LaTeX 代码按字面意义存储在 Python 中?

标签 python latex

我正在使用 python 和 sqlite3 制裁剪理解决方案的数据库。我有很多想要存储的 LaTeX 代码,但我遇到了问题。很多 LaTeX 代码都有 python 解释的字符,而不是仅仅接受文字文本。例如,我试过以下方法来存储\frac{}{}:

foo = "\frac{}{}"
foo2 = """\frac{}{}"""
foo3 = '''\frac{}{}'''
print foo
rac{}{}
foo
Out[10]: '\x0crac{}{}'

我真的很想把它作为原始的 ascii 字符逐字存储。有办法做到这一点吗?

最佳答案

我会简单地使用 raw strings :

foo = r"\frac{}{}"

这将阻止 Python 将反斜杠解释为转义序列,并将按原样包含它们。

关于python - 如何让 LaTeX 代码按字面意义存储在 Python 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7495693/

相关文章:

latex - 我听说 LaTeX 是图灵完备的。有没有用 LaTeX 编写的程序?

latex - 如何对多种语言/语言变体的 LaTeX 进行拼写检查

r - 操作 xtable() 输出

latex - 如何从 rbookdown pdf 中删除空白页?

latex - Latex 中的多语言文档

python - 通过某种内存提高 BFS 性能

python - 是否存在用于在 Excel、CSV 和 SQL 之间打乱数据的现有库?

python - '库未加载 : @rpath/libcudart. 7.5.dylib' Mac 上的 TensorFlow 错误

python - 每次我在 Python shell 中按回车键时如何运行一个函数

python - 如何在 python 中标记输入文件中的自然英文文本?