The braket
package defines Dirac's braket notation. To use it in Lyx, I add the line:
\usepackage{braket}
to the LaTeX preamble. Then Lyx will be able to compile commands like \bra
and \ket
. Problem is that the Lyx editor itself won't recognize this commands.
If instead of using the braket
package I had defined math-macros for the commands \bra
, \ket
, etc., I could tell Lyx how these things should look in the editor. That is, I can tell it to put an \rangle
before the argument (that Lyx knows how to draw) and a |
after.
Is there a way to use the \bra
, \ket
, etc., commands from the braket
package, and still be able to tell Lyx how these should look in the editor?
EDIT: Right after posting, I discovered this question, which mentions the Instant Preview feature of Lyx. Although this kind of fixes my issue, it's not exactly what I want. I want to be able to specify what the command should look like in the editor, in terms of other commands that Lyx already recognizes (in the editor), like I would do with a math-macro.
Best Answer
Place
\let\realket\ket
in your preamble, and then redefine\ket
using LyX's new command feature, providing LyX with the TeX code to use and the LyX code to display.\let
, like\def
, takes two arguments. When you say\let\realket\ket
, you instruct TeX to copy the definition of\ket
into\realket
. This differs from\def
in as much as\ket
isn't itself mentioned in the definition of\realket
(IIRC, it's a one-level-deep copy), whereas\def\realket\ket
would simply have\realket
'pointing to'\ket
, where\ket
s definition could change at any time. Since the definition of\ket
frombraket
is saved into\realket
, you are free to redefine\ket
to whatever you please :)