问题描述
我正在尝试使用 ket 符号,该符号通常以 \ket {\ psi}
编写。但是,在 $$ ... $$
中编写时,这不起作用。使用 IPython.display
编写时,这也不起作用。
I am trying to have the ket symbol which is usually written in latex as \ket{\psi}
. However, this doesn't work when written within the $$ ... $$
. This also doesn't work when written using IPython.display
.
推荐答案
$ latex
** \documentclass{article}\usepackage{amsmath}\begin{document}
... chatter chatter ...
* \show\ket
> \ket=undefined.
所以你的 \ket
宏即将到来从一些包或其他我不知道它是什么。这并不能解释为什么它在 $$ ... $$
中不起作用 - 你必须努力使它在显示数学中不起作用 - - 但它确实解释了为什么它在IPython中不起作用:在IPython的罐装TeX环境中没有加载哪个包(或者)IPython对TeX数学输入语言的仿真不包括这个宏。
So your \ket
macro is coming from some package or other which I don't know what it is. This doesn't explain why it doesn't work in $$ ... $$
-- you have to work at it to get things to not work in display math -- but it does explain why it doesn't work in IPython: whichever package this is isn't being loaded in IPython's canned TeX environment (or) IPython's emulation of TeX math input language does not include this macro.
这是一个合理的原始数学符号定义,它应该在显示模式下正常工作。我不知道你是否可以逐字地将它放入IPython中,但你至少应该能够在需要时写出扩展名(例如 $$ \ leftft | \ psi \ right \\ \\ _ $$ $
)
Here's a reasonable definition in terms of primitive math symbols, which should work fine in display mode. I don't know if you can put this into IPython verbatim, but you should at least be able to write out the expansion longhand when needed (e.g. $$ \left| \psi \right\rangle $$
)
\newcommand{\ket}[1]{\left|{#1}\right\rangle}
\newcommand{\bra}[1]{\left\langle{#1}\right|}
编辑:使用LaTeX首选接口定义宏,而不是原始 \ def
。
define macros using LaTeX preferred interface, rather than primitive \def
.
这篇关于IPython中的物理bra-ket符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!