# Using \newcommand to create a math symbol

I have seen some examples of using \newcommand to create a new math symbol, e.g.,

\newcommand\indep{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2.5mu{#1#2}}}

but unfortunately this appears as obscure nonsense to me.

I would like to create a new math symbol, which is easily visualized: similar to \oplus but with a smaller (centered) circle, like the one given by \circ, so that the lines of the + stretch outside of the circle.

How can this be done?

Here, \stackinseting a \circ over a +. Using scalerel to carry it across all math styles.

\documentclass{article}
\usepackage{stackengine,scalerel}
\stackMath
\newcommand\circplus{\mathbin{\ThisStyle{\ensurestackMath{%
\stackinset{c}{}{c}{\dimexpr.1pt-.4\LMpt}{\SavedStyle\circ}{\SavedStyle+}}}}}
\begin{document}
$1 + 2 \oplus 3 \circplus 4_{\circplus_{\circplus}}$

\end{document}

For something that fits the \oplus line widths:

\documentclass{article}
\usepackage{stackengine,scalerel,graphicx}
\def\pieceA{\scalebox{.8}{$\scriptscriptstyle{-}\kern3pt{-}$}}% THE 3pt CAN VARY ARM LENGTH
\savestack\Xoplus{%
\setbox0=\hbox{$\pieceA$}%
\ensurestackMath{%
\kern.5\wd0%
\makebox[0pt]{%
\stackinset{c}{}{c}{}%
{\rotatebox[origin=c]{90}{\copy0}}%
{\stackinset{c}{}{c}{}{\copy0}{\oplus}}%
}%
\kern.5\wd0
}%
}
%\newcommand\xoplus{\mathbin{\scalerel*{\Xoplus}{\oplus}}}% FOR SIMPLE, AS IS SCALING
% FOR TUNABLE SCALING using \xoplusscale
\newcommand\xoplusscale{1}
\newcommand\xoplus{\mathbin{\ThisStyle{\vcenter{\hbox{%
$\SavedStyle\scalerel*{\Xoplus}{\vstretch{\xoplusscale}{\oplus}}$}}}}}
\begin{document}
$1 + 2 \oplus 3 \xoplus 4_{\xoplus_{\xoplus}}$
\renewcommand\xoplusscale{1.5}
\vspace{-12pt}
$1 + 2 \oplus 3 \xoplus 4_{\xoplus_{\xoplus}}$
\end{document}

• Thank you, your answer looks visually the same as the one above. The problem is that I would like to recreate the thin lines of \oplus, but not the (relatively) bold lines of +. – PseudoRandom Oct 24 '17 at 13:05
• @PseudoRandom I will give it some more thought. Do you want an \oplus with the lines extended or an \oplus with the circle shrunk? – Steven B. Segletes Oct 24 '17 at 13:06
• If you can do both, it would be awesome. Otherwise, an \oplus with the circle shrunk is good enough. – PseudoRandom Oct 24 '17 at 13:07
• @PseudoRandom As you wish... though it is a more complicated calculation. – Steven B. Segletes Oct 24 '17 at 13:41
• @PseudoRandom even for the simplest of glyphs, say a minus, -, one must consider issues of line thickness, vertical/horizontal placement, overall scale, and surrounding space. All of these must be addressed any time you want to put a new symbol on the screen. – Steven B. Segletes Oct 24 '17 at 14:07

Picture mode to the rescue!

\documentclass{article}
\usepackage{pict2e,picture}

\makeatletter
\newcommand{\cplus}{\mathbin{\mathpalette\pseudorandom@cplus\relax}}
\newcommand{\pseudorandom@cplus}[2]{%
\vcenter{\hbox{%
\sbox\z@{$\m@th#1+$}%
\setlength{\unitlength}{\dimexpr\ht\z@+\dp\z@}%
\linethickness{.06\unitlength}%
\begin{picture}(\wd\z@,1)
\put(0.5\wd\z@,0.5){\circle{0.5}}
\put(0,0){\raisebox{\depth}{\box\z@}}
\end{picture}%
}}%
}
\makeatother

\begin{document}

\begingroup % show the bounding boxes
\fboxsep=-0.1pt \fboxrule=0.1pt
\fbox{$+$}\fbox{$\cplus$}

\nointerlineskip
\fbox{$\cplus$}\fbox{$+$}
\endgroup

% test for the spacing and subscripts

$a+b\cplus c_{+\cplus}$

$a\cplus b+c_{+\cplus}$

\medskip

% test for larger size

{\LARGE$a\cplus b+c_{+\cplus}$}

\end{document}

For lighter strokes to accompany \oplus:

\documentclass{article}
\usepackage{pict2e,picture}

\makeatletter
\newcommand{\cplus}{\mathbin{\mathpalette\pseudorandom@cplus\relax}}
\newcommand{\pseudorandom@cplus}[2]{%
\vcenter{\hbox{%
\sbox\z@{$\m@th#1+$}%
\setlength{\unitlength}{\dimexpr\ht\z@+\dp\z@}%
\linethickness{.06\unitlength}%
\begin{picture}(\wd\z@,1)
\put(0.5\wd\z@,0.5){\circle{0.5}}
\put(0,0){\raisebox{\depth}{\box\z@}}
\end{picture}%
}}%
}
\makeatother

\begin{document}

\fboxsep=-0.1pt \fboxrule=0.1pt
\fbox{$+$}\fbox{$\cplus$}

\nointerlineskip
\fbox{$\cplus$}\fbox{$+$}

$a+b\cplus c_{+\cplus}$

$a\cplus b+c_{+\cplus}$

\medskip

{\LARGE$a\cplus b+c_{+\cplus}$}

\end{document}