# How can I add space before my unit vectors?

This is how I'm currently typesetting vectors:

\documentclass{article}

\newcommand{\ih}{\mathbf{i}}
\newcommand{\jh}{\mathbf{j}}
\newcommand{\kh}{\mathbf{k}}

\begin{document}

$1/z \ih + \jh - y/z^2 \kh$

\end{document}


This gives me:

I think the unit vectors are too close to the expressions they follow. But if I place a \, in the definitions of the commands, extra spacing will also be added before the j-component here, which would look odd. What is the best way to add more spacing, preferably by changing the definitions of my unit vectors?

• Check out the \xspace package. It may solve your problem. – Ruben Jul 12 '15 at 17:39
• @Ruben I don't think it will. From what I hear, xspace is for inserting spaces after macros, not before. (It peeks at the next token, not the previous one.) – Radon Rosborough Jul 12 '15 at 17:54
• Totally right, I realised that too now. Maybe try parentheses: $(1/z)\ih + \jh - (y/z^2) \kh$. It's really not an answer to your question, but I think it helps to make the expression look clearer with less work. – Ruben Jul 12 '15 at 17:59
• Why not just $1/z\, \ih + \jh - y/z^2\, \kh$? – Zarko Jul 12 '15 at 17:59
• @Zarko, because the author of the OP wants to automate this. – Ruben Jul 12 '15 at 18:00

It's a similar situation as for the differential symbol in integrals:

\documentclass{article}

% avoid code duplication
\newcommand{\unitvector}[1]{%
\mathop{}\!\mathbf{#1}%
}

\newcommand{\ih}{\unitvector{i}}
\newcommand{\jh}{\unitvector{j}}
\newcommand{\kh}{\unitvector{k}}

\begin{document}

$1/z \ih + \jh - y/z^2 \kh$

$(a+b)\ih + (a+b)\jh$

\end{document}