[Tex/LaTex] Double-nested logical-and and logical-or symbols

logicsymbols

I'm typesetting a bunch of source code, and I really like the way the double-nested logical-and and logical-or symbols look for denoting bitwise logical and/or.

Unfortunately, LaTeX doesn't seem to have these symbols, so I resorted to rolling my own using a combination of \land and \lor with carefully rotated and aligned rules. The results are acceptable to my eye at 10pt, but the placement of the rules is fragile for a couple of reasons. Here's how they look magnified:

home-rolled double-nested logical-and and logical-or

The first reason they're fragile is because (against my better judgment, but not knowing a better way), I'm making assumptions about spacing:

\newcommand{\bland}{% bitwise logical and
  \hbox{%
    $\land$%
    \hspace{-.47em}%
    \raisebox{-.04em}{%
      \rotatebox{66}{%
        \vrule width .3em height .45pt depth 0pt%
      }%
      \hspace{.065em}%
      \rotatebox{-66}{%
        \hspace{-.3em}%
        \vrule width .3em height .45pt depth 0pt%
      }%
    }%
    \hspace{.20em}%
  }%
}

Thus, when shown in a smaller size—for example when stacked atop = or \Leftarrow—the internal lines are off by a small but noticeable amount.

The second reason is more insidious and seems to have to do with rounding error in PDF conversion or display: the inner wedge "wobbles" half a pixel or so (as compared to the outer wedge) at various sizes.

I'm wondering what the best solution is here. I'm not opposed (in theory) to diving into XeLaTeX to see how U+2A53 and U+2A54 look, but if possible I'd prefer to avoid dependencies on XeTeX/XeLaTeX for this. Also, the first thing I tried was nesting a \tiny\land inside a \land but the slopes of the strokes were different. Basically I need something with the same slopes and thicknesses, and it would also be nice if they had rounded edges, but I haven't the TeXpertise to make that happen.

Here's how the symbols look at a more regular size (top line is regular boolean logical operators; second two lines are bitwise boolean operators):

sample code

By the way, I did come across a double-nested less-than and greater-than in a standard LaTeX package, which I think I could maybe use—if I rotated them 90 degrees—but the problem I have with those is that they override/redefine \ll and \gg rather than adding new control sequences, and I have places elsewhere where I want to use the real \ll and \gg.

Best Answer

You don't need to load the mathabx package just to use one symbol: just load the necessary font and consult the package to know the slot corresponding to \lll; it turns out that the font is matha and the slot is "CE.

\usepackage{graphicx}

\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * matha
      <10.95> matha10 <12> <14.4> <17.28> <20.74> <24.88> matha12
      }{}

\newcommand{\bland}{\mathbin{
  \raisebox{.1ex}{%
    \rotatebox[origin=c]{-90}{\usefont{U}{matha}{m}{n}\symbol{\string"CE}}}}}
\newcommand{\blor}{\mathbin{
  \raisebox{.1ex}{%
    \rotatebox[origin=c]{90}{\usefont{U}{matha}{m}{n}\symbol{\string"CE}}}}}

enter image description here

If you need those symbols also in subscripts and superscripts, some more work is needed. A possible definition is

\usepackage{graphicx}

\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * matha
      <10.95> matha10 <12> <14.4> <17.28> <20.74> <24.88> matha12
      }{}

\makeatletter
\newcommand{\blandor}[1]{\mathbin{\@blandor{#1}}}
\newcommand{\@blandor}[1]{\mathchoice
  {\@@blandor{#1}{\tf@size}}
  {\@@blandor{#1}{\tf@size}}
  {\@@blandor{#1}{\sf@size}}
  {\@@blandor{#1}{\ssf@size}}
}
\newcommand{\@@blandor}[2]{%
    \raisebox{.1ex}{\rotatebox[origin=c]{#1}{%
      \fontsize{#2}{#2}\usefont{U}{matha}{m}{n}\symbol{\string"CE}}}%
}
\makeatother
\newcommand{\bland}{\blandor{-90}}
\newcommand{\blor}{\blandor{90}}
Related Question