# Typesetting coordinates

I'm trying to typeset coordinates like:

(0 0 0) or (0, 0, 0)

I'm not sure if LaTeX offers a package which can make the notation a bit more professional than just manually inserting spaces between each coordinate.

-
Commas are most frequently used for separating coordinates. – egreg May 1 '12 at 13:15
Related Question: Typesetting Sets. – Peter Grill Mar 14 at 9:23

If you later decide to change formatting (adjusting spacing, etc.), here's an adaptation of Ryan Reich's answer to a similar question about vectors. It will at least give you a semantic command for coordinates:

\documentclass{article}
\usepackage{amsmath}
% From Ryan Reich, http://tex.stackexchange.com/a/19698/3345
\def\vektor#1{\innervector(#1)}
\def\innervector(#1,#2,#3) {\ensuremath{\left( #1,#2,#3 \right)}}

\let\coord\vektor

\begin{document}
Displaymath version, probably not relevant: $\coord{a,b,c}$
Inline version: \coord{a,b,c}
\end{document}


-
Using \ensuremath in this context is very wrong. Try \coord{a,b,c}=\coord{1,2,3}+\coord{4,5,6} versus $\coord{a,b,c}=\coord{1,2,3}+\coord{4,5,6}$. This is a misuse of concept that easily leeds to bad typography. – yo' Jan 24 '13 at 11:06
If you mean the change in spacing when your first \coord line is rendered as three expressions with text-mode spacing around the = and +, I agree. If you mean something else, I don't yet understand. – Mike Renfro Jan 24 '13 at 13:52
Yes, that is exactly what I mean. The macro \ensuremath is one of the things I really dislike in LaTeX. IMHO it should have been \ensur@math so that unaware users don't use it at all. --- Making math macro available in text mode is very wrong and dangerous, notice that no built-in macros (symbols etc.) don't allow it, nor do the ones you define using standard methods (\DeclareMathOperator, \DeclarePairedDelimiter etc.). It happens to everybody that he forgets to switch to mathmode and that's why it should raise an error. – yo' Jan 24 '13 at 16:01
I could be doing it wrong, but in the research proposal I've been writing for far too long, I make tons of use of \ensuremath macros. For one, because I've tried to train myself to use $$ and $$ instead of '$' and '$', and defining macros so I can more easily write things like sum of an elastic component (\Jel) and a plastic component (\Jpl) or $$\J = \Jel + \Jpl$$ with the two values defined as macros like \newcommand{\Jel}{\ensuremath{\J_\textnormal{el}}\xspace} -- is there a better option I've missed somewhere? – Mike Renfro Jan 24 '13 at 19:50
Since I would not put standalone \Jel in parentheses, I would end with $$\Jel$$, which is not that bad. And \xspace is exactly the second thing I don't like, exactly because it means "losing of control". It's IMHO much more convenient and consistent to write \xyz{}  instead of relying on \xspace and having to remember whether I put it in the command or not. Of course, in your case, I would have $$\JpL$$  and no {} not \xspace. – yo' Jan 26 '13 at 23:50

A solution that works for any number of coordinates (well, at least one):

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\coord}{sO{}m}
{
\IfBooleanTF{#1}
{\left(\coord_print:n {#3}\right)}
{\mathopen{#2(}\coord_print:n {#3}\mathclose{#2)}}
}

\seq_new:N \l_coord_list_seq
\tl_new:N \l_coord_last_tl
\cs_new_protected:Npn \coord_print:n #1
{
\seq_set_split:Nnn \l_coord_list_seq { , } { #1 }
\seq_pop_right:NN \l_coord_list_seq \l_coord_last_tl
\seq_map_inline:Nn \l_coord_list_seq { ##1 , }
\tl_use:N \l_coord_last_tl
}
\ExplSyntaxOff

\begin{document}

$\coord{0,1,0}$

$\coord[\Big]{0,1,2,3,4}$

$\coord*{\dfrac{1}{2},2}$

$\coord{1}$

\end{document}


With the *-variant we use \left and \right; with the optional argument one can choose an explicit size (with \big, \Big, \bigg or \Bigg).

By changing the comma or the parentheses in the definition, one can modify the appearance.

-
You can express that in an easier way using \DeclarePairedDelimiter, see: tex.stackexchange.com/a/56130/6993 – mSSM May 16 '12 at 19:25
@mSSM Yes, but with these macros it's easy to change the comma into anything else. – egreg May 16 '12 at 22:20

You might want to define a dedicated command, like

\newcommand{\coord}[3]{\ensuremath{(#1,#2,#3)}}


This allows you to insert coordinates in or out of math environments, e.g., \coord{1}{2}{3}. Later, you can change the typesetting of the coordinates easily by adapting a single line.

-
Using \ensuremath in this context is very wrong. Try \coord{a,b,c}=\coord{1,2,3}+\coord{4,5,6} versus $\coord{a,b,c}=\coord{1,2,3}+\coord{4,5,6}$. This is a misuse of concept that easily leeds to bad typography. – yo' Jan 24 '13 at 11:06
@tohecz: This depends on the point of view. The problem of your “counter-example” isn't \ensuremath for \coord, but typesetting a formula containing + and = outside a math environment. – simon04 Feb 4 '13 at 9:35
Which has never happened to any of us of course. The LaTeX error Missing $inserted (when you use math-mode macro in text-mode) has rescued me many times, and you, by using \ensuremath get rid of this rescue system. – yo' Feb 4 '13 at 9:41 You do not have to manually insert any spaces, just use the math-mode and LaTeX will insert the proper spaces itself: We have a vector$(x,y,z)$that is orthogonal to$(1,2,3)$and$(4,5,6)\$.

-