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!

8

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

  • Only possible suggestion would be to change \stackMath declaration to \ensurestackMath{...}, so that current text/math stack setting is not perturbed by the macro. – Steven B. Segletes Nov 5 '18 at 1:17
  • I confess I had forgotten this command. I'll fix the code at once. Thanks! – Bernard Nov 5 '18 at 1:22
  • \ensurestackMath takes an argument, so you need to enclose everything that follows in braces...[at least that is the official syntax]. – Steven B. Segletes Nov 5 '18 at 1:46
  • Of course. I guess I was out of my mind… – Bernard Nov 5 '18 at 9:38
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.