# Correctly scale and space TikZ symbol in math mode

I wish to define a mathematical symbol, similar to \odot, using TikZ. The symbol should thus scale appropriately in accordance with its context (e.g. inline math, footnotes, diagrams, etc.). As a template, I followed this related question. However, it doesn't appear to be scaling correctly in all contexts. Furthermore, the spacing around the symbol is subtly wrong.

Here is a minimal working example:

\documentclass{article}

\usepackage{mathtools}
\usepackage{tikz-cd}

\newlength{\oh}

\newcommand{\ostar}{\mathbin{\vcenter{\hbox{\text{\settoheight{\oh}{$\odot$}\tikz[baseline=.45\oh]{\draw[line width=.06\oh](0,0)circle[radius=.57\oh]node[overlay,yshift=-.025\oh]{\ensuremath{*}};}}}}}}

\begin{document}

\begin{align*}
f \odot g \\
f \ostar g \\
x^{f \odot g} \\
x^{f \ostar g} \\
\end{align*}
\vspace{-7ex}
$\begin{tikzcd}[column sep=large,row sep=tiny] \cdot & \cdot \\ \cdot & \cdot \\ \arrow["{f \odot g}"{description}, from=1-1, to=1-2] \arrow["{f \ostar g}"{description}, from=2-1, to=2-2] \end{tikzcd}$

\end{document}


which produces:

As seen in the image, the size of \ostar is correct for normal size math and in the commutative diagram. However, it is too large in the superscript (with respect to \odot), even though it should be scaled proportionally to \odot (since all the dimensions are with respect to \oh). Furthermore, though it is a little hard to see in the image, there is less spacing around \ostar than around \odot in every place it is used.

I suspect there's a simple solution, but I haven't been able to figure it out. How can I fix the definition of \ostar so that it behaves the same as \odot?

(Note that I actually want to define more complicated symbols than \ostar using the same method, so alternative solutions like this one do not suffice for my purposes.)

• You should use \text{$\vcenter{...}$} in order to fix the size. But this won't work in tikzcd, because you're nesting tikzpicture inside tikzpicture. Commented May 17, 2023 at 10:52
• @egreg: that's already a significant improvement, thank you. The spacing appears not to be perfect in tikzcd, but it is perhaps close enough to be acceptable. Commented May 17, 2023 at 12:05

You can put the symbol in a savebox and use the scalerel package to give it the same size as \odot. Changing the inner sep of the node will make the * larger or smaller.

\documentclass{article}

\usepackage{scalerel}
\usepackage{mathtools}
\usepackage{tikz-cd}

\newsavebox{\circstar}
\sbox{\circstar}{\kern.075em\tikz{\node[draw, circle, line width=.36pt, inner sep=.5pt]{$*$};}\kern.075em}

\newcommand{\ostar}{\mathbin{\scalerel*{\usebox{\circstar}}{\odot}}}

\begin{document}

\begin{align*}
f \odot g \\
f \ostar g \\
x^{f \odot g} \\
x^{f \ostar g} \\
\end{align*}
\vspace{-7ex}
$\begin{tikzcd}[column sep=large,row sep=tiny] \cdot & \cdot \\ \cdot & \cdot \\ \arrow["{f \odot g}"{description}, from=1-1, to=1-2] \arrow["{f \ostar g}"{description}, from=2-1, to=2-2] \end{tikzcd}$

\end{document}

• Thanks, this is a cleaner solution. Commented May 17, 2023 at 16:26