# Writing vector * matrix * vector

I am using $\vec{s}^\intercal \vec{A} \vec{s}$ to represent s^T * s * S where s is a column vector and A is a square matrix. The problem with this representation is that there is little too much space between s^T and As.

Is there a way I can represent this with uniform spacing?

PS: I am using \renewcommand{\vec}[1]{\mathbf{#1}}.

-

This may depend on personal preference, but you could increase of decrease the horizontal gap between your vectors/matrices:

\documentclass{article}
\usepackage{amssymb}% http://ctan.org/pkg/amsmath
\renewcommand{\vec}[1]{\mathbf{#1}}
\begin{document}
$\vec{s}^\intercal\!\vec{A} \vec{s}$ \quad
$\vec{s}^\intercal \vec{A}\mskip\thinmuskip \vec{s}$
\end{document}


The first example adds a negative \thinmuskip to draw A closer to s^T, while the second example reverses this process, pushing s \thinmuskip away from A.

Perhaps, in this instance, in may be advisable to produce a command that could do this spacing for you, rather than fiddle with the spacing every time (for consistency):

\newcommand{\vmprod}[3]{%
\vec{#1}^\intercal\!\vec{#2}\vec{#3}%
}


Now you would be able to use $\vmprod{s}{A}{s}$ and obtain the spacing provided in the first example.

You could go one step further. If your structure is very similar and usually has the form s^T A s, you could structure the command to take only two arguments, with an optional third using xparse:

\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{amssymb}% http://ctan.org/pkg/amsmath
\renewcommand{\vec}[1]{\mathbf{#1}}
\NewDocumentCommand{\vmprod}{o m m}{%
\IfNoValueTF{#1}
{\vec{#3}^\intercal}% \vmprod{A}{s}
{\vec{#1}^\intercal}% \vmprod[t]{A}{s}
\!\vec{#2}\vec{#3}%
}
\begin{document}
$\vmprod{A}{s}$ \quad
$\vmprod[x]{A}{y}$
\end{document}

-
this works only if #2 is "A" -- it's the relative shapes of "A" and \intercal that result in the gap. –  barbara beeton Jan 18 '12 at 13:53

Tex automatically inserts a space \scriptspace (0.5pt) after every sub or superscript. Define a command to get rid of it

\newcommand\transp{^\intercal\kern-\scriptspace}


and then use it

$\vec{s}\transp \vec{A} \vec{s}$


Some letters may need additional kerning, compare

-