# Defining a new mathematical symbol without argument

I defined a new logical symbol in LaTeX using TikZ:

\newcommand{\excl}[1]{\operatorname{
\begin{tikzpicture}[#1]
\draw[line cap=round] (0,0) --(1.4ex,0) -- (2.2ex,0.6ex);
\draw[line cap=round] (1.4ex,0) -- (2.2ex,-0.6ex);
\end{tikzpicture}
}}


It goes fine as long as I type $excl{}$ with an empty argument. This is quite inconvenient so I would like to get rid of the curly brackets and just type $\excl$ instead. But I simply do no know how to do it and simply deleting [1] in newcommand simply blocks compilation. Anyone to help me?

• delete both [1] and [#1] but if then seems big or small for you try placing at the deleted [#1]'s position something like [scale=0.8] or similar... – koleygr Aug 28 '19 at 1:49
• \newcommand{\excl}[1][]{\operatorname{ \begin{tikzpicture}[#1] \draw[line cap=round,line width=0.07em] (0,0) --(1.4ex,0) -- (2.2ex,0.6ex); \draw[line cap=round,line width=0.07em] (1.4ex,0) -- (2.2ex,-0.6ex); \end{tikzpicture} }}, i.e. make the argument optional by adding []. These optional arguments can be useful if you want, say, to change the baseline of the picture. BTW, I'd specify the line width in scalable units, too, hence the line width=0.07em. That way the symbol really adjusts to the font size. – Schrödinger's cat Aug 28 '19 at 1:54
• @Schrödinger'scat please turn your comment to an answer! – Black Mild Aug 28 '19 at 7:02
• Thanks to all of you! I simply deleted both [1] and [#1] and that worked perfectly fine. – IanShil Aug 29 '19 at 2:03

You could just make the argument optional. However, I'd recommend adding a few more features:

1. Make the symbol bold if the ambient text is.
2. Use \mathchoice to make the symbol adjust its size in, say, a subscript.

\documentclass{article}
\usepackage{amsmath,amsfonts}
\usepackage{tikz}
\makeatletter
\DeclareRobustCommand{\checkbold}[1]{% https://tex.stackexchange.com/a/24635/121799
\edef\@tempa{\math@version}\edef\@tempb{bold}%
\ifx\@tempa\@tempb%
\def#1{1}%
\else
\def#1{0}%
\fi}
\makeatother
\newcommand{\excl}[1][]{\checkbold\tmp%
\ensuremath{\operatorname{%
\mathchoice{%
\begin{tikzpicture}[#1]
\draw[line cap=round,line width=(1+0.33*\tmp)*0.06em] (0,0) --(1.4ex,0) -- (2.2ex,0.6ex)
(1.4ex,0) -- (2.2ex,-0.6ex);
\end{tikzpicture}}{%
\begin{tikzpicture}[#1]
\draw[line cap=round,line width=(1+0.33*\tmp)*0.06em] (0,0) --(1.4ex,0) -- (2.2ex,0.6ex)
(1.4ex,0) -- (2.2ex,-0.6ex);
\end{tikzpicture}}{%
\begin{tikzpicture}[#1]
\draw[line cap=round,line width=(1+0.33*\tmp)*0.045em] (0,0) --(1.05ex,0) --
(1.6ex,0.45ex)
(1.05ex,0) -- (1.6ex,-0.45ex);
\end{tikzpicture}}{%
\begin{tikzpicture}[#1]
\draw[line cap=round,line width=(1+0.33*\tmp)*0.035em] (0,0) --(0.85ex,0) --
(1.4ex,0.35ex)
(0.85ex,0) -- (1.4ex,-0.35ex);
\end{tikzpicture}}}}}
\newcommand{\oldexcl}[1][]{\operatorname{\begin{tikzpicture}[#1]
\draw[line cap=round] (0,0) --(1.4ex,0) -- (2.2ex,0.6ex);
\draw[line cap=round] (1.4ex,0) -- (2.2ex,-0.6ex);
\end{tikzpicture}}}
\begin{document}
$A\excl B$ $X_{A\excl B}$ \boldmath $A\excl B$ $X_{A\excl B}$\unboldmath\par
$A\oldexcl B$ $X_{A\oldexcl B}$ \boldmath $A\oldexcl B$ $X_{A\oldexcl B}$\unboldmath\par
$A\excl[baseline=-0.65ex,purple] B$
\end{document}


The first line shows how the symbol behaves with these additional features, the second line shows what happens without them, and the third line illustrates what the optional argument(s) can be used for.

• Wow! I would have never thought of that. Thanks a lot for this answer, be sure I will incorporate it in my file :-) – IanShil Aug 29 '19 at 2:05