6

I have trouble getting a nice symbol for the set of non-squares. I would like to have a crossed out square, but the

$\not\square$

command does not place the line at the right place.

Using the package centernot it gets a little better

\usepackage{centernot}
$\centernot\square$

Now the line is at the right place but it is not as symmetric as it should be: the line comes only just up to the top side of the square. Any ideas?

Choky
  • 163

3 Answers3

5

You can avoid any guesswork, by letting TeX do the computations.

\documentclass{article}
\usepackage{amsmath,amssymb}

\makeatletter
\DeclareRobustCommand{\notsquare}{\mathord{\mathpalette\generic@not\square}}
\newcommand{\generic@not}[2]{%
  \sbox\z@{$\m@th#1/$}%
  \sbox\tw@{$\m@th#1#2$}%
  \sbox\z@{\raisebox{\dimexpr(\ht\tw@-\dp\tw@-\ht\z@+\dp\z@)/2\relax}{$\m@th#1/$}}%
  \vphantom{\usebox{\z@}}%
  \ooalign{\hidewidth\usebox{\z@}\hidewidth\cr$\m@th#1#2$\cr}%
}
\makeatother

\begin{document}

$\square\notsquare_{\square\notsquare}$

\end{document}

I used \mathord because such is \square.

enter image description here

egreg
  • 1,121,712
4

Since \not is made to apply to math relations, a better syntax would be \mathord{\not\mathrel{\square}}. However, while that fixes the horizontal placement, vertical is still not ideal.

So I propose a "BEST" stackengine approach.

However, the OP notes the desire to avoid extra packages so I edited to also provide a native Alternative.

\documentclass{article}
\usepackage{amssymb,stackengine}
\begin{document}
\[
\textrm{Better: }\quad\mathord{\not\mathrel{\square}}
\]
\[
\textrm{Best: }\quad\ensurestackMath{\stackinset{c}{}{c}{}{/}{\square}}
\]
\[
\textrm{Alternative: }\quad\raisebox{1pt}{$\not\mathrel{\raisebox{-1pt}{$\square$}}$}
\]
\end{document}

enter image description here

  • The `Best' output is certainly what I want, but the stackengine package isn't installed by default. While I could install it, I am using it for a paper with coauthors and I really do not want to annoy them (or the publisher!). Is there a way to get the same output by only using standard packages? – Choky Oct 25 '18 at 03:37
  • @Choky Please see my update. – Steven B. Segletes Oct 25 '18 at 04:00
4

You can define your own symbol as an overlay of \square with / using \ooalign:

enter image description here

\documentclass{article}

\usepackage{amssymb}

\newcommand{\notsquare}{
  \mathrel{
    \ooalign{
      $\square$\cr
      \hidewidth\raise.225ex\hbox{$/$}\hidewidth
    }
  }
}

\begin{document}

\[
  f \mathrel{\square} g \notsquare h
\]

\end{document}

Here is a short course on \ooalign: \subseteq + \circ as a single symbol ("open subset")

Werner
  • 603,163