[Tex/LaTex] How to write NAND resp. NOR operators

math-modesymbols

I'm trying to define Boolean operators NAND and NOR, using a tilde that overlaps either a \wedge or a \vee. I can't find these in the comprehensive list of LaTeX symbols. I tried using \llap, but I'm getting error messages because \wedge and \vee are defined as operators. This is how I would like, them to look:

nor, nand

Best Answer

You can exploit \ooalign:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\DeclareRobustCommand{\nand}{\mathbin{\mathpalette\n@and@or\land}}
\DeclareRobustCommand{\nor}{\mathbin{\mathpalette\n@and@or\lor}}

\newcommand{\n@and@or}[2]{%
  \vphantom{#2}%
  \ooalign{$\m@th#1#2$\cr\hidewidth$\m@th#1\sim$\hidewidth\cr}%
}
\makeatother

\begin{document}

$a \land b$ $a \lor b_{a\lor b\land c}$

$a \nand b$ $a \nor b_{a\nor b\nand c}$

\end{document}

enter image description here