6

does any know how I can create a command that places a symbol given as an argument inside \cup?

For instance, the command \uplus has the symbol '+' inside \cup. I would like to be able to place any given symbol inside \cup (in special, the letter 'k'). An important issue is that the size of the symbol must respect the superscript math mode. Actually, the size of this symbol has to be a bit smaller, so as is '+' inside \cup in \uplus.

The figure below explains better what I am talking about.

enter image description here

I would like to obtain something similar to the second (from left to right) case.

Thanks in advance!

2 Answers2

9

The \stackinset command from stackengine can do that:

\documentclass[border = 2pt]{standalone}

 \usepackage{stackengine} %
\newcommand\cupk{\ensurestackMath{\stackinset{c}{0ex}{c}{0.2ex}{\scriptscriptstyle k}{\scriptstyle\cup}}}

\begin{document}

$B^{\cupk} $

\end{document} 

enter image description here

Bernard
  • 271,350
9

We need fully scalable fonts for this, so fix-cm if the document is in the standard Computer Modern font. It is not necessary if other fonts are chosen.

\RequirePackage{fix-cm}
\documentclass{article}
\usepackage{amsmath}

\makeatletter
\DeclareRobustCommand{\vcup}[1]{%
  \mathbin{\vphantom{\cup}\mathpalette\vcup@{#1}}%
}
\newcommand{\vcup@}[2]{%
  \ooalign{%
    $\m@th#1\cup$\cr
    \hidewidth
    \raisebox{%
      \dimexpr\depth+\demote@{#1}\dimexpr1.5pt\relax\relax
    }{\fontsize{\demote@{#1}\dimexpr\f@size pt}{\z@}\selectfont\check@mathfonts
      $\m@th#2$}%
    \hidewidth\cr
  }%
}
\newcommand{\demote@}[1]{%
  \ifx#1\displaystyle 0.7
  \else\ifx#1\textstyle 0.7
  \else\ifx#1\scriptstyle 0.5
  \else 0.4\fi\fi\fi
}
\makeatother

\begin{document}

$A\vcup{k}B^{\vcup{k}}$

$\uplus\scriptstyle\uplus\scriptscriptstyle\uplus$
$\vcup{k}\scriptstyle\vcup{k}\scriptscriptstyle\vcup{k}$
$\vcup{y}\scriptstyle\vcup{y}\scriptscriptstyle\vcup{y}$
$\vcup{g}\scriptstyle\vcup{g}\scriptscriptstyle\vcup{g}$

\end{document}

enter image description here

egreg
  • 1,121,712