53

I'd like to typeset two compound symbols for making definitions. The following

  • \newcommand{\defeq}{\mathrel{\mathop:}=}
  • \newcommand{\eqdef}{\mathrel{\mathop=}:}

are suggested by the CTAN symbol list in the footnote on page 35. (Well, the first is suggested, and I made up the second.) Is there a better way to do this, short of including txfonts? Basically, it always looks like \defeq has more space on the left than on the right, and conversely for \eqdef.

EDIT - Most of the answers are taking about packages that fix the vertical placement of the colon. Ok, that is great and I'm interested to hear it. But let me restate my question. I want to fix the apparent difference in space on the left and right sides of \defeq. To see what I mean, look at typeset equation $a \defeq b$ in Stefan's answer. The $a$ and the $b$ are equal distances from the center. But because the colon is a lighter symbol _it_looks_ the $a$ is further away. Does that make sense?

2
  • 7
    Possible duplicate: How to typseset $:=$ correctly?
    – diabonas
    Commented Sep 18, 2011 at 19:52
  • @diabonas: The qn should be edited to refer to the older question, but it is asking for something more specific, so it is not an exact duplicate. Commented Sep 19, 2011 at 9:27

4 Answers 4

42

I recommend using a vertically centered colon which matches the equal sign better, such as \vcentcolon from the mathtools package. You can also change it generally to vertical by \mathtoolsset{centercolon}.

Compare standard :=

def equal

to the vertically centered:

def equal

So your definition could become

\usepackage{mathtools}
\newcommand{\defeq}{\vcentcolon=}
\newcommand{\eqdef}{=\vcentcolon}

with tighter spacing. And since both symbols are already relation symbols, as egreg said, we even could omit \mathrel.

And you could do that even easier by mathtools provided commands:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$a\coloneqq b \qquad b\eqqcolon a$
\end{document}
3
  • 6
    There's no need to add \mathrel with the second set of definitions, as both = and \vcentcolon are already relation symbols. The \mathop in the first definition in the first set does nothing; in the second it's wrong.
    – egreg
    Commented Sep 18, 2011 at 20:10
  • In the latter group the \mathrel is useless. The former group gives obviously wrong spacing.
    – egreg
    Commented Sep 18, 2011 at 20:24
  • The use of \mathop in the question is correct in the first definition and incorrect in the second one, as I remarked in my answer. The fact is that \vcentcolon is defined exactly as \mathrel{\mathop:}; TeX doesn't space consecutive Rel atoms.
    – egreg
    Commented Sep 18, 2011 at 20:39
12

The mathtools package offers you the centercolon = true|false option, as well as a wide range of predefined symbols that include a vertically centered colon:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\[
a \coloneqq b \quad c \Colonapprox d \quad e \dblcolon f
\]

\mathtoolsset{centercolon}
\[
a := b
\]

\end{document}
1
  • 1
    Be aware that centercolon cannot be used with french babel, og other setups that leave : active. The full names are recommended.
    – daleif
    Commented Sep 20, 2011 at 9:40
11

This, as far as I know, is the best kludge around (it's the same used by mathtools for its \vcentcolon command). However the second definition should be

\newcommand{\eqdef}{=\mathrel{\mathop:}}

otherwise both symbols would be misplaced with respect to the other, and the result would be bad anyway.

Note
As a mathematician I've never felt any need of an equals-by-definition symbol as did many others for centuries. But this risks to be the source for another religion war. :)

8
  • 2
    I completely agree with you. I don't see the need for the equals-by-definition symbol. Commented Sep 18, 2011 at 19:56
  • 1
    I've seen eqdef used in applied maths (control theory) and I quite like it there; sort of like a capital letter at the start of a sentence for maths. But I'm not a mathematician, only a lowly engineer :-) Commented Sep 18, 2011 at 22:15
  • 2
    @WillRobertson It makes sense in assignments, where it doesn't represent equality; but in definitions it's not necessary. Clarity is achieved through words, not symbols.
    – egreg
    Commented Sep 18, 2011 at 22:31
  • 2
    A colleague of mine refers to that urge that some mathematicians feel to introduce unnecessary new symbols as "conjuntivitis" (playing with "misusing the set theory object language" (set is Spanish is "conjunto") and the well known inflammation of the conjunctiva). Commented Sep 19, 2011 at 1:22
  • 1
    @Aditya: can you make an example? As far as I know, there's no legal break point between two consecutive Rel atoms; compare, for example, the Plain TeX definition of \longrightarrow, where three consecutive Rel atoms are used, not enclosed in \mathrel. It would be different if a \mkern were inserted between the two symbols, of course; mathtools actually does this, which was the real cause of the bug.
    – egreg
    Commented Sep 19, 2011 at 8:49
5

Looking at your code for the \defeq command, I noticed an asymmetry w.r.t. the scope of the \mathrel instruction. The following commands avoid this asymmetry in the spacing around the symbols:

\newcommand{\defeq}{\mathrel{:\mkern-0.25mu=}}
\newcommand{\eqdef}{\mathrel{=\mkern-0.25mu:}}

where I've made use of the \mkern ("math-kern") command to tighten up the space (by a very small amount) between the two constituent symbols. The value of the mkern instruction was determined by the eyeball method.

A downside of this approach is that the colon isn't centered vertically relative to the equals sign. This could be fixed by fiddling some more, but I think you're better off using a predefined macro. One actually almost has an embarrassment of riches for the "colon-equals" symbol:

  • packages mathabx, MnSymbol, and mtpro2: \coloneq
  • packages txfonts, pxfonts, and mathtools: \coloneqq
  • package colonequals: \colonequals (what else?!)

Note that the mtpro2 package (short for "MathTime Pro 2") is available in a "lite" version (free) as well as a "professional" (not free) version. The mtpro2 and txfonts will use a Times-Roman font style, and pxfonts will use a Palatino-type font; this may or may not be acceptable to you, depending on what text font you're using. The version from the \mathabx package has the interesting feature that the length of its "equal" symbol is shorter than normal, and the resulting width of its \coloneq command is the same as that of the normal equals sign.

For a predefined version of the reverse symbol, i.e., "equals-colon", you could use the \eqcolon command of the mtpro2 package (may be easiest if you already have that package) or the \equalscolon command of the colonequals package. In addition, you can always rotate your preferred form of the colon-equals symbol by 180 degrees to generate the reverse symbol using, say, the \rotatebox command of the graphicx package. Just remember that you need to tell TeX about the "type" of the new symbol, which should be "mathrel". The following MWE explains how to achieve this effect.

\documentclass{article}
\usepackage{MnSymbol, graphicx}
\newcommand{\eqcolon}{\mathrel{\rotatebox[units=360]{180}{\ensuremath{\coloneq}}}}
\begin{document}
$a \coloneq b$ and $c \eqcolon d$.
\end{document}

Happy TeXing!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .