Julia - 由显示方程触发的无效转义序列
Julia - Invalid escape sequence triggered by a display equation
朱莉娅 documentation 说:
Large LaTeX equations that do not fit inline within a paragraph may be
written as display equations using a fenced code block with the
"language" math as in the example below.
```math
f(a) = \frac{1}{2\pi}\int_{0}^{2\pi} (\alpha+R\cos(\theta))d\theta
```
然而,在我的一个项目中,内联数学表达式似乎触发了 "invalid escape sequence" 错误:
"""
...
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
...
"""
我是不是理解错了文档中显示方程式的用法?
Julia 版本是 0.7
字符串中有转义序列,因此可以使用 raw
字符串:
julia> s = raw"""
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
"```math\nG_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})\n```\n"
julia> println(s)
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
或者转义\
(这个不太方便):
julia> s = """
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
"```math\nG_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})\n```\n"
julia> println(s)
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
最后,如果您使用 Markdown
模块,您可以像这样使用 doc
字符串:
julia> using Markdown
julia> s = doc"""
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
julia> println(s)
$$
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
$$
编辑:现在观察 doc
用 $$
包装数学,如上所述。另外 doc
只处理 $
和 \
所以例如插值在 doc
内工作,而不是在 raw
内工作,后者尽可能原始 :)。最后 doc
不产生字符串而是 Markdown.MD
对象。例如:
julia> using Markdown
julia> raw"""$x = 1"""
"$x = 1"
julia> doc"""$x = 1"""
1
= 1
julia> """$x = 1"""
"1 = 1"
julia> typeof(doc"""$x = 1""")
Markdown.MD
朱莉娅 documentation 说:
Large LaTeX equations that do not fit inline within a paragraph may be written as display equations using a fenced code block with the "language" math as in the example below.
```math
f(a) = \frac{1}{2\pi}\int_{0}^{2\pi} (\alpha+R\cos(\theta))d\theta
```
然而,在我的一个项目中,内联数学表达式似乎触发了 "invalid escape sequence" 错误:
"""
...
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
...
"""
我是不是理解错了文档中显示方程式的用法?
Julia 版本是 0.7
字符串中有转义序列,因此可以使用 raw
字符串:
julia> s = raw"""
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
"```math\nG_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})\n```\n"
julia> println(s)
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
或者转义\
(这个不太方便):
julia> s = """
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
"```math\nG_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})\n```\n"
julia> println(s)
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
最后,如果您使用 Markdown
模块,您可以像这样使用 doc
字符串:
julia> using Markdown
julia> s = doc"""
```math
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
```
"""
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
julia> println(s)
$$
G_u \sim PY(d_{|u|}, \theta_{|u|}, G_{\pi(u)})
$$
编辑:现在观察 doc
用 $$
包装数学,如上所述。另外 doc
只处理 $
和 \
所以例如插值在 doc
内工作,而不是在 raw
内工作,后者尽可能原始 :)。最后 doc
不产生字符串而是 Markdown.MD
对象。例如:
julia> using Markdown
julia> raw"""$x = 1"""
"$x = 1"
julia> doc"""$x = 1"""
1
= 1
julia> """$x = 1"""
"1 = 1"
julia> typeof(doc"""$x = 1""")
Markdown.MD