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.
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.
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}
\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.
\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.
Jan 24, 2013 at 13:52
\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.
\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?
Jan 24, 2013 at 19:50
\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
.
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.
\DeclarePairedDelimiter
, see: tex.stackexchange.com/a/56130/6993
\left
and \right
macros (e.g. the ones from mleftright
) in order to get the right spacing?
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.
\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.
\ensuremath
for \coord
, but typesetting a formula containing +
and =
outside a math environment.
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.
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)$.