276

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?

Charles Stewart
  • 21,014
  • 5
  • 65
  • 121
  • 3
    ":=" is usually meant to be a quite different concept, namely imperative assignment. – Charles Stewart Oct 18 '10 at 12:58
  • 53
    @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 Spector-Zabusky Nov 03 '10 at 19:34
  • 10
    Oh yes, they do, all the time. – Hendrik Vogt Nov 04 '10 at 07:26
  • @Antal, @Hendrik: I've seen it, but I thought it was fairly rare. I certainly think it is sloppy. – Charles Stewart Nov 04 '10 at 09:50
  • 12
    @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 Spector-Zabusky Nov 04 '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 04 '10 at 13:36
  • 1
    @Charles: You make a valid point about <. I might instead compare := to → being used for implication and the type of a function (whose relationship was discovered, I believe, after the notation); or the use of [a,b] for the closed interval from a to b in one context and the commutator of a and b in another; or the use of ⊥ to mean both perpendicular and false. Sometimes identical notations arise, but I don't think there's anything wrong with that if they end up in such different fields. – Antal Spector-Zabusky Nov 04 '10 at 18:09
  • As regards the discussion about using ":=" for "defined to be equal to," I was always told that ":=" is a sort of neologism resulting from Mathematica syntax, whereas the original notation is the three-bar equal sign (the same one you use for "identically equal to"). For what it's worth. –  Apr 17 '12 at 21:34
  • 5
    @user, you were misinformed. The symbol goes much further back, to APL and the Pascal family of languages. It's meant to resemble APL's left-pointing arrow, which is of course not part of ASCII. That's why people associate it with "imperative assignment" in the discussion. – alexis Apr 18 '13 at 10:17
  • Related: http://tex.stackexchange.com/questions/125023/mathtools-vcentcolon-and-fouriers-utopia – Steven B. Segletes Oct 28 '15 at 14:31
  • 1
    I have in the book metamathematische Methoden in der Geometrie found the wonderful convention of typesetting a := b as a\colon=b. The nice thing about this notation is that it readily generalizes to logical definitions of the form a\colon\leftrightarrow b where you cannot readily assert equality. It also looks great as it avoids the visual problem of the : and = not aligning. – FUZxxl Oct 02 '17 at 15:47
  • You don't need to do anything; it's already typeset "correctly" by plain old $:=$. The offset you see between the horizontal planes of symmetry of the colon and the equals sign is also present when the symbol is defined, in item 2-7.3 of the ISO 80000-2:2009 standard. – Daniel Hatton Aug 27 '20 at 20:58

12 Answers12

247

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

\documentclass{standalone}
\usepackage{mathtools}
\begin{document}
\( b := 10 \) \emph{versus} \( b \coloneq 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.


Edit: as of 2022, \coloneq replaces legacy \coloneqq (which is still supported, but now labeled a 'Legacy duplicate name' in the mathtools docs' colon symbols list)

postylem
  • 276
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 21
    @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 '14 at 16:55
  • 9
    Is there a unicode symbol for :=, with same benefits as \coloneqq? Yes: U+2254 – phs Mar 07 '17 at 12:12
98

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.}}}%
                     =}

Hendrik Vogt
  • 37,935
  • 4
    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 03 '10 at 18:12
  • @Matthew: I saw this question coming ... yes, the dots are rather large, and I should be able to make them smaller. – Hendrik Vogt Nov 03 '10 at 18:18
  • 5
    @Matthew: Happy now? – Hendrik Vogt Nov 03 '10 at 19:13
  • 3
    Not bad at all. – Matthew Leingang Nov 03 '10 at 19:18
  • 8
    Fantastic! I've been looking for this for ages. +++++1 – Glen Wheeler Sep 06 '11 at 07:45
  • 1
    You miss usability in indices – yo' Feb 09 '13 at 20:59
  • 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 08:00
  • What’s nice is that it’s easy to adapt for ::= (the symbol we use for BNF grammar definitions). What’s less nice is that the tweaking apparently depends on the font and size (in my case I had to reduce the \baselineskip and put the dots in \tiny instead of \scriptsize, and their size doesn’t adapt when the font size changes; for that I replaced \tiny with \smaller[3] from package relsize). Any way to adjust to the height of the equal sign and/or to the width of its bars automatically? – Maëlan May 10 '22 at 17:34
38

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.

Per @Will Robertson's comment, there is also a feature of mathtools to change the vertical alignment of all colons in math mode.

\mathtoolsset{centercolon}
Paul Wintz
  • 402
  • 2
  • 14
Hendrik Vogt
  • 37,935
19

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

doncherry
  • 54,637
Aditya
  • 62,301
15

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, :=).

doncherry
  • 54,637
Philipp
  • 17,641
12

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!

diabonas
  • 25,784
einpoklum
  • 12,311
11

I tried quite some of the solutions given here but none of those seemed satisfactory to me. Most of them only solve the problem of the vertical alignment of the colon but do not respect the length of all the other binary relations, that is ":=" is much longer than "=" and the like.

My suggestion hence is the following:

\newcommand{\eqcolon}{\mathrel{\resizebox{\widthof{$\mathord{=}$}}{\height}{ $\!\!=\!\!\resizebox{1.2\width}{0.8\height}{\raisebox{0.23ex}{$\mathop{:}$}}\!\!$ }}}
\newcommand{\coloneq}{\mathrel{\resizebox{\widthof{$\mathord{=}$}}{\height}{ $\!\!\resizebox{1.2\width}{0.8\height}{\raisebox{0.23ex}{$\mathop{:}$}}\!\!=\!\!$ }}}

This will result in ":=" beeing equally long as "=" so it will align properly in multiline math equations. Below is a comparisson of the approach \newcommand{\eqcolon}{\ensuremath{\mathrel{=\!\!\mathop{:}}}} with my suggestion. Note how the lines align properly in amsmath align environments.

Before:

unaligned relations

After:

aligned relations

jenom
  • 111
10

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.

Charles Stewart
  • 21,014
  • 5
  • 65
  • 121
Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • 13
    Whereas I think that the overset "def" is ugly (and illegible from any distance)! There's no accounting for taste ... – Andrew Stacey Oct 18 '10 at 08:04
  • I've used $\hat{=}$ for definitional equality. – Charles Stewart Oct 18 '10 at 13:01
  • 20
    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
  • 5
    +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 00:08
  • 3
    @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 01:08
  • 3
    @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 03 '10 at 16:49
  • 1
    In a similar vein, I've also seen (and quite like) \stackrel{\Delta}{=}. – Simon Nov 04 '10 at 00:00
10

My solution is

\def\defeq{\mathrel{\mathop:}=}
Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • 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 https://groups.google.com/group/comp.text.tex/msg/50796a27e6b04a0f?hl=en). – Aditya Nov 03 '10 at 17:54
  • 9
    @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
6

You may try \coloneq (as well as \eqcolon) from unicode-math package:

enter image description here

Note that unicode-math requires XeLaTeX/LuaLaTeX.

stone-zeng
  • 2,710
4

I use \vcentcolon= from the mathtools package. I like it better than \coloneqq because with the former, there is more spacing between the colon and the equals sign.

enter image description here

3

Edit: I didn't know this at the time of writing this answer, but commath is not a well designed package, and it can lead to obscure problems. I would stay away from it and use a solution from another answer.


The commath package automatically fixes the alignment of := and =: in math mode.

...
\usepackage{commath}
...
\begin{gather*}
a := b \\
b =: a
\end{gather*}
...

cropped render of the above code