44

I have defined the equal by definition sign:

enter image description here

with this code: \newcommand{\eqdef}{\overset{def}{=}}.

However, "def" extends over the edges of the equal sign. Is there a wider equal sign to use?

Charles Stewart
  • 21,014
  • 5
  • 65
  • 121
Zack
  • 543

6 Answers6

70

Just put two equals signs, backing up slightly:

\newcommand{\eqdef}{\overset{\mathrm{def}}{=\joinrel=}}

This is how TeX builds extensible arrows.

enter image description here

The magic macro \joinrel is defined as

\mathrel{\mkern-3mu}

and the magic is done by the fact that TeX doesn't put spaces between consecutive relation symbols:

=\mathrel{\mkern-3mu}=

will thus result in two equals signs slightly superimposed to each other.

egreg
  • 1,121,712
39

The extarrows package provides \xlongequal{<stuff>}:

enter image description here

\documentclass{article}
\usepackage{extarrows}% http://ctan.org/pkg/extarrows
\newcommand{\eqdef}{\xlongequal{\text{def}}}%
\begin{document}
\[ f(x) \eqdef g(x) = ax^2+bx+c \]
\end{document}

extarrows requires amsmath (so it is loaded by default). As such, I've used \text which scales to the appropriate text font in the given math size.

If you want the boundary of the overset def to be tighter, use

\newcommand{\eqdef}{\xlongequal{\!\text{def}\!}}%

which removes some space around def.

Werner
  • 603,163
24

If you want the size to math exactly, you can use \resizebox from the graphicx package and scale the width to the desired size (width of the unscaled version), and leave the height to be the same as the height of the = sign. Here is a comparison of the regular, and re sized versions:

enter image description here

Note that the manual tweak of \kern1.25pt may need to be adjusted based on the font being used.

\documentclass{article}
\usepackage{amsmath}% 
\usepackage{graphicx}% needed for \resizebox
\usepackage{calc}%     needed for the width/height calculations

\newcommand{\MyDef}{\mathrm{def}} \newcommand{\MyEqdefU}{\ensuremath{\mathrel{\overset{\MyDef}{=}}}}% Unscaled version \newcommand*{\MyEqdef}{\mathrel{\overset{\MyDef}{\resizebox{\widthof{\kern1.25pt\MyEqdefU}}{\heightof{$=$}}{$=$}}}}

\begin{document} \begin{alignat}{2} f(x) &\MyEqdefU g(x) = h(x) \quad\text{Unscaled}\ f(x) &\MyEqdef g(x) = h(x) \quad\text{Scaled} \end{alignat} \end{document}

Peter Grill
  • 223,288
  • a simply \height instead of \heightof{=} should also work, because you can take the natural height. –  Nov 20 '11 at 06:35
  • In the second version "def" slightly extends to the left beyond the equality symbol, at least in your output. Is it possible to improve? –  Feb 09 '23 at 20:04
  • @AlbertNash: I think that slight difference is due to how the font is designed. If you apply a slight \kern as \newcommand*{\eqdef}{\mathop{\overset{\MyDef}{\resizebox{\widthof{\kern1.25pt\eqdefU}} then you should get better alignment (at least with the default font). Here is the result of that. – Peter Grill Feb 09 '23 at 21:42
  • @AlbertNash: If the code does not compile for you there is probably some issue with your pacakges as I just ran it now to produce the linked result with TeXLive 2022. If you are not able to resolve the issue, I suggest you post a new question and include the list pf packages with version numbers are produced by \listfiles (just before \begin{document}). – Peter Grill Feb 09 '23 at 21:43
  • @PeterGrill it doesn't compile for me, it works fine with article.cls. – Ulrike Fischer Feb 09 '23 at 21:48
  • @user2478 replacing \heightof{=} by \height doesn't work in inline todonotes. –  Feb 09 '23 at 23:02
  • @UlrikeFischer: Thanks. I think I had an older standalone that was allowing to compile. Have now switched it to article class. – Peter Grill Feb 10 '23 at 03:37
  • 1
    @AlbertNash: Have incorportaed the tweak mentioned in the comments to get a better match of the width and renamed the macros so as to not conflict with unicode-math. – Peter Grill Feb 10 '23 at 03:38
  • 1
    @AlbertNash: Good point. Now using \mathrel. – Peter Grill Feb 10 '23 at 19:14
14

It doesn't strictly answer the question but if you only want the "def" to be about the same size as the equal sign you could also resize the text, i.e.

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{mathtools}

\def\Tiny{\fontsize{4pt}{4pt}\selectfont}
\newcommand*{\eqdef}{\ensuremath{\overset{\mathclap{\text{\Tiny def}}}{=}}}

\begin{document}

\begin{align} 
 A &\eqdef B \\
 &= C
\end{align}

\end{document}

This way it looks better (in my opinion) when used together with normal equal signs. enter image description here

David Carlisle
  • 757,742
Philipp
  • 3,815
  • Can you choose font sizes below 5pt? When I run your example, I get the warning Font shapeOT1/cmr/m/n' in size <4> not available ... size <5> substituted`. – Mico Nov 20 '11 at 00:26
  • @Mico: I don't really know. I chose the font size more or less randomly. But I guess your right and one really can't go below 5pt (at least not by default) as nothing changed when I tried smaller font sizes. – Philipp Nov 20 '11 at 22:09
3

Just the plain horizontal extension of the equation mark is possible with the graphicx package:

\usepackage{graphicx}
 ...
{\scalebox{3}[1]{=}}

You can also define a command for this and use it lateron

\newcommand{\longeq}{\scalebox{3}[1]{=}}

like this:

\longeq
OlliKru
  • 31
  • 1
    Will this provide the correct spacing around the relation? Perhaps wrap it with \mathrel. How would you replicate the output requested by the OP? – Werner Dec 15 '16 at 19:13
3

Here is one adaptation of the Philipp's proposition so as to take care of the different math modes.

% Source : http://tex.stackexchange.com/questions/35404/is-there-a-wider-equal-sign

\documentclass{scrartcl}
    \usepackage{amsmath}
    \usepackage{mathtools}

    \usepackage{graphicx}

    \makeatletter
        \newcommand{\@@eqDef}[1]{%
            \ensuremath{\overset{\mathclap{\text{\scalebox{#1}{def}}}}{=}}%
        }
        \newcommand*{\eqDef}{
            \mathchoice
                {% \displaystyle
                    \@@eqDef{0.7}
                }
                {% \textstyle
                    \@@eqDef{0.7}
                }
                {% \scriptstyle
                    \@@eqDef{0.6}
                }
                {% \scriptscriptstyle
                    \@@eqDef{0.5}
                }
        }
    \makeatother

\begin{document}

\begin{align}
    A &\eqDef B \\
    A &= C
\end{align}

\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{llll} 
        \textbf{Style}            & \verb!\eqDef!
        \\ \hline
        \verb!\displaystyle!      & \displaystyle      A \eqDef B
        \\
        \verb!\textstyle!         & \textstyle         A \eqDef B
        \\
        \verb!\scriptstyle!       & \scriptstyle       A \eqDef B
        \\
        \verb!\scriptscriptstyle! & \scriptscriptstyle A \eqDef B
    \end{array}
\]

\end{document}
David Carlisle
  • 757,742
projetmbc
  • 13,315