This example shows using macros for drawing Karnaugh diagrams. They visualize boolean algebra expressions.

Edit and compile if you like:
% Karnaugh diagram% Author: Uwe Zimmermann\documentclass[x11names,border=10pt,tikz]{standalone}\usepackage{xstring} % needed for string manipulations\usepackage{fmtcount} % needed for some binary printing\usetikzlibrary{calc,math}\newif\ifKaddress\newif\ifKInd\pgfkeys{/K/.is family, /K,x bits/.estore in = \KXvars, % bits along the horizontal axisy bits/.estore in = \KYvars, % bits along the vertical axisvariable names/.estore in = \KVars, % comma-separated variable nameslabel/.estore in = \KLabel, % label for the diagramlabel scale/.estore in = \KLabelscale,% scale factor for valuesvalue scale/.estore in = \KValscale, % scale factor for valuesvariable scale/.estore in = \KVarscale, % scale factor for variablesvariable sep/.estore in = \KVarsep, % inner sep for variablesaddress scale/.estore in = \KAddrscale, % scale factor for adressesaddress sep/.estore in = \KAddrsep, % inner sep for adressesgroup distance/.estore in = \KGdist, % distance for grouping linesgroup color/.estore in = \KGcolor, % grouping colorgroup linewidth/.estore in = \KGwidth, % grouping line widthgroup rounded/.estore in = \KGrounded, % grouping rounded corner radiusgroup opacity/.estore in = \KGopacity, % grouping field opacityindicator distance/.estore in = \KInddist, % variable indicator distanceindicator linewidth/.estore in = \KIndwidth, % line width for indicatorsindicator scale/.estore in = \KIndscale, % scale factor for indicatorsindicator sep/.estore in = \KIndsep, % inner sep for indicatorsplot addresses/.is if=Kaddress, % plot address fieldsplot indicators/.is if=KInd, % plot variable indicators}\pgfkeys{/K,default/.style = { plot addresses = true,plot indicators = true,x bits = 2,y bits = 2,address scale = 0.5,address sep = 1pt,variable names = {$A$,$B$,$C$,$D$,$E$,$F$,$G$},
Click to download: karnaugh-diagram.tex • karnaugh-diagram.pdf
Open in Overleaf: karnaugh-diagram.tex