27

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
  • 9
    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
    Commented Apr 29, 2012 at 8:45
  • 1
    See also tex.stackexchange.com/questions/7032/… for a similar question with numbers instead of an operator.
    – knut
    Commented Sep 28, 2013 at 19:22

8 Answers 8

24

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

oland example

3
  • There are unnecessary braces inside the \ooalign. I'd use \hidewidth rather than \hfil, but it's not so important, in this case.
    – egreg
    Commented Apr 29, 2012 at 11:05
  • 1
    Your small symbols are not correct, circles seems to be ellipses ! Commented Apr 29, 2012 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 ;-) Commented Apr 29, 2012 at 12:24
17

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} 

enter image description here

11
  • 2
    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? Commented Apr 29, 2012 at 10:24
  • 1
    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/…. Commented Apr 29, 2012 at 10:43
  • 1
    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. Commented Apr 29, 2012 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 ;-) Commented Apr 29, 2012 at 11:38
  • 1
    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 ! Commented Apr 29, 2012 at 13:09
8

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:

enter image description here

1
  • 1
    I suggest using inner sep/outer sep=0pt and use the command \mathop to get the correct spacing. Commented Apr 29, 2012 at 8:55
6

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

enter image description here

\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
  • 2
    +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
    Commented Mar 18, 2017 at 0:06
2

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):

Big O table

1

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} 

Rendering of MWE

Matthias

1

For me the idea from here was very useful:

enter image description here

\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}
0

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:

enter image description here

This approach takes a lot of manually fiddling, however, to make different symbols properly centered.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .