[Tex/LaTex] New Symbols in Latex

macrostikz-pgf

I want to define the following commands directly in latex.

  • \cross{a}{b} which should create a black square, with a grey
    cross inside it and the symbols $a$ and $b$ arranged along the
    diagonal. Obs: the letters a and b are passed as arguments. I'm only
    intersted in the case in which the arguments are single lowercase letters.

  • \crossdot{a}{b} which is similar to \cross{a}{b}, except that
    a grey circle should be added to the middle of the cross.

Both new symbols should be used in the text, and therefore I
would like them to have approximately the size of a capital $G$.
A little bit larger would be ok. A picture illustrating what I want
is given below.

How do I create commands for such symbols in latex?

\cross{a}{b}, \crossdot{a}{b}, and letter $G$

Best Answer

Stack and scale.

\documentclass{article}
\usepackage{xcolor,stackengine,scalerel}
\newcommand\graybox[1][]{\color{gray}%
  \fbox{\makebox[\dimexpr\ht\strutbox+\dp\strutbox\relax]{\textcolor{black}{$#1$}\strut}}}
\newcommand\crossbox[2]{\hbox{\fboxsep=-\fboxrule\relax\fbox{%
  \fboxrule=.5\fboxrule\relax\stackon[0pt]{\graybox\graybox[#2]}{\graybox[#1]\graybox}}}}
\newcommand\cross[2]{\kern1pt\scalerel*{\crossbox{#1}{#2}}{G}\kern1pt}
\newcommand\crossdot[2]{\stackinset{c}{}{c}{-.31pt}{\textcolor{gray}{$\cdot$}}%
  {\cross{#1}{#2}}}
\begin{document}
$\cross{g}{d} \crossdot{a}{b} G$
\end{document}

enter image description here

In this version, the \fboxsep inside the \crossbox has been reduced to grow the size of the inset letters slightly.

\documentclass{article}
\usepackage{xcolor,stackengine,scalerel}
\newcommand\graybox[1][]{\color{gray}%
  \fbox{\makebox[\dimexpr\ht\strutbox+\dp\strutbox\relax]{\textcolor{black}{$#1$}\strut}}}
\newcommand\crossbox[2]{\hbox{\fboxsep=-\fboxrule\relax\fbox{\fboxsep=-1pt\relax%
  \fboxrule=.5\fboxrule\relax\stackon[0pt]{\graybox\graybox[#2]}{\graybox[#1]\graybox}}}}
\newcommand\cross[2]{\kern1pt\scalerel*{\crossbox{#1}{#2}}{G}\kern1pt}
\newcommand\crossdot[2]{\stackinset{c}{}{c}{-.31pt}{\textcolor{gray}{$\cdot$}}%
  {\cross{#1}{#2}}}
\begin{document}
$\cross{g}{d} \crossdot{a}{b} G$
\end{document}

enter image description here

Related Question