4

I want to define a simple shape and use it as a binary math operator. This implies that it should scale when used as a subscript (e.g., the same behavior as \bigcirc). My attempts so far led me here:

\documentclass{article}

\usepackage{tikz,amsmath}

\DeclareRobustCommand{\myop}{%
  \mathbin{\text{\tikz \node[circle,draw=black,scale=0.4] () {$r$};}}}

\begin{document}
$A \bigcirc B$ $_{A \bigcirc B}$

$A \myop B$ $_{A \myop B}$
\end{document}

Tikz circ

As one can see, the TikZ variant doesn't behave well: in the first case, the shape is smaller than the operands, while it is pretty much of the same height in the second one. Removing the scale, adding some minimum size=0mm,inner sep=0mm, etc. did not change anything to the problem. Hence:

Question: How can I obtain a smooth scaling of the operator?

4
  • Does this help? tex.stackexchange.com/q/160764/4778
    – Alenanno
    Feb 2, 2016 at 17:20
  • \text is basically doing the mathchoice here. I'm really searching for an option that keeps the tikz (because I may have something more complex) and that avoids a mathchoice. In a way, I'd like to be able to say "Let $x$ be the height of an "o" in the current mode, then scale the tikz picture to $x$."
    – Michaël
    Feb 2, 2016 at 17:24
  • comment to @JohnKormylo's comment: one needs to take care of timing of evaluation.
    – Symbol 1
    Feb 3, 2016 at 5:39
  • @JohnKormylo: As Symbol says, it's not that easy, and \text goes a long way to make it easier. However, experiment with \DeclareRobustCommand{\myop}{\mathbin{\text{\rule{1mm}{.7em}}}} or similar, and you'll see that it does not scale properly. What I'd really like to have, again, is something like "Put 'A' in a vbox, and scale the symbol to the height of that vbox." I just can't seem to be able to do that, because of evaluation timing.
    – Michaël
    Feb 3, 2016 at 11:33

1 Answer 1

5

The problem is that the inner sep and line width do not change with the font. The solution is to define a length that does change proportionately with the font. I chose the height of \mathstrut, but almost anything will do. Also, by drawing the circle separately, you can adjust its size and the size of the contents ($r$) separately.

\documentclass{article}

\newlength{\tempdima}

\usepackage{tikz,amsmath}

\DeclareRobustCommand{\myop}{%
  \mathbin{\text{\settoheight{\tempdima}{\mathstrut}\raisebox{-.3\tempdima}{%
    \tikz{\draw[line width=0.05\tempdima] circle (0.6\tempdima);
    \node[scale=0.8] {$r$};}}}}}

\begin{document}
$A \bigcirc B$ $_{A \bigcirc B}$

$A \myop B$ $_{A \myop B}$
\end{document}
1
  • Ah! That's perfect! We arrived at a similar solution at the same time—but I had to search for hours :-) I used a resizebox to avoid having \tempdima everywhere, but I'm not sure one is better than the other. Thanks greatly!
    – Michaël
    Feb 3, 2016 at 17:04

You must log in to answer this question.

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