# DeclareMathOperator and align environment

Minimal working example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
&s + t &\text{foo}\\
&\sin x &\text{bar}
\end{align}
\end{document}


Here, the \sin (or any other operator declared with \DeclareMathOperator) is not aligned with the s, it has some spacing in front of it. I know that math operators are inserting some spacing such that x \sin y works as expected, but since there is nothing in front of the \sin here, I wouldn't expect that to apply. Typesetting the paragraph \noindent$$s + t$$\\$$\sin x$$ works as expected, too, so why doesn't it align correctly when used with the align environment?

-

Since the question already answers the cause of the space. The macro, defined by \DeclareMathOperator is defined as \mathop with additional spacing in some situations.

Here align adds an empty math ordinary atom to get correct spacing for binary or relation symbols. Also a space is added between \mathord and \mathop.

In this case the space can be avoided using an emtpy \mathopen in front of \sin. TeX does not insert a space between \mathord and \mathopen and between \mathopen and \mathop:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
&s + t &\text{foo}\\
&\mathopen{}\sin x &\text{bar}
\end{align}
\end{document}


-
@Manuel: Close, but there is a case left, a preceding punctuation atom. Putting \mathclose in \scriptstyle helps: \begingroup\scriptstyle\mathclose{}\endgroup\mathord{<here the input>}\mathopen{} – Heiko Oberdiek Jun 18 '14 at 10:17

The align environment expects a relation symbol after &, as the point of alignment, so there is an implicit {} at the beginning of the second column (and all other even numbered columns).

This has the unfortunate consequence that, if a math operator follows &, a thin space is added, because of TeX's spacing rules: when a math operator follows an ordinary atom a thin space is added, like in

$3\sin x$


which results in

3<thin space>sin<thin space>x

Solution:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
&s + t    &&\text{foo}\\
&\!\sin x &&\text{bar}
\end{align}

\end{document}


Since a thin space is automatically added, because of the rule explained above, a \! will cancel it, because it's exactly the opposite of a thin space.

Note the && before \text, so the conditions are left aligned.

Here's a set of variant environments where the automatic empty group is not added:

\documentclass{article}
\usepackage{amsmath,etoolbox}

\makeatletter
\newcommand{\patch@align@preamble}{\patchcmd{\align@preamble}{{}}{}{}{}}
\newenvironment{varalign}
{\patch@align@preamble\start@align\@ne\st@rredfalse\m@ne}
{\endalign}
\newenvironment{varalign*}
{\patch@align@preamble\start@align\@ne\st@rredtrue\m@ne}
{\endalign}
\newenvironment{varalignat}
{\patch@align@preamble\start@align\z@\st@rredfalse}
{\endalign}
\newenvironment{varalignat*}
{\patch@align@preamble\start@align\z@\st@rredtrue}
{\endalign}
\makeatother

\begin{document}

\begin{varalign}
&s + t    &&\text{foo}\\
&\sin x &&\text{bar}
\end{varalign}
text in between
\begin{varalign*}
&s + t    &&\text{foo}\\
&\sin x &&\text{bar}
\end{varalign*}
text in between
\begin{varalignat}{2}

I think you should remark that \! is exactly the space you need to substract in such case, it's not just a “small amount of negative space”. I learned it rather late. – Manuel Jun 18 '14 at 10:03