5

I'm using the Unicode character "Double-Stroke Not Sign" (U+2AEC) to represent bitwise logical not operation (a.k.a. one's complement). I've implemented a control sequence called \blnot which accomplishes this, but my solution feels kludgey and I suspect there must be a best-practices solution which is much cleaner. Here is how my output looks with $-$, \lnot, and \blnot, respectively:

blnot sample

My question is two parts:

  1. What is the cleanest way to stack two \lnot operators as shown above? I made an \hbox and used \raisebox to adjust the base of each instance, but I don't like how I used \kern-.666666em to back up 2/3 em after the first instance. I feel like there should be a way to cleanly go back the exact width of \lnot without having to know it, or better yet simply to not advance at all between the two.

  2. I would also like to insert approximately .11em after both \lnot and \blnot because it looks too tight otherwise. (I'll be using \blnot mostly with multi-character identifiers in italics.) I've added the space this by saying \kern.11em, but again that feels kludgey to me. Ideally, I'd like to inuit the width of $-$ and simply use that, without hard-coding any width.

Here's an MWE:

\documentclass{article}

\newcommand{\blnot}{
  \mathord{%
    \hbox{%
      \raisebox{.19ex}{$\lnot$}\kern-.666666em%
      \raisebox{-.21ex}{$\lnot$}%
    }%
  }%
}

\begin{document}
$-a$                  \vskip -1ex
$\lnot\kern.11em a$   \vskip -1ex
$\blnot\kern.11em a$  \par
\end{document}

p.s. I know I could easily implement this using TikZ, but stacking two \lnots seems easier to make work at multiple font sizes. (I won't probably be using this at any size other than 10pt, but I might use it in a footnote or a caption.)

3 Answers 3

4

This is a job for \ooalign:

\newcommand{\blnot}{\mathord{\ooalign{%
  \relax\cr
  \noalign{\vskip-.2ex}
  $\lnot$\cr
  \noalign{\vskip.4ex}
  $\lnot$\cr
  \noalign{\vskip-.2ex}}%
  }}

Here's a complete example, where the \fbox show the effect on the bounding box; the first is \lnot, the second my proposed definition, the third is from Todd Lehman's self answer.

\documentclass{article}

\newcommand{\blnot}{\mathord{\ooalign{%
  \relax\cr
  \noalign{\vskip-.2ex}
  $\lnot$\cr
  \noalign{\vskip.4ex}
  $\lnot$\cr
  \noalign{\vskip-.2ex}}%
  }}

\newcommand{\TLblnot}{
  \mathord{%
    \hbox{%
      \raisebox{.18ex}{\rlap{$\lnot$}}%
      \raisebox{-.22ex}{\rlap{$\lnot$}}%
      \hphantom{$-$}%
    }%
  }%
}\begin{document}
\fbox{$\lnot a$}\fbox{$\blnot a$}\fbox{$\TLblnot a$}
\end{document}

enter image description here

For a size changing symbol, you can do the more complicated

\newcommand{\blnot}{\mathord{\mathpalette\xblnot\relax}}

\newcommand{\xblnot}[2]{
  \sbox2{$#1\lnot$}\vrule height 1.1\ht2 width0pt \ooalign{%
  \relax\cr
  \noalign{\vskip-.2\ht2}
  $#1\lnot$\cr
  \noalign{\vskip.4\ht2}
  $#1\lnot$\cr
  \noalign{\vskip-.2\ht2}}%
  }

and here's the result of

\fbox{$\lnot$}\fbox{$\blnot$}\fbox{$\blnot_{\blnot_{\blnot}}$}

enter image description here

It's quite simple also to get the symbol's bounding box as wide as a minus sign:

\newcommand{\blnot}{\mathord{\mathpalette\xblnot\relax}}

\newcommand{\xblnot}[2]{
  \sbox2{$#1\lnot$}\vrule height 1.1\ht2 width0pt \ooalign{%
  \hphantom{$#1-$}\relax\cr
  \noalign{\vskip-.2\ht2}
  \hfil$#1\lnot$\hfil\cr
  \noalign{\vskip.4\ht2}
  \hfil$#1\lnot$\hfil\cr
  \noalign{\vskip-.2\ht2}}%
  }

Some information on \ooalign can be found in this answer of mine

5
  • This is cool. A couple follow-up questions: (1) How best then to ensure a width equal to $-$? Wrap the \ooalign inside an \hbox with \rlap and \hphantom? I did that, and it seemed to work great. (2) Is there a good tutorial on \ooalign? I did some web searches and only turned up obscure examples. (3) The fact that the bounding box is larger than necessary in my version...is that actually a problem? It doesn't seem to be problematic unless the upper \lnot is raised about 1.2ex higher. Commented Jan 15, 2012 at 10:56
  • 1
    @ToddLehman See edit
    – egreg
    Commented Jan 15, 2012 at 11:01
  • I see what you're saying about the size changes, @egreg. My \hbox was clobbering the super/sub-script sizes. It worked fine when I did \scriptsize, but it fails, as you point out, in actual superscripts and subscripts. I probably won't be using this symbol in superscripts or subscripts, but it's really nice to see an example of how to make that work. I didn't know about \mathpalette, although I have a tiny bit of experience with \mathchoice. I'll read up on \mathpalette tomorrow so I can understand what is going on under the hood here. :) Commented Jan 15, 2012 at 11:22
  • Hey @egreg, I'm really liking this \ooalign. I just modified one of my other stacking symbol commands to use it where my bounding boxes had been slightly a bit too tall, causing a bit of unwanted space between lines. But now, with \ooalign, the line spacing is constant even if I stack a symbol so high that it protrudes all the way up into the line above it. (Not that I would do that for real, but I tested it that way just to be sure.) Nifty. Commented Jan 15, 2012 at 11:58
  • p.s. I marked your answer as my accepted answer. I was really happy with the \rlap solution earlier, but your \ooalign solution seems a safer way to go, and a better habit to get into for this sort of thing. Commented Jan 15, 2012 at 12:00
3

(Answering my own question here.) I ended up solving this myself, after Mikael Vejdemo-Johansson recommended that I use \llap or \rlap. Here's what I did. I am very happy with this solution:

\newcommand{\blnot}{
  \mathord{%
    \hbox{%
      \raisebox{.18ex}{\rlap{$\lnot$}}%
      \raisebox{-.22ex}{\rlap{$\lnot$}}%
      \hphantom{$-$}%
    }%
  }%
}

But taking it one step further, I defined it in terms of a \stacktwo command (for lack of a better name) that takes five parameters...

  1. First character (e.g., \lnot)
  2. Distance to raise first character (e.g., .18ex)
  3. Second character (e.g., \lnot)
  4. Distance to raise second character (e.g., -.22ex)
  5. Phantom character to define width of composite character sequence (e.g., $-$)

...and goes like this:

\newcommand{\stacktwo}[5]{%
  \mathord{%
    \hbox{%
      \raisebox{#2}{\rlap{#1}}%
      \raisebox{#4}{\rlap{#3}}%
      \hphantom{#5}%
    }
  }
}

The final definition then is very simple:

\newcommand{\xblnot}{\stacktwo{$\lnot$}{.18ex}{$\lnot$}{-.22ex}{$-$}}

This does exactly what I want for all of \normalsize, \footnotesize, \scriptsize, and \tiny, and I can re-use \stacktwo for other composites like Unicode character U+2A59 ("Logical Or Overlapping Logical And").

A minor flaw here is that the widths of the two characters must be exactly the same, because I haven't yet figured out how to vertically align two stacked items of different widths, but this solution works fine for the characters I need.

3
  • What would be a better name here than \stacktwo? It's more "overlapping" than it is "stacking." Need some name that means "overlap two non-advancing characters at different heights and then advance by the phantom width of a third character." Commented Jan 15, 2012 at 7:40
  • 1
    What about \verticalcombine? Or maybe shorter, \vcombine?
    – celtschk
    Commented Jan 15, 2012 at 8:52
  • I like \vcombine, @celtschk. Thank you. Voted your comment up. :) Commented Jan 15, 2012 at 11:24
2

This forum thread: https://groups.google.com/group/comp.text.tex/browse_thread/thread/8ed2ea2326858f8f?pli=1 provides several suggestions on how to implement a negative \phantom command which would allow you to step backwards with exactly your symbol's width.

In particular, this thread points out the LaTeX commands \llap and \rlap, both built to allow the construction of complex shapes by overlapping glyphs with sensible alignment. The example given is a construction of ≠ by either of the commands /\llap{=} or \rlap{=}/.

Thus, for your case, it would seem as if \rlap{\raisebox{-0.21em}{\lnot}}\raisebox{0.19em}{\lnot} might work.

2
  • Oooh. Excellent. I will check those out. I may devise a general control sequence that combines the the \rlap with the raising/lowering. Commented Jan 15, 2012 at 4:04
  • Mikael, that worked great. It wasn't easy for me, as I hadn't used \rlap before, but I figured it out with some experimentation. I posted my solution as an answer. Is that what you had in mind? I was very pleasantly surprised to see that a double use of \rlap makes it possible to use \hphantom{$-$} to define the width. Commented Jan 15, 2012 at 7:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .