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.

I like to use $:=$ for "is defined to be equal to", but this is never typeset with the symmetry one would like, as the colon is always too low relatively to the equals sign. Is there any way of getting this to appear correctly?

share|improve this question
3  
":=" is usually meant to be a quite different concept, namely imperative assignment. –  Charles Stewart Oct 18 '10 at 12:58
19  
@Charles: I've seen it used for both. Pure mathematicians, who have little use for imperative assignment, I think tend to use it more for definitional equality. –  Antal S-Z Nov 3 '10 at 19:34
3  
Oh yes, they do, all the time. –  Hendrik Vogt Nov 4 '10 at 7:26
3  
@Charles: I don't think it's any sloppier than, say, an algebraist writing H < G for "H is a subgroup of G". Sure, we think of < as meaning numerically less than, but there's no ambiguity in the context. And there's a related meaning in both cases: both uses of < give rise to a poset, and both uses of := mark some "special" form of equality. And since most mathematicians have no use for the imperative :=, there's no confusion. Just my 2¢. (Personally, I'm not particularly fond of either usage of :=, preferring "we define x to be …" or "x = …" for the one and "var ← value" for the other.) –  Antal S-Z Nov 4 '10 at 10:28
2  
@Antal: This analogy doesn't work at all! Using < with subgroups is fine, because subgrouphood is a well-behaved order relation. But the use of ":=" in imperative programming is not much like equality, because it does not equate what is at the two sides: the left hand side is a reference, whilst the right hand side is an expression - after executing "x:=y", x and y are not the same variable. I agree that the mathematicians for whom there is a risk of confusion seem to avoid the usage. –  Charles Stewart Nov 4 '10 at 13:36

8 Answers 8

up vote 72 down vote accepted

See the mathtools package, which offers the macro \coloneqq for this purpose.

\documentclass{standalone}
\usepackage{mathtools}
\begin{document}
\( b := 10 \) \emph{versus} \( b \coloneqq 10 \).
\end{document}

yields

Preview of the above document

Click image or right here to see it at full size (1600×133).

Note that the colon is slightly too low on the left, but vertically centered on the right.

share|improve this answer
    
I don’t get it. Isn’t the \coloneqq in the image just as asymetric as the := on the left? What does the package solve, then? –  Emil Jeřábek May 20 at 16:48
2  
@EmilJeřábek Perhaps you can't see it very well in the image, but if you run the code and zoom in on the PDF you'll find the second version has the : and = on the same axis whereas the first one doesn't. –  Joseph Wright May 20 at 16:55

This answer is an attempt to make Matthew happy, who doesn't like that the dots in the colon are so far apart. (@Matthew: I do understand that you don't like it.)

\makeatletter
\newcommand*{\defeq}{\mathrel{\rlap{%
                     \raisebox{0.3ex}{$\m@th\cdot$}}%
                     \raisebox{-0.3ex}{$\m@th\cdot$}}%
                     =}
\makeatother

EDIT:

To make Matthew even happier, I provide yet another answer that uses a different approach (motivated by the definition of \vdots) where the dots are smaller:

\newcommand*{\defeq}{\mathrel{\vcenter{\baselineskip0.5ex \lineskiplimit0pt
                     \hbox{\scriptsize.}\hbox{\scriptsize.}}}%
                     =}

share|improve this answer
    
thanks for caring about my happiness. :-) In addition to the dots being the same distance apart as the lines, I were writing ":=" with chalk or pencil I think the diameter of the dots would be about the same as the line width. Can you do that? –  Matthew Leingang Nov 3 '10 at 18:12
1  
@Matthew: Happy now? –  Hendrik Vogt Nov 3 '10 at 19:13
1  
Not bad at all. –  Matthew Leingang Nov 3 '10 at 19:18
1  
Fantastic! I've been looking for this for ages. +++++1 –  Glen Wheeler Sep 6 '11 at 7:45
2  
@tohecz: You're right, but do you really want to define something in an index? Or is there some other usage of the symbol? –  Hendrik Vogt Feb 10 '13 at 8:00

I prefer Donald Arseneau's hack that can be found on the TeX FAQ (sorry, this links to a page in German):

\mathchardef\ordinarycolon\mathcode`\:
\mathcode`\:=\string"8000
\begingroup \catcode`\:=\active
  \gdef:{\mathrel{\mathop\ordinarycolon}}
\endgroup

Just put this code into your preamble. Then you can use := as usual, and you'll get horizontal symmetry. Much easier to use than \coloneqq, in my opinion.

share|improve this answer
24  
This is already part of mathtools: \mathtoolsset{centercolon} –  Will Robertson Oct 17 '10 at 14:34
    
@Will Robertson: Thanks for the tip. I already thought that this should be in some package, but didn't find it. –  Hendrik Vogt Oct 17 '10 at 14:40

Obligatory ConTeXt solution: \colonequals; which uses a composed character in MkII and the proper unicode math character in MkIV

share|improve this answer

I actually think that symbol looks ugly. It would be OK if the spacing between the dots were the same as that between the lines of the equals. But I use

\newcommand{\defeq}{\stackrel{\text{def}}{=}}

instead.

share|improve this answer
5  
Whereas I think that the overset "def" is ugly (and illegible from any distance)! There's no accounting for taste ... –  Loop Space Oct 18 '10 at 8:04
12  
One advantage of := is that ir is bidirectional. := and =: mean different things. \defeq and \triangleeq loose that distinction. –  Aditya Oct 18 '10 at 13:41
4  
+1 for this. ":=" is programming jargon and, as Charles Stewart points out, misused programming jargon. Personally, I prefer \newcommand{\defeq}{\stackrel{\textup{\tiny def}}{=}}. Then Andrew Stacey can't see it at all, and everyone's happy. –  Mephisto Oct 19 '10 at 0:08
2  
@Charles: thanks for matching my braces. @Aditya: I see your point of view, but I think bidirectional means the opposite of the way you're using it. –  Matthew Leingang Oct 21 '10 at 1:08
1  
@Matthew: I'd use your \defeq to indicate that an equality holds by definition (i.e., by a definition stated earlier). I've posted another answer that changes the spacing of the dots. –  Hendrik Vogt Nov 3 '10 at 16:49

There is also a package by Heiko Oberdiek: colonequals

Some fonts have dedicated characters for these symbols. Unfortunately, there are name clashes concerning \coloneq, which may refer to :- or to ≔ (U+2254, :=).

share|improve this answer
3  
pxfonts is one of the fonts with this already in. –  Loop Space Oct 18 '10 at 8:03

A way to get this with pxfonts without including the whole package:

\DeclareSymbolFont{symbolsC}{U}{pxsyc}{m}{n}
\DeclareMathSymbol{\coloneqq}{\mathrel}{symbolsC}{"42}

and you get:

it's a:= b magic!

share|improve this answer

My solution is

\def\defeq{\mathrel{\mathop:}=}
share|improve this answer
    
This is not a good solution because you can have a line break between the : and the = (mathtools had this bug a while back, see groups.google.com/group/comp.text.tex/msg/…). –  Aditya Nov 3 '10 at 17:54
4  
@Aditya: something like \mathrel{\mathop:}= does not break between lines, but using \mathrel{\mathop:}\mkern-1.2mu= as in mathtools does introduce a breaking point at the \mkern (and can be solved by putting a \nobreak just before \mkern or by wrapping everything in a \mathrel). –  Philippe Goutet Dec 11 '10 at 23:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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