[Tex/LaTex] \subseteq + \circ as a single symbol (“open subset”)

math-moderelation-symbolssymbols

I'm trying to create symbols \opn for "open subset" and \cls "closed subset". I want them to look like this:

enter image description here

enter image description here

My current solution is:

\def\opn{\!\ensuremath{\subseteq\!\!\!\!\!\raisebox{1pt}{$\circ$}}\,} 
\def\cls{\!\ensuremath{\subseteq\!\!\!\!\!\raisebox{1pt}{$\bullet$}}\,}

But the problem is when I use this, Latex doesn't treat \subseteq and \circ as a single symbol, so the spacing is incorrect when for example I write $U~\!\!\!\opn\!\!\!~X$:

enter image description here

How can I make the position of the circle be fixed in the middle, so that \opn becomes a single symbol that is resizable, i.e. responds well to \huge?

Edit: @egreg @MartinScharrer: When using your command (to define the stalk of a sheaf)

\mathcal{F}_x:=\frac{\bigsqcup\{\mathcal{F}(U);\, x\in U \opn X\}}{s\sim s' 
\,\Longleftrightarrow\, s\in\mathcal{F}(U)\text{ and }s'\in\mathcal{F}(U')\text{ and }
\exists x\in W \opn U\cap U'\!:s|_W=s'|_W}

I get ugly results, namely (egreg's solution)
enter image description here
and (Martin Scharrer's solution)
enter image description here.

Currently, I like this edited Martin's solution the most aesthetically appealing:

\def\opn{ \ensuremath{\mathrel{\subseteq \!\!\!\!\!\raisebox{1.63pt}{$\scriptstyle\circ$}}}}    %odprta podmnozica
\def\opnn{\ensuremath{\mathrel{\subsetneq\!\!\!\!\!\raisebox{1.63pt}{$\scriptstyle\circ$}}}}    %prava odprta podmnozica
\def\cls{ \ensuremath{\mathrel{\subseteq \!\!\!\!\!\raisebox{1.63pt}{$\scriptstyle\bullet$}}}}  %zaprta podmnozica
\def\clsn{\ensuremath{\mathrel{\subsetneq\!\!\!\!\!\raisebox{1.63pt}{$\scriptstyle\bullet$}}}}  %prava zaprta podmnozica

but there is still a problem in the above code. Could anyone edit this last code to fix the problem with spacing?

Best Answer

Here is a possibility:

\newcommand\opn{\mathrel{\ooalign{$\subseteq$\cr
  \hidewidth\raise.225ex\hbox{$\circ\mkern.5mu$}\cr}}}
\newcommand\cls{\mathrel{\ooalign{$\subseteq$\cr
  \hidewidth\raise.225ex\hbox{$\bullet\mkern.5mu$}\cr}}}

The symbols will change size according to the context. They don't reduce in subscript or superscripts, for that something more is needed.

This is a case where \ensuremath is superfluous, since the symbols will always be used in math mode, except perhaps in their definition, where adding $ symbols around them is not much of a hassle.

The low level \ooalign command is one of my favorite tools. I'm telling TeX to superimpose the two symbols, the circle or bullet is aligned at right, but pushed left a bit by \mkern.5mu and raised with a font dependent dimension (the amount 0.225ex has been computed by trial and error). Act on \mkern.5mu if you want to push the circles a bit more to the left.

Here's the result of $A\opn B\cls C$

enter image description here

A quick course on \ooalign

Think to \ooalign{...} pretty much like

\begin{tabular}[t]{@{}l@{}}
...
\end{tabular}

where instead of \\ one has to write \cr, but all rows are printed on top of each other. It is customary to use \hidewidth instead of \hfil to get an entry centered with respect to the widest one and actually it has its benefits.

Let's see an example from plain.tex (the LaTeX definition is similar, and this one is simplified): we want to put a cedilla after some non standard character.

\def\c#1{{\ooalign{#1\cr\hidewidth\char24\hidewidth\cr}}}

Here \char24 is the cedilla in the usual Knuth font encoding; it's a character that sits just below the baseline, so for characters that don't have descenders, we can print the character (#1) and superimpose to it the cedilla (it will go under it, of course). With \hidewidth\char24\hidewidth we pretend that the cedilla takes up no horizontal space, so the resulting block will be the same width as the character; we don't even need to know how wide is \char24.

If we want to build a "supinf" symbol, superimposing \land and \lor, we can define

\newcommand{\supinf}{\mathbin{\ooalign{$\lor$\cr$\land$\cr}}}

Here \mathbin says that this command must be used in math mode and the symbol is considered as an operation symbol.

The command \hidewidth just adds a large negative space (it's \hskip -1000pt plus 1fill compensating it with infinite stretchability. A table cell where \hidewidth is present will never be the largest one.

Caution
Always enclose {\ooalign{...}} in a group as shown here and in the definition of \c, otherwise nasty surprises can spoil your masterpiece of typography. In our cases, the braces in \mathbin{...} and \mathrel{...} act as group delimiters.


Here's how you can get size changing according to the math style:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand\opn{\mathrel{\opncls@{\circ}}}
\newcommand\cls{\mathrel{\opncls@{\bullet}}}
\newcommand{\opncls@}[1]{%
  \vphantom{\subseteq}% to fix the bounding box
  \mathpalette\opncls@@{#1}%
}
\newcommand{\opncls@@}[2]{%
  \ooalign{$\m@th#1\subseteq$\cr
  \hidewidth\opncls@fix{#1}\hbox{$\m@th#1#2\mkern.5mu$}\cr}}

\newcommand\opncls@fix[1]{%
  \ifx#1\displaystyle
    \raise.225ex
  \else
    \ifx#1\textstyle
      \raise.225ex
    \else
      \ifx#1\scriptstyle
        \raise.180ex
      \else
        \raise.150ex
      \fi
    \fi
  \fi
}
\makeatother

\begin{document}
$
\mathcal{F}_x:=
  \frac{\bigsqcup\{\mathcal{F}(U);\, x\in U \opn X\}}
  {\exists x\in W \opn U\cap U'\!:s|_W=s'|_W}
$

\bigskip

$\displaystyle\opn\cls
 \quad
 \textstyle\opn\cls
 \quad
 \scriptstyle\opn\cls
 \quad
 \scriptscriptstyle\opn\cls$

\end{document}

enter image description here

(I've simplified your formula just to show the effect of the new symbol; however, such a big formula should always be typeset in display style and with \dfrac.)

A couple of further notes. I used \m@th in order to avoid problems if the document class sets a nonzero value for \mathsurround (but it's rare that it's set otherwise).

The \vphantom{\subseteq} is needed because \ooalign sets the bounding box using the first row for the height and the last row for the depth.