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


karnaugh-diagram

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 axis
y bits/.estore in = \KYvars, % bits along the vertical axis
variable names/.estore in = \KVars, % comma-separated variable names
label/.estore in = \KLabel, % label for the diagram
label scale/.estore in = \KLabelscale,% scale factor for values
value scale/.estore in = \KValscale, % scale factor for values
variable scale/.estore in = \KVarscale, % scale factor for variables
variable sep/.estore in = \KVarsep, % inner sep for variables
address scale/.estore in = \KAddrscale, % scale factor for adresses
address sep/.estore in = \KAddrsep, % inner sep for adresses
group distance/.estore in = \KGdist, % distance for grouping lines
group color/.estore in = \KGcolor, % grouping color
group linewidth/.estore in = \KGwidth, % grouping line width
group rounded/.estore in = \KGrounded, % grouping rounded corner radius
group opacity/.estore in = \KGopacity, % grouping field opacity
indicator distance/.estore in = \KInddist, % variable indicator distance
indicator linewidth/.estore in = \KIndwidth, % line width for indicators
indicator scale/.estore in = \KIndscale, % scale factor for indicators
indicator sep/.estore in = \KIndsep, % inner sep for indicators
plot addresses/.is if=Kaddress, % plot address fields
plot 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$},
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Click to download: karnaugh-diagram.texkarnaugh-diagram.pdf
Open in Overleaf: karnaugh-diagram.tex