[Tex/LaTex] Creating a symbol that combines a number with a triangle for math-mode

math-modesymbols

I'm trying to create a new symbol that simply combines a number with a triangle, by placing the number inside the triangle. It should work in math-mode (text mode would be nice, but not required).

I've tried the following:

\documentclass{article}
\usepackage{graphicx}


\newcommand{\trinum}[1]{%
\triangle\hspace{-.57em}\raisebox{0.1em}{\scalebox{.5}{#1}}
}

\begin{document}

Works fine in default environment
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]

Slightly shifted when used in Huge environment:
{\Huge
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}

Slightly shifted when used in tiny environment:
{\tiny % I know, it's too small to read, but just used as a check
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}

Messed up when used as subscript or super script    
\[
\trinum{1} \qquad x_\trinum{1} \qquad x^\trinum{1}
\]

\end{document}

result
As you can see, it doesn't work nicely for scaled text and very badly for superscript and subscript. I was wondering if there is a better way of doing this.

Best Answer

Magic of \ooalign:

\documentclass{article}
\usepackage{graphicx}

\newcommand{\trinum}[1]{\mathpalette\dotrinum{#1}}
\newcommand{\dotrinum}[2]{{%
  \vphantom{\triangle}%
  \ooalign{%
    $#1\triangle$\cr\hidewidth\scaleraise{$#1#2$}\hidewidth\cr
  }%
}}
\newcommand{\scaleraise}[1]{%
  \raisebox{.2\height}{\scalebox{0.5}{#1}}%
}

\begin{document}

Works fine in default environment
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]

Slightly shifted when used in Huge environment:
{\Huge
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}

Slightly shifted when used in tiny environment:
{\tiny % I know, it's too small to read, but just used as a check
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}

Messed up when used as subscript or super script    
\[
\trinum{1} \qquad x_{\trinum{1}} \qquad x^{\trinum{1}}
\]

\end{document}

I left your original text, except for bracing the subscript and superscript. See https://tex.stackexchange.com/a/22375/4427 for details on \ooalign

enter image description here