The braket package defines Dirac's braket notation. To use it in Lyx, I add the line:


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.

  • If I recall correctly, there are two fields when you define a new macro from within LyX, one for LyX's preview and one for TeX's use. Does this have the effect that I remember? – Sean Allred Jun 7 '13 at 0:37
  • @SeanAllred That's right. Two fields in a math-macro in Lyx. The problem is that if I want to use the braket package, that means that the LaTeX command \ket is already defined, so I can't create a macro \ket in this case. I could define a command with another name, like \ket2, but that seems too ugly... isn't there a better way? – becko Jun 7 '13 at 2:54
  • 1
    You may be able to \let\realket\ket and then renew ket to be real ket. – Sean Allred Jun 7 '13 at 21:56
  • @SeanAllred That works! I put the \let\realket\ket command in the LaTeX preamble. I had not seen \let before. It defines a synonym? – becko Jun 8 '13 at 17:31
  • @SeanAllred Maybe you could post an answer. – becko Jun 8 '13 at 17:31

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 \kets definition could change at any time. Since the definition of \ket from braket is saved into \realket, you are free to redefine \ket to whatever you please :)

  • @becko You're most welcome :) – Sean Allred Jun 9 '13 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.