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?

Snowball
  • 2,835
  • 5
  • 17
  • 11
  • 8
    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 08:45
  • 1
    See also http://tex.stackexchange.com/questions/7032/good-way-to-make-textcircled-numbers for a similar question with numbers instead of an operator. – knut Sep 28 '13 at 19:22

8 Answers8

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

  • 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
  • 1
    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
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

Alain Matthes
  • 95,075
  • 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? – Stephan Lehmke Apr 29 '12 at 10:24
  • 1
    Like 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
  • 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. – 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 I think it's possible and normal that your code is faster. – Alain Matthes Apr 29 '12 at 12:17
  • 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 \mathchoice typesets 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 \land becomes thinner at smaller styles. Lastly, \mathop might not be the best choice because it'll look strange in front of parentheses. Compare x \circleland (y\circleland z) with x \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 \buildcircleland is for? It doesn't seem to be used. – Stephan Lehmke Apr 29 '12 at 13:09
  • 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 ! – Alain Matthes Apr 29 '12 at 13:09
  • @StephanLehmke Nothing I forgot to modify egreg's macro ! – Alain Matthes Apr 29 '12 at 13:11
  • @StephanLehmke mathpalette is a wrapper to mathchoice \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 \mathchoice is the only way to react to math styles in complex macros. \mathpalette is 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
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

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}
  • 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 Mar 18 '17 at 00: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

Ludovic C.
  • 8,888
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.

Paul Wintz
  • 402
  • 2
  • 14