40

Is it possible to overlay a symbol with another?

I want to write an equal sign with a question mark overlayed (or the other way around).

Note I don't want

\stackrel{?}{=}

I want the question mark to be right on top, to cross over the equal sign (which creates kind of a new sign).

Is this possible? How? Or is there a one character sign for this?

azetina
  • 28,884
masterxilo
  • 563
  • 1
  • 5
  • 7
  • Can you try this? \DeclareMathOperator{\maybe}{\stackrel{?}{=}} – Chuang Mar 07 '11 at 20:17
  • There must be a better way, but \DeclareMathOperator{\overlay}{?\hspace{-9pt}=} seems to work. With this version you'll have to adjust the spacing depending on the size of the font and the characters being overlaid. – John Palmieri Mar 07 '11 at 20:39
  • @masterxilo: Thanks for accepting my answer. However in the meantime better answers appeared and one of it should be accepted to indicate the preferred solution to other users with the same issue. – Martin Scharrer Jul 19 '11 at 10:25

3 Answers3

39

You can overlay the symbols the following way: Box the wider one and let the other one lap over it (using \rlap or \llap). The correct centering is achieved by placing the second character into a box with the equal width but using \hss to center it. The correct size for the different math modes can be adjusted using \mathchoice.

\documentclass{article}
\def\qeq{\mathrel{%
    \mathchoice{\QEQ}{\QEQ}{\scriptsize\QEQ}{\tiny\QEQ}%
}}
\def\QEQ{{%
    \setbox0\hbox{=}%
    \rlap{\hbox to \wd0{\hss?\hss}}\box0
}}

\textwidth=2cm
\begin{document}

$ A \qeq B $

$ A = B $

\[ A \qeq B \]
\[ A = B \]

$ S_{ A \qeq B } $

$ S_{ A = B } $

$ S_{S_{ A \qeq B }} $

$ S_{S_{ A = B }} $

\end{document}

Result

Result

Martin Scharrer
  • 262,582
  • 4
    For centering there's \mathclap if you're willing to load mathtools. – Hendrik Vogt Mar 07 '11 at 21:10
  • Thanks @Hendrik, mathtools seems to be the way to go. I didn't know it before. As an engineer I'm not doing this much math with LaTeX... – Martin Scharrer Mar 07 '11 at 21:12
  • Thanks a lot for this, exactly what I was looking for! However, this seems pretty complex for something I'd expect LaTeX to have built-in support for. Doesn't anyone ever use this sign? I use it all the time to start proofs... – masterxilo Mar 07 '11 at 22:28
  • @masterxilo: I've never seen it before. I don't believe it's a common symbol in math or computer science. Maybe it is unique to your field. – TH. Mar 10 '11 at 09:04
  • It didn't work for math mode symbols: tried with \cdot and \Diamond and got a missing $ error. – Caleb Stanford Jul 01 '18 at 06:30
32

You could also use the Plain macro \ooalign:

$\mathrel{\ooalign{\hss?\hss\cr=}}$\bye
morbusg
  • 25,490
  • 4
  • 81
  • 162
11

The just submitted stackengine package is tailor made for combining glyphs. Since it was just submitted to CTAN, it will hopefully propagate this weekend.

\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx}
\parskip 1ex\parindent 0in
\begin{document}
%Arguments to inset commands{overlay image}{base image}{V-offset}{H-offset}
Relative to bottom vs. top:\\
\bottominset{*}{O}{}{}%
\topinset{*}{O}{}{}%

With V and H shifting:\\
\topinset{*}{O}{}{}%
\topinset{*}{O}{1pt}{}%
\def\stackalignment{r}%
\topinset{*}{O}{2pt}{-1pt}%

Glyphs of different scales:\\
\def\stackalignment{c}%
\def\newi{\stackon[-.4ex]{i}{\scalebox{3}{.}}}
\def\useanchorwidth{T}
Th\newi s uses width of anchor alone

\def\useanchorwidth{F}
Th\newi s uses width of complete stack
\end{document}

enter image description here

David Carlisle
  • 757,742
  • 1
    Later revisions of stackengine deprecate \topinset and \bottominset, and replace them both with \stackinset. It gives more alignment options and has a syntax more suited for nesting. – Steven B. Segletes Feb 04 '14 at 22:45