21

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.

2
  • Was your usage of this symbol standard, and if so, what subject was it for? A question on Math.SE came up recently asking for how this symbol is used, and your example was the only one that I could find easily.
    – John
    Jul 29, 2018 at 1:50
  • @John — Not standard, no. Just typesetting some code for myself. (See example image above.) Jul 29, 2018 at 19:13

1 Answer 1

19

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}}
6
  • Thank you so much. This is perfect. Beautiful. Exactly what I need. (I actually saw your reply yesterday while I was on the train, but I didn't have time to try it out until I got home today.) I made two small modifications: (1) I added a \scalebox{.82}[1] between the \raisebox and the \rotatebox so that the width and stroke slopes exactly match the \land and \lor symbols, and (2) I added \kern.061em on each side so that the spacing also matches (at least, that is to say, in 10pt). Thank you also for the edit which added the multiple sizes! Dec 26, 2011 at 18:17
  • 1
    @ToddLehman I'd do the scaling before rotating, with \scalebox{1}[.82]{\fontsize...}.
    – egreg
    Dec 26, 2011 at 18:23
  • Ok, I've made that change, thanks. (It also required changing \raisebox{.1ex} to \raisebox{.19ex}.) Question: It's going to need slightly different scaling values for the smaller sizes. I modified \@@blandor to take 4 arguments instead of 2, so I can pass scaling values for each size, and I noticed that the second of the four \mathchoice lines seems to control all of \normalsize, \small, \footnotesize, \scriptsize, and \tiny. In other words, {\@@blandor{#1}{\tf@size}{1}{.82}} seems to govern all the sizes, with the other three lines ignored. Does that sound right? Dec 26, 2011 at 18:56
  • 1
    @ToddLehman The four arguments to \mathchoice tell TeX what to do when it has to typeset the object in \displaystyle, \textstyle, \scriptstyle and \scriptscriptstyle; the use of \tf@size and so on guarantees that the chosen font is the right one depending on the context (\small, \large or any other).
    – egreg
    Dec 26, 2011 at 19:08
  • Aha. Cool. I'll do some more experimenting along those lines. I actually don't need these symbols in superscripts or subscripts; I only need the smaller size for stacking above a widened \Leftarrow, and the normal size for regular operations. Dec 26, 2011 at 19:10

You must log in to answer this question.

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