[Tex/LaTex] How to put a symbol inside a circle arrow

stacking-symbolssymbols

I'm trying to draw a clockwise circle arrow with a symbol inside. My current solution requires manual alignment of the content, and as such doesn't look very good.

\makebox[0pt][l]{\huge$\circlearrowright$}\ $i_3$ }

circle arrow with content

Is there a solution which doesn't require manual correction? If not, is there a method to have more fine-grained control over the horizontal alignment, and any control at all over the vertical?

Best Answer

Here is slightly automated solution using tikz. I measure the height and width of the text and place an arc whose size is based on the maximum of that. Am sure this can be improved, but this should get you started:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{calc}

\makeatletter
\newlength\@SizeOfCirc%
\newcommand{\CricArrowRight}[1]{%
    \setlength{\@SizeOfCirc}{\maxof{\widthof{#1}}{\heightof{#1}}}%
    \tikz [x=1.0ex,y=1.0ex,line width=.15ex, draw=blue]%
        \draw [->,anchor=center]%
            node (0,0) {#1}%
            (0,1.2\@SizeOfCirc) arc (85:-240:1.2\@SizeOfCirc);%
}%
\makeatother

\begin{document}
\CricArrowRight{$i$}
\CricArrowRight{$i_3$}
\CricArrowRight{$\frac{a}{b}$}
\CricArrowRight{$\dfrac{a}{b}$}
\end{document}

I created a temporary length \@SizeOfCirc so as to minimize potential name conflicts, and need to use \maktatother. See What do \makeatletter and \makeatother do? for more info if you are not familiar with that.