106

I've seen an equals sign with a small exclamation mark on top being used to say "equals because of data that was given in the problem", for example for a boundary condition or initial value in a differential equation.

A rough picture of what I mean:

     !
f(x) = 4

How do I typeset this in LaTeX? I've tried $=^!$ (which doesn't produce the desired result) and looked through the "relations" section of the Comprehensive List of Symbols without success.

7 Answers 7

123

That's very easy. And there are at least two identical solutions.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}
 \[
   a\stackrel{!}{=} b   % from vanilla LaTeX
 \]

 \[
   a\overset{!}{=} b    % from »amsmath«
 \]
\end{document}

Both give identical output in this case but \overset should be preferred because it takes care of operator spacing.

5
  • 1
    Is there any reason to use the ams solution over the plain TeX version?
    – Seamus
    Dec 17, 2010 at 18:05
  • 16
    »amsmath« is always preferable. Dec 17, 2010 at 22:18
  • 3
    in most cases, it's preferable for some reason! For my part I'm not skeptical that it is better here, but I would be interested to know in what ways it's better :-) Dec 21, 2010 at 6:32
  • 18
    @Peter: when you use amsmath, \stackrel can be considered obsolete as \overset does the same thing better, because it gives correct spacing with binary operators (like +, \oplus, etc.) and ordinary symbols. Jan 20, 2011 at 13:07
  • 2
    @ThorstenDonig: The output is ugly when I want to put a questionmark over equals sign, because "?" is too high above "=". How can I make it appear lower, right above "="?
    – Leo
    Aug 22, 2012 at 7:02
26
\stackrel#1#2

is the command you search.

\stackrel{!}{=}

will lead to the sign you want to typeset. The first argument sits on top of the second argument, where the first one is smaller than the second one.

16

If you needed to customize the separation between the overset, here's a way it could be done. The default is 3pt, halfway between the two examples shown.

\documentclass[11pt]{article}
\usepackage{stackengine}
\begin{document}
\[
 a \mathrel{\stackon[5pt]{$=$}{$\scriptstyle!$}} b
\quad
 a \mathrel{\stackon[1pt]{$=$}{$\scriptstyle!$}} b
\]
\end{document}

enter image description here

14

just to add another one....

\mathop{=}\limits^!
2
  • Also fine! Just the spacing is too tight for a relation symbol, but you could add \mathrel around the expression.
    – Stefan Kottwitz
    Dec 17, 2010 at 18:28
  • This is perfect. A quick explanation of what is going on would be nice though. E.g. what does the limits do?
    – lucidbrot
    Apr 29, 2021 at 7:16
5

Here's an oldie goldie

\documentclass{article}
\begin{document}
\[ a \buildrel!\over= b \]
\end{document}
2

To reduce typing and opportunity for syntax errors, it is better to place a frequently used typesetting algorithm inside a macro. Rather than type

    \[
        a\overset{!}{=} b
    \]

for each equation, one might utilize a macro in the preamble

    \newcommand{\XoverE}{\ensuremath{\overset{!}{=}}}

and use it thusly

    $a\XoverE{}b$

For myself, I use the following macro for an overset question mark:

    \newcommand{\?}{\ensuremath{\overset{?}{-}}}

then

    $a\?{}b$

Edited

1
  • 3
    Try to use it in text mode and you'll have a nasty surprise :-) This works in math mode because of a happy coincidence, since \ensuremath basically becomes \@firstofone. However, in text mode this becomes $relax\overset${!}{=} and goes quite wrong. Either you enclose the whole \overset construction in braces or (IMNSHO better) you eliminate \ensuremath altogether.
    – campa
    Mar 6, 2018 at 16:12
0

Here is how you can define custom commands using special characters for the \stackrel approach.

\catcode`\!=11
\newcommand{\eq!}{\stackrel{?}{=}}
% ...
$f(x) \eq! 4$

It is also nice to define \leq?, \mid? etc.

This solution is significantly better than writing \stackrel{?}{=} and friends frequently.

3
  • 4
    You'll regret doing this when $x/\!y$ will throw you a strange error.
    – egreg
    Oct 9, 2019 at 9:07
  • @egreg Why? Just write $x/!y$
    – okovko
    Oct 9, 2019 at 10:48
  • That's a different thing.
    – egreg
    Oct 9, 2019 at 12:37

You must log in to answer this question.

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