# How do I put a circle around an operator?

For example, I want to put a circle around \land, just like one can put a circle around + by writing \oplus. Is there a general method to do this?

• With \usepackage{stmaryrd} you can choose between \owedge and \varowedge. The former is lighter than the latter. Before building a symbol by hand, try and see if it's already available: see this answer. – egreg Apr 29 '12 at 8:45
• See also tex.stackexchange.com/questions/7032/… for a similar question with numbers instead of an operator. – knut Sep 28 '13 at 19:22

Here's a version combining \land and \bigcirc:

\makeatletter
\newcommand\incircbin
{%
\mathpalette\@incircbin
}
\newcommand\@incircbin[2]
{%
\mathbin%
{%
\ooalign{\hidewidth$#1#2$\hidewidth\crcr$#1\bigcirc$}%
}%
}
\newcommand{\oland}{\incircbin{\land}}
\makeatother


It will change size according to math style:

$a\oland b\frac{a\oland b}{a\oland b^{a\oland b^{a\oland b}}}$


gives

• There are unnecessary braces inside the \ooalign. I'd use \hidewidth rather than \hfil, but it's not so important, in this case. – egreg Apr 29 '12 at 11:05
• Your small symbols are not correct, circles seems to be ellipses ! – Alain Matthes Apr 29 '12 at 12:07
• @Altermundus Well that's what \bigcirc looks like at this style. Observe \land also changes proportion. I believe there is some bigger scheme behind this ;-) – Stephan Lehmke Apr 29 '12 at 12:24

Update

More correct is the next code, I used the code from egreg here

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

\newcommand{\circleland}{
\mathbin{
\mathchoice
{\buildcircleland{\displaystyle}}
{\buildcircleland{\textstyle}}
{\buildcircleland{\scriptstyle}}
{\buildcircleland{\scriptscriptstyle}}
}
}

\newcommand\buildcircleland[1]{%
\begin{tikzpicture}[baseline=(X.base), inner sep=0, outer sep=0]
\node[draw,circle] (X)  {$#1\land$};
\end{tikzpicture}%
}

\begin{document}

$a\circleland b\frac{a\circleland b}{a\circleland b^{a\circleland b^{a\circleland b}}}$

$x \circleland (y\circleland z)$ and  $x \land (y\land z)$
\end{document}


• Apart from the abstract question "is this possible", is it really a good idea to make a math operator based on TikZ? As it's a basic logical operator, an average thesis or monograph in the field will contain several thousand instances of these. Add to that \mathchoice effects plus the fact that amsmath executes everything in an aligned environment twice, wouldn't this mean a lot of running time? Do you have experience with defining math operators with TikZ? Shouldn't this at least be solved with some caching in boxes? – Stephan Lehmke Apr 29 '12 at 10:24
• Like egreg writes, the good way is to search inside "The Comprehensive LATEX Symbol List" ctan.org/tex-archive/info/symbols/comprehensive. Now for the running time, I don't know. It will be interesting to test. For the math operator with tikz, you can give a look at the excellent answer from egreg : tex.stackexchange.com/questions/46376/…. – Alain Matthes Apr 29 '12 at 10:43
• egregs suggestion is applicable only if the symbol does indeed already exist. I'm interpreting the answers here as general advice on how to make a circled math operator. I just tested your symbol, and another issue is that it doesn't change size in \scriptstyle etc. – Stephan Lehmke Apr 29 '12 at 10:56
• I just made a small test with about 5000 symbols in one doc, and my version runs about 40 times faster than yours ;-) – Stephan Lehmke Apr 29 '12 at 11:38
• Yes you are right \mathbin is a better option than \mathop and I corrected a bug with the limits. Yes you are also right with \mathchoice this macro is not very efficient ! – Alain Matthes Apr 29 '12 at 13:09

You can use pgf for this purpose by defining a new command:

\newcommand{\circleland}{
\tikz{
\pgfsetbaselinepointlater{\pgfpointanchor{X}{base}}
\pgfcircle{\pgfpointorigin}{0.15cm}
\pgfusepath{stroke}
\node (X) {$\land$};
}}


Look at this MWE:

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

\newcommand{\circleland}{
\tikz{
\pgfsetbaselinepointlater{\pgfpointanchor{X}{base}}
\pgfcircle{\pgfpointorigin}{0.15cm}
\pgfusepath{stroke}
\node (X) {$\land$};
}}
\begin{document}
$x \land y$

$$x \circleland y$$

\end{document}


the result will be:

• I suggest using inner sep/outer sep=0pt and use the command \mathop to get the correct spacing. – Marco Daniel Apr 29 '12 at 8:55

I am giving the general answer to the question (valid for any operator and even text) by slightly modifying Alain's code.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{wasysym}
\usepackage{tikz}

%The given symbol or text (\text{mytext}) in a circle
%To be used always in math mode
\newcommand{\circlesign}[1]{
\mathbin{
\mathchoice
{\buildcirclesign{\displaystyle}{#1}}
{\buildcirclesign{\textstyle}{#1}}
{\buildcirclesign{\scriptstyle}{#1}}
{\buildcirclesign{\scriptscriptstyle}{#1}}
}
}

\newcommand\buildcirclesign[2]{%
\begin{tikzpicture}[baseline=(X.base), inner sep=0, outer sep=0]
\node[draw,circle] (X)  {\ensuremath{#1 #2}};
\end{tikzpicture}%
}

\begin{document}

$\circlesign{+} \neq \oplus$,  $\circlesign{\bullet} \neq \odot$ \\
Put whatever you want inside the circle $\circlesign{\davidsstar}$

$\circlesign{\text{whatever!}}$

\end{document}

• +1. But note that you can use the \mathpalette macro here, specifically designed for this kind of tasks. More specifically, I’d say \DeclareRobustCommand*{\circlesign}[1]{\mathbin{\mathpalette{\buildcirclesign}{#1}}}. – GuM Mar 18 '17 at 0:06

I spent some time trying to get the <,<=,=,>= and > operators circled nicely. Code ended up a bit hacky, even though it worked:

<

\Large \textcircled{\normalsize \$\hspace{0.05 mm} &lt;\$} \normalsize


<=

\Large \textcircled{\raisebox{1pt} {\normalsize \$\hspace{0.05 mm} \leq\$}} \normalsize


=

\Large \textcircled{\raisebox{1pt} {\normalsize \$\hspace{0.05 mm} =\$}} \normalsize


>=

\Large \textcircled{\raisebox{1pt} {\normalsize \$\hspace{0.1 mm} \geq\$}} \normalsize


>

\Large \textcircled{\normalsize \$\hspace{0.1 mm} &gt;\$} \normalsize


The horizontal spacings are quite finicky. It ended up looking like this (center column):

Thanks for the great answers! However, Stephan's original code produced an error in my project ("Illegal parameter number in definition of \reserved@a"). I did not figure out what exactly the problem was. I solved it by adding some \protects, which seems to be a bit more robust. Here is my version of the MWE:

\documentclass{article}
\usepackage{amssymb,amsmath}

\newcommand{\incircbin}[1]{%
\mathbin{%
\mathchoice%
{\protect\incircint{\displaystyle}{#1}}%
{\protect\incircint{\textstyle}{#1}}%
{\protect\incircint{\scriptstyle}{#1}}%
{\protect\incircint{\scriptscriptstyle}{#1}}%
}%
}
\newcommand{\incircint}[2]{%
\ooalign{$#1\bigcirc$\crcr\hidewidth$#1#2$\hidewidth\crcr}%
}
\newcommand{\circleland}{\incircbin{\land}}

\begin{document}

$a\circleland b\frac{a\circleland b}{a\circleland b^{a\circleland b^{a\circleland b}}}$

\end{document}


Matthias