On 1/30/2026 9:53 AM, Jeong Dal via ntg-context wrote:
Hi, Hans,

It is great to see the result of defining fonts of Logic gates.
Also, I learn your clever way of drawing logic gates a lot from your code.

It was just a quick hack. I cleaned it up a bit.

Last year, I need to make a short manuscript of logic which contains the logic 
gates and Karnaugh Map for high school teachers.
You may remember that I asked a lot to use Lua and MetaFun to draw Karnaugh map.
You helped a lot and I am able to draw them more easily.
Later, I found a Karnaugh Map module!

At that time, another huddle is to draw logic gates. I draw it one by one that 
is a real time consuming job, and connecting those gates with lines is another 
trial and error job.

I wonder if the flowchart module could help you there. After all there we have shapes, connecting lines, etc.

There are so many math symbols like \infty, \sum, etc.
Is it possible to define them like math symbols to use them  \logicNot, 
\logicOr, …

It depends on how you use the font. We basically hook them into a regular font.


BTW, logic gates is used to draw a circuit diagram, so it is another way to use 
them as figure.
I believe that you find the best way of using it.

For circuit diagram there are cad-like programs that also validate the design.

Hans


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
%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{F800} \NC \Gate{00AC} \NC \Gate{F801} \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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to