TikZ PGF – Customize Circled Numbers

tikz-pgf

Below is one solution (by @Stefan) for circled numbers with the help of tikz. What can I do to make it such that I can in-place customize its draw color, fill color, text color, etc.?

\documentclass[tikz,border=7pt]{standalone}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\begin{document}
    \circled{1}
\end{document}

enter image description here

Best Answer

I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
\begin{document}
abc \tikzmarknode[mycircled,draw=red]{t1}{d} 
{\Huge \tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
\[
\int\limits_{\tikzmarknode[mycircled,red]{a1}{a}}^{\tikzmarknode[mycircled,blue]{b1}{b}}
 f(x)\,\mathrm{d}x=F(\tikzmarknode[mycircled,red]{a2}{a})-
 F(\tikzmarknode[mycircled,blue]{b2}{b})
\]
\begin{tikzpicture}[overlay,remember picture]
 \draw[latex-latex,red] (a1) to[bend right] (a2);
 \draw[latex-latex,blue] (b1) to[bend left] (b2);
\end{tikzpicture}
\end{document}

enter image description here