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.