CSS

Sunday, December 16, 2012

TeX macro for normal operator ordering

I've always been bothered with normal operator ordering, writing $:O(a)O(b):$ always produces bad results.

The quick fix I've been using is the following:

\def\normOrd#1{\mathop{:}\nolimits\!#1\!\mathop{:}\nolimits}

%%
% example:
% \begin{equation}
% \normOrd{a(z)b(\omega)} = a(z)_{+}b(\omega)+(-1)^{\alpha\beta}b(\omega)a(z)_{-}
% \end{equation}
%%
Which in practice looks like:

How I got this solution

I determined this solution iteratively after many different attempts, which I shall enumerate along with the problems they each had.

However, using mere colons :a(z)b(\omega): = ... produces the following:
Being clever, I asked myself "Hey, why not write :x\colon for the normal ordering?" This was clever, but wrong. Consider the following example:
g = :x\colon
Producing:
Not one to give up easily, I found a \cocolon definition on tex.stackexchange. Trying that instead:
g = \cocolon x\colon = y
Produces strange extra whitespace on the right:
After examining the co-colon code, I just determined that something along the lines of
% rough draft definition #1
\def\normOrd#1{\mathrel{:}\!#1\!\mathrel{:}}
would work. This didn't quite work, the whitespacing was strange. So instead I just use \mathop{:}\nolimits..., which produces the desired result.

5 comments:

  1. Any chance of resurrecting a post from 2009, where you wrote about latex/emacs macros? It kind-of went way over my head. Would love see a simpler tutorial. For example, is there a way to automate cite command? E.g. first ask me for page number, then for cite key?

    Cheers!

    ReplyDelete
    Replies
    1. Ah, I should give you the motivation behind that post: I was working with a netbook, and wanted to write up some notes in LaTeX.

      The problem: the "\" key was too small for me to hit!

      The solution: concoct some emacs macros to simplify typing in LaTeX code (e.g., "C-l C-e" for writing "\begin{equation}\n\n\end{equation}").

      As far as automating citation, well, I don't know offhand how to do that. But -- knowing Emacs! -- there are probably a million different packages out there...

      Delete
  2. \DeclarePairedDelimiter{\normalorder}{\vcentcolon}{\vcentcolon} with mathtools deals with it the best way, in my opinion.

    ReplyDelete
    Replies
    1. The problem with this is `\normalOrder{a^{\dagger}(k)a(k)}` results in a "! Missing { inserted" error. It is quite possible I'm an idiot and too unskilled to implement this properly ;)

      Delete
  3. Thanks for sharing these useful information! This is really interesting information for me.

    ReplyDelete