# Circle and arrow on a single term of a math equation

I want to create an equation with this circle and arrow on a single term by a single command. I want to obtain an equation similar to this:

I need a new command \mathcircled with 2 parameters \mathcircled[0]{f(x)}. "0" is the number that will inserted on top of the arrow, "f(x)" is the term to circle:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
...
}
\makeatother
\begin{document}
$\lim_{x\to\infty} \frac{\sin x}{x}= \mathcircled[0]{\frac{\sin x}{x}}=1$
\end{document}

• Welcome to TeX.SE! Oct 5, 2021 at 13:30
• Is there any chance, that you can help me with my problem. Your answers are really great and work very well. But is it possible to have an arrow going down, when expression is in a denominator? I would like to have something like this: ![enter image description here](i.sstatic.net/w1Db7.jpg) Jul 4, 2023 at 15:22

I propose a solution with pstricks:

\documentclass[svgnames]{article}
\usepackage{amsmath}
\usepackage{pst-node, pst-arrow}

\begin{document}

$\lim_{x\to\infty} \frac{\sin x}{x}= \circlenode[linewidth=0.6pt, linecolor=Tomato, framesep=0pt]{A}{\frac{\sin x}{x}}=1 \uput{32pt}[ur](A){\Rnode{B}{1}} \ncline[linecolor=Tomato, arrowinset=0, arrowscale=1.25, ArrowFill=false]{->}{A}{B}$

\end{document}


• This code give me some error. Oct 5, 2021 at 14:20
• @GerardoSchiavo: pstricks code, traditionally, is compiled with the cycle latex> dvips > pstopdf, because pdflatex cannot make the computations required by Adobe Postscript code. Other method: compile with xelatex --shell-escape. Oct 5, 2021 at 14:44
• Just a curiosity: but the limit is 1 when x \to 0 :-))))) Where the user have seen this "notable" limit? :-)))) Oct 5, 2021 at 22:27
• @Sebastiano: I was also surprised by this formulation, but I thought that the O.P .had written a formula to show explicitly his latex problem, independently of the meaning of the formula. Oct 5, 2021 at 22:39

This seems to be close to what you're looking for. It doesn't look that good in a fraction, but I don't really see how such a construction could really look better in this context.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcommand\mathcircled[3][\displaystyle]{%
\mathord{%
\begin{tikzpicture}[baseline=(X.base)]
\useasboundingbox (0,0) node[circle, inner sep=1.5pt] {\phantom{$$#1#3$$}} -- ++(0,.4) node {};
\node[circle, draw, inner sep=1pt] (X) at (0,0) {$$#1#3$$};
\draw[-{Triangle[open]}] (X.north east) -- ++(.25,.25);
\path (X.north east) ++(.35,.35) node {$$\scriptstyle #2$$};
\end{tikzpicture}%
}%
}
\begin{document}
$\lim_{x\to\infty} \frac{\sin x}{x} = \mathcircled{0}{\frac{\sin x}{x}} = 0 \qquad \lim_{x\to 0} \frac{x \biggl[ 2\mathcircled[\textstyle]{1}{\frac{\sin x}{x}} + 4 \frac{\tan x}{x} \biggr]}{[\cos x + 2 \frac{\sin x}{x}]}$
\end{document}

• if i use this in a fraction it doesn't work well Oct 5, 2021 at 14:22
• @GerardoSchiavo what do you mean exactly by "it doesn't work well"? Oct 5, 2021 at 14:26
• Like this: i.imgur.com/nAFM7fD.png Oct 5, 2021 at 14:40
• @Sebastiano yes, the 2 and the circle were indeed very close. I added a little more space to the bounding box. Oct 5, 2021 at 22:18
• @Sebastiano the limit is 1 when x -> 0, but not when x -> \infty ;-) Oct 5, 2021 at 22:34

Here is a TikZ solution similar to @Vincent's but with somewhat simplified TikZ code and slightly improved horizontal spacing.

The command usage is \mathcircled[<style>]{<limit>}{<circled math>}. The optional argument has default \displaystyle.

$\lim_{x\to\infty} \frac{\sin x}{x}= \mathcircled{0}{\frac{\sin x}{x}}=1$


If your circled math is not in \displaystyle, use the optional argument:

Here is the code:

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

\newcommand\mathcircled[3][\displaystyle]{\tikz[baseline]{
\node[draw,circle,inner sep=0,anchor=base](A){$#1#3$};
\draw[overlay,->](A.north east)--++(.3,.3)node[shift={(.1,.1)}]{$\scriptstyle#2$};
}}

\begin{document}
$\lim_{x\to\infty} \frac{\sin x}{x}= \mathcircled{0}{\frac{\sin x}{x}}=1$

\hspace{2cm}

$\lim_{x\to 0} \frac{x \biggl[ 2\mathcircled[\textstyle]{1}{\frac{\sin x}{x}} + 4 \frac{\tan x}{x} \biggr]}{[\cos x + 2 \frac{\sin x}{x}]}$
\end{document}

• Very nice all (question and answers). Oct 5, 2021 at 21:26