[Tex/LaTex] Extendible \cong congruence sign

amsmathsymbols

This question is very similar to Extendible equals sign but the solutions given there do not apply immediately.

At times I woud like to clarify the nature of a mathematical congruence. So I have defined in my preamble

\newcommand*\morph[1]{\underset{\mbox{\tiny #1}}{\cong}}

So I can write things like \morph{diff} and \morph{hom} to differentiate between different congruences. But even with the \mbox content set to \tiny, the text is still wider than the congruence sign. Any ideas?

Best Answer

One could always use \resizebox to stretch the symbol.

\documentclass{article}
\usepackage{amsmath,graphicx}
\makeatletter
\newcommand*\morph[1]{%
    \setbox0=\hbox{\scriptsize#1}%
    \setbox2=\hbox{$\m@th{\cong}$}%
    \stackrel{\copy0}{%
        \ifdim\wd2<\wd0
            \resizebox{\wd0}{\ht2}{$\m@th{\cong}$}%
        \else
            \cong
        \fi
    }%
}
\begin{document}
\[X\morph{long text}Y\morph{i}Z\]
\end{document}
Related Question