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?
- 2,835
- 5
- 17
- 11
8 Answers
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

- 24,361
-
There are unnecessary braces inside the
\ooalign. I'd use\hidewidthrather than\hfil, but it's not so important, in this case. – egreg Apr 29 '12 at 11:05 -
1Your small symbols are not correct, circles seems to be ellipses ! – Alain Matthes Apr 29 '12 at 12:07
-
@Altermundus Well that's what
\bigcirclooks like at this style. Observe\landalso 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}

- 95,075
-
2Apart 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
\mathchoiceeffects plus the fact thatamsmathexecutes 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 -
1Like egreg writes, the good way is to search inside "The Comprehensive LATEX Symbol List" http://www.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 : http://tex.stackexchange.com/questions/46376/writing-specific-versions-of-an-operator-for-display-and-inline-modes. – Alain Matthes Apr 29 '12 at 10:43
-
1egregs 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
\scriptstyleetc. – 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
-
-
Great you made a version which changes size with math style! Though I think "more efficient" is not the right way to put it. Note that
\mathchoicetypesets all four of its arguments, so now your solution is 200 times slower than mine :-) Furthermore, maybe you should also adapt line width, as the stroke of\landbecomes thinner at smaller styles. Lastly,\mathopmight not be the best choice because it'll look strange in front of parentheses. Comparex \circleland (y\circleland z)withx \land (y\land z). I suggest\mathbin. – Stephan Lehmke Apr 29 '12 at 12:43 -
Way to go! I hope I'm not pestering you with comments, but may I ask what the second argument to
\buildcirclelandis for? It doesn't seem to be used. – Stephan Lehmke Apr 29 '12 at 13:09 -
1Yes you are right
\mathbinis a better option than\mathopand I corrected a bug with the limits. Yes you are also right with\mathchoicethis macro is not very efficient ! – Alain Matthes Apr 29 '12 at 13:09 -
-
@StephanLehmke
mathpaletteis a wrapper tomathchoice\def\mathpalette#1#2{\mathchoice .... It will be interesting, when you test the two methods to load in each code TikZ. – Alain Matthes Apr 29 '12 at 13:24 -
That's clear, as in fact
\mathchoiceis the only way to react to math styles in complex macros.\mathpaletteis only more convenient when all I need is the math style switch. So our solutions are on equal odds now :-) I don't understand the TikZ bit of your comment. Do you mean the loading time of TikZ itself? Thats completely insignificant. A document with 5000 operators takes 0.2s for my solution and 45s for your solution here on my Linux box. Nearly nothing of this is spent on loading TikZ. – Stephan Lehmke Apr 29 '12 at 13:32
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\]
\begin{equation}
x \circleland y
\end{equation}
\end{document}
the result will be:

- 63,575
-
1I suggest using
inner sep/outer sep=0ptand use the command\mathopto get the correct spacing. – Marco Daniel Apr 29 '12 at 08: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}
- 3,848
-
2+1. But note that you can use the
\mathpalettemacro 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 00: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} <\$} \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} >\$} \normalsize
The horizontal spacings are quite finicky. It ended up looking like this (center column):

- 8,888
- 121
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
For me the idea from here was very useful:
\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[draw,circle,thick,blue,text=black] (char) {#1};}}
\begin{document}
\noindent
Text: \circled{=} \newline
Math: $\circled{\textbf{=}}$
\end{document}
The other approaches weren't working for me because I was working in an environment where I couldn't define new macros or import packages. So my solution was to simply overlay \bigcirc and the symbol that I want inside the circle, in this case a <, by using \hspace to shift the inner symbol until it is aligned.
$\bigcirc\hspace{-12pt}<$
The result looks reasonable:
This approach takes a lot of manually fiddling, however, to make different symbols properly centered.
- 402
- 2
- 14




\usepackage{stmaryrd}you can choose between\owedgeand\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 08:45