Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Space after LaTeX commands

I`ve made a few very short commands, and they work, alas the spacing after them is wrong.

\newcommand{\yaksen}{$y$-aksen}
\newcommand{\xaksen}{$x$-aksen}
\newcommand{\zaksen}{$z$-aksen}

This produces no space after the commands, so if i type

this is an example \yaksen, is the norwegian term for the y-axis.
and the \zaksen is perpendicular to both the \xaksen and the \yaksen.

The output is

this is an example y-aksen, is the norwegian term for the y-axis.
and the z-aksenis perpendicular to both the x-aksenand the y-aksen.

However, putting blank spaces after the commands. Like this

\newcommand{\yaksen}{$y$-aksen }
\newcommand{\xaksen}{$x$-aksen }
\newcommand{\zaksen}{$z$-aksen }

Produces this

this is an example y-aksen , is the norwegian term for the y-axis.
and the z-aksen is perpendicular to both the x-aksen and the y-aksen .

Is there any easy way to obtain correct spacing? I think I`ve read something about it, but my searches ended in vain.

share|improve this question
1  
See tex.stackexchange.com/questions/31091/…. If this answers your question, please leave a comment so that we can close this question and link it to the previous one. –  Yiannis Lazarides Oct 24 '11 at 6:41
add comment

marked as duplicate by Werner, Yiannis Lazarides, Jake, lockstep, Alan Munn Oct 25 '11 at 13:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 3 down vote accepted

You need to use \xspace provided by the xspace package. It checks to see whether the character following a command sequence is a space or not, and inserts a space accordingly:

enter image description here

\documentclass{article}
\usepackage{xspace}% http://ctan.org/pkg/xspace
\newcommand{\yaksen}{$y$-aksen\xspace}
\newcommand{\xaksen}{$x$-aksen\xspace}
\newcommand{\zaksen}{$z$-aksen\xspace}
\begin{document}
this is an example \yaksen, is the norwegian term for the y-axis.
and the \zaksen is perpendicular to both the \xaksen and the \yaksen.
\end{document}
share|improve this answer
    
thanks! It worked =D –  N3buchadnezzar Oct 24 '11 at 6:53
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.