Spacing for homogeneous coordinates

Homogeneous coordinates in projective geometry are usually denoted like this: $[x:y:z]$. However, I think that : plays the role of a comma, and should be surrounded by much smaller spaces than for other uses of :.

Is there a simple way in LaTeX to automatically adjust the spacing in homogeneous coordinates, without messing with the spacing of other uses of :?

• Personally, I think the colon should be treated like a binary operator (written as \mathbin:) in this context. No, I understand it is not binary, it's n-ary, but it still walks and quacks like an operator to me, not as punctuation. (To me, the square brackets are incidental, and I'd just as soon do without them. It is the colons that turn the list of coordinates into a point in projective space.) – Harald Hanche-Olsen Feb 14 '11 at 16:42

Set it as a {:} or use \mathpunct{:}

\documentclass{article}
\usepackage[french]{babel}
\makeatletter
\def\Coor#1{\begingroup\mathcode\:="603A[\Coor@i#1::\@nil}
\def\Coor@i#1:#2:#3\@nil{%
#1\ifx\relax#2\relax ]\else\mathpunct{:}\Coor@i#2:#3\@nil\fi\endgroup}
\makeatother

\begin{document}

$\Coor{1}$
foo $\Coor{1:2}$ bar $\Coor{1:2:3}$ baz $[1:2:3]$

\end{document}
• Thank you, but the number of coordinates may vary. Is there a way to ask LaTeX to systematically treat ':' specially inside a given command? – Benoît Kloeckner Feb 14 '11 at 14:22
• see edited answer – user2478 Feb 14 '11 at 14:39
• I think you can remove \@nil and #3. – Bruno Le Floch Feb 14 '11 at 15:07
• Thanks, your solution works... except it's overrun by babel (I write in French). – Benoît Kloeckner Feb 14 '11 at 15:19
• @Benoît, I edited the code for french and an active : – user2478 Feb 14 '11 at 16:15

I think it's better to consider : as a binary operator (without a break point after it).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel} % just for testing

\newcommand{\pcoor}{%
\begingroup\lccode~=: \lowercase{\endgroup
\edef~}{\mathbin{\mathchar\the\mathcode:}\nobreak}%
[% opening symbol
\begingroup
\mathcode:=\string"8000
#1%
\endgroup
]% closing symbol
}

\begin{document}

Coordonnées projectives sur la ligne: $\pcoor{a:b}$

Coordonnées projectives sur le plan: $\pcoor{a:b:c}$

Coordonnées projectives sur l'espace: $\pcoor{a:b:c:d}$

\end{document} The same with \mathpunct instead, by changing the \edef line into

\edef~}{\mathpunct{\mathchar\the\mathcode:}}% The \mathbin version without loading babel-french, just to see it's independent of it (the problem is that the french option makes : into a shorthand).

\documentclass{article}

\newcommand{\pcoor}{%
\begingroup\lccode~=: \lowercase{\endgroup
\edef~}{\mathbin{\mathchar\the\mathcode:}\nobreak}%
[% opening symbol
\begingroup
\mathcode:=\string"8000
#1%
\endgroup
]% closing symbol
}

\begin{document}

Projective coordinates on the line: $\pcoor{a:b}$

Projective coordinates on the plane: $\pcoor{a:b:c}$

Projective coordinates on the space: $\pcoor{a:b:c:d}$

\end{document} 