4

How can I properly design a symbol, such as \oiint with Tikz?

I've found something like this on the internet

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

[ \oint\iint {\tikz \node[draw, ellipse, inner xsep=-3.6pt, inner ysep=-9pt] {$\displaystyle\iint$};} ]

\end{document}

Which outpouts

enter image description here

and has a vertical misalignment and doesn't work with subscripts. How can I fix this? Also, how can i change the ellipse's thinkness?

Nolord
  • 111

2 Answers2

10

The solution without usage of TikZ can be:

\def\circle{.5 0 m .5 .276 .276 .5 0 .5 c -.276 .5 -.5 .276 -.5 0 c
                  -.5 -.276 -.276 -.5 0 -.5 c .276 -.5 .5 -.276 .5 0 c }
\protected\def\oiint{%
  \mathop{\vcenter{
     \pdfliteral{q 10 0 0 6 7 0 cm .06 w \circle S Q}
       }}\!\iint
}

test: $$ \oint, \iint_X, \oiint_X $$

The \pdfliteral is pdfTeX primitive. You can define \def\pdfliteral#1{\special{pdf:literal #1}} in XeTeX or \def\pdfliteral{\pdfextension literal} in LuaTeX.

wipet
  • 74,238
  • I have no idea what that does, but that does the job lol. Could you at least explain how to change the dimensions of the ellipse? So i can do the same with \oiiint. – Nolord May 24 '23 at 19:36
  • 1
    @Nolord the width of the ellipse is 10, the height is 6 and the shift is 7 bp. If you want to draw an ellipse over \iiint, try 15 0 0 6 9 0 cm. The cm PDF operator sets the current matrix of linear transformation. – wipet May 24 '23 at 20:01
  • Thanks a lot ! I'm gonna accept the other answer because of what I asked, but I'll definitely use your method. – Nolord May 25 '23 at 11:17
  • Do you know any way to adapt the macro to different sizes? – Nolord May 25 '23 at 11:40
6

There are probably better ways.

\documentclass{article}
\usepackage{amsmath}
\usepackage{esint}

\usepackage{tikz} \usetikzlibrary{shapes}

\DeclareRobustCommand{\oiint}{% \mathop{}!% \vcenter{\hbox{% \makebox[0pt][l]{% \sbox0{$\displaystyle\phantom{\iint}$}% \makebox[\wd0]{% \begin{tikzpicture} \node[ line width=0.5pt, draw, ellipse, inner xsep=-0.15ex, inner ysep=-0.15ex, ] {\phantom{+,}}; \end{tikzpicture}% }% }% }}!% \iint }

\begin{document}

[ \oint_{X} \quad \iint_X \quad \oiint_X ]

[ X\iint X ]

[ X\oiint X ]

\end{document}

The idea is to insert an empty mathop in order to get the right spacing before the symbol; then we insert a negative thin space because we add an ordinary symbol, namely the ellipse set to a zero width box that has inside it a box as wide as the integral, containing the ellipse. Next another negative thin space to cancel the one that's inserted in front of \iint. Thus limits will be appended to \iint.

enter image description here

egreg
  • 1,121,712