%D \module
%D   [       file=meta-imp-logicsymbols,
%D        version=2026.01.29,
%D          title=\METAPOST\ Graphics,
%D       subtitle=Logic Symbols,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

This module is a quick and dirty answer to a (few) question(s) on the mailing list
asking for a font that has such symbols. Here we show how to use \METAFUN\ to meet this demand.
that shows how to  make a font

\startMPcalculation{simplefun}

    path Logic[] ;

    Logic[30] := (0,1  ) -- (-1,1  ) ;
    Logic[31] := (0,0.5) -- (-1,0.5) ;
    Logic[32] := (0,1.5) -- (-1,1.5) ;
    Logic[33] := (2,1  ) -- ( 3,1  ) ;
    Logic[34] := fullcircle scaled .4 shifted (2.2,1) -- (2.4,1) -- (3,1) ;
    Logic[35] := (-.2,2) .. (.2,1) .. (-.2,0) ;

    Logic[1]  := (0,0) -- (1,0) .. (2,1) .. (1,2) -- (0,2) -- cycle ;
    Logic[2]  := (0,0) -- (2,1) -- (0,2)-- cycle ;
    Logic[3]  := (-.2,0) -- (1,0) .. (2,1) .. (1,2) -- (-.2,2) .. (.2,1) .. cycle ;
    Logic[4]  := ( .2,0) -- (1,0) .. (2,1) .. (1,2) -- ( .2,2) .. (.6,1) .. cycle ;

    numeric LogicPenWidth ; LogicPenWidth := 1/6 ;

    def LogicBUFFER =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[2] && Logic[30] && Logic[33] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicNOT =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[2] && Logic[30] && Logic[34] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicAND =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[1] && Logic[31] && Logic[32] && Logic[33] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicNAND =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[1] && Logic[31] && Logic[32] && Logic[34] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicOR =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[3] && Logic[31] && Logic[32] && Logic[33] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicNOR =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[3] && Logic[31] && Logic[32] && Logic[34] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicXOR =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[4] && Logic[31] && Logic[32] && Logic[33] && Logic[35] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    def LogicNXOR =
        pickup pencircle scaled LogicPenWidth ;
        draw Logic[4] && Logic[31] && Logic[32] && Logic[34] && Logic[35] ;
        currentpicture := currentpicture shifted (1,0) ;
    enddef ;

    lmt_registerglyphs [
        name     = "symbols:logic",
        units    = 4,
        width    = 4,
        height   = 2,
        depth    = 0,
        usecolor = true,
    ] ;

    lmt_registerglyph [ category = "symbols:logic", unicode = "0xF800", code = "LogicBUFFER;" ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x00AC", code = "LogicNOT;"    ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x2227", code = "LogicAND;"    ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x2228", code = "LogicOR;"     ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x22BC", code = "LogicNAND;"   ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x22BD", code = "LogicNOR;"    ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0x22BB", code = "LogicXOR;"    ] ;
    lmt_registerglyph [ category = "symbols:logic", unicode = "0xF801", code = "LogicNXOR;"   ] ;

\stopMPcalculation

\definefontfeature
  [symbols:logic]
  [default]
  [metapost={category=symbols:logic}]


\definefontsynonym[LogicGates][Serif*symbols:logic]

\definesymbol[LogicBUFFER] [\getglyph{LogicGates}{\char"F800}] \protected\def\lBUFFER{\symbol[LogicBUFFER]}
\definesymbol[LogicNOT]    [\getglyph{LogicGates}{\char"00AC}] \protected\def\lNOT   {\symbol[LogicNOT]}
\definesymbol[LogicAND]    [\getglyph{LogicGates}{\char"2227}] \protected\def\lAND   {\symbol[LogicAND]}
\definesymbol[LogicOR]     [\getglyph{LogicGates}{\char"2228}] \protected\def\lOR    {\symbol[LogicOR]}
\definesymbol[LogicNAND]   [\getglyph{LogicGates}{\char"22BC}] \protected\def\lNAND  {\symbol[LogicNAND]}
\definesymbol[LogicNOR]    [\getglyph{LogicGates}{\char"22BD}] \protected\def\lNOR   {\symbol[LogicNOR]}
\definesymbol[LogicXOR]    [\getglyph{LogicGates}{\char"22BB}] \protected\def\lXOR   {\symbol[LogicXOR]}
\definesymbol[LogicNXOR]   [\getglyph{LogicGates}{\char"F801}] \protected\def\lNXOR  {\symbol[LogicNXOR]}

\continueifinputfile{meta-imp-logicsymbols.mkxl}

\starttext

    \showglyphs

    \definefont[logic][Serif*symbols:logic]

    \protected\def\Gate#1{\logic \char"#1 }
    \protected\def\Mate#1{\im{\Gate{#1}}}

    \startTEXpage[offset=3pt]
        \starttabulate[|c|c|c|c|c|c|c|c|]
            \NC AND         \NC NAND        \NC OR          \NC NOR         \NC XOR         \NC NXOR        \NC NOT         \NC BUFFER      \NC \NR
            \NC \Gate{2227} \NC \Gate{22BC} \NC \Gate{2228} \NC \Gate{22BD} \NC \Gate{22BB} \NC \Gate{F801} \NC \Gate{00AC} \NC \Gate{F800} \NC \NR
            \NC \Mate{2227} \NC \Mate{22BC} \NC \Mate{2228} \NC \Mate{22BD} \NC \Mate{22BB} \NC             \NC \Mate{00AC} \NC             \NC \NR
            \NC \logic  ∧   \NC \logic ⊼   \NC \logic ∨    \NC \logic ⊽    \NC \logic ⊻    \NC \logic       \NC \logic ¬    \NC \logic      \NC \NR
        \stoptabulate
    \stopTEXpage

    \startTEXpage[offset=3pt]
        \symbol{LogicBUFFER} \symbol{LogicNOT}
        \symbol{LogicAND}    \symbol{LogicOR}
        \symbol{LogicNAND}   \symbol{LogicNOR}
        \symbol{LogicXOR}    \symbol{LogicNXOR}
        \par \darkred
        \lBUFFER\space  \lNOT\space
        \lAND   \space  \lOR \space
        \lNAND  \space  \lNOR\space
        \lXOR   \space  \lNXOR
    \stopTEXpage

\stoptext
