# How to encircle a character inside a Latex formula?

Slight improvement of ThV's answer, in order to preserve the proper math style.

\documentclass{article}

\usepackage{tikz}

\makeatletter
\newcommand*{\encircled}[1]{\relax\ifmmode\mathpalette\@[email protected]{#1}\else\@encircled{#1}\fi}
$f_{\encircled{n}} = \encircled{f_n}$

\end{document}


For convenience, I've added code to automatically switch to math mode if needed. This is based on question 3.