2

I am setting questions onto my university's version of Moodle. This accepts LaTeX commands so I can write most maths into a question, however I can only use the preinstalled packages which does not include the braket package, but does include amsmath etc (there isn't exactly a list anywhere).

So is there a way I can write kets when the \ket{} command does not work?

Using the greater than symbol is not really ideal.

  • 2
    What symbol do you want? Like \lvert \rangle? If yes, you can define \newcommand{\ket}[1]{\lvert #1 \rangle} on preamble and simply use as \ket{}. – Sigur Feb 11 at 15:24
  • 2
    The actual code in braket.sty, i.e. after removing the comments, is actually very short. You could just put it in the preamble of your document sandwiched between \makeatletter and \makeatother. This is so much more powerful since the middle vertical lines also adjust their sizes. – user194703 Feb 11 at 15:29
  • 1
    @Sigur - Short answer: No. Longer answer: mathtools loads amsmath, and amssymb loads amsfonts. – Mico Feb 11 at 15:30
  • 1
    @Mico, I'll never memorize which one loads others. – Sigur Feb 11 at 15:31
  • 4
    It might be an idea to figure out how Moodle actually renders math. Is it rendered as images or more like mathjax or katex? This will greatly affect any answer we can provide. – daleif Feb 11 at 15:39
3

It is possible to put the command at the top of the document body, instead of the preamble.

You want the option to specify the size manually, since a bra and its matching ket should always be the same size. If your preamble includes mathtools, you have an easy way to create new paired delimiters. Otherwise, here's something quick and dirty:

\documentclass{book}
\usepackage{amsmath}

\begin{document}

\newcommand\bra[2][]{#1\langle {#2} #1\rvert}
\newcommand\ket[2][]{#1\lvert {#2} #1\rangle}

\begin{align*}
  \bra{x}                   &\; \ket{y} \\
  \bra[\Big]{x^{c^k}_{a_b}} &\; \ket[\Big]{y}
\end{align*}

\end{document}

Bra-ket sample

| improve this answer | |
2

Here is what I use.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\bra}[1]{\langle#1\rvert} % Bra
\newcommand{\ket}[1]{\lvert#1\rangle} % Ket
\newcommand{\qprod}[2]{ \langle #1 | #2 \rangle} %Inner Product
\newcommand{\braopket}[3]{\langle #1 | #2 | #3\rangle} % Matrix Element
\newcommand{\expect}[1]{ \langle #1 \rangle} % Expectation value

\begin{document}
    \begin{align*}
        \bra{\psi}\\
        \ket{\phi}\\
        \qprod{\psi}{\phi}\\
        \braopket{\psi}{A}{\phi}\\
        \expect{A}
    \end{align*}
\end{document}

enter image description here

| improve this answer | |
1

AMSmath is not suited for physics writing. You can use physics package: Physics. This is suitable for physics content and offers much more than bra-ket typing

| improve this answer | |
  • 3
    There are many on the site who does not recommend the physics package as it makes a lot of questionable choices and unintuitive syntaxes. So knowing who to build your tools properly is a better choice – daleif Jul 11 at 17:11

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.