texlive[61614] Master/texmf-dist: karnaugh-map (15jan22)

commits+karl at tug.org commits+karl at tug.org
Sat Jan 15 22:37:34 CET 2022


Revision: 61614
          http://tug.org/svn/texlive?view=revision&revision=61614
Author:   karl
Date:     2022-01-15 22:37:34 +0100 (Sat, 15 Jan 2022)
Log Message:
-----------
karnaugh-map (15jan22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/karnaugh-map/README.md
    trunk/Master/texmf-dist/doc/latex/karnaugh-map/karnaugh-map.pdf
    trunk/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx
    trunk/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty

Modified: trunk/Master/texmf-dist/doc/latex/karnaugh-map/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/karnaugh-map/README.md	2022-01-15 21:37:19 UTC (rev 61613)
+++ trunk/Master/texmf-dist/doc/latex/karnaugh-map/README.md	2022-01-15 21:37:34 UTC (rev 61614)
@@ -10,6 +10,8 @@
     pdflatex karnaugh-map.dtx
 
 ## Dependencies
+* keyval
+* kvoptions
 * tikz
 * xparse
 * xstring

Modified: trunk/Master/texmf-dist/doc/latex/karnaugh-map/karnaugh-map.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx	2022-01-15 21:37:19 UTC (rev 61613)
+++ trunk/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx	2022-01-15 21:37:34 UTC (rev 61614)
@@ -1,5 +1,5 @@
 % \iffalse meta-comment
-% Copyright (C) 2015, 2016, 2017 Mattias Jacobsson and contributors
+% Copyright (C) 2015-2022 Mattias Jacobsson and contributors
 % This work, karnaugh-map, is written from the ground up by Mattias Jacobsson. However the general implementation idea is based on the work published on [TeX - LaTeX Stack Exchange](https://tex.stackexchange.com) by [Ignasi](https://tex.stackexchange.com/users/1952/ignasi) found [here](https://tex.stackexchange.com/a/140581) and [here](https://tex.stackexchange.com/a/36879) which is licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). karnaugh-map is therefore licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). Contributors include [Oscar Gustafsson](https://github.com/oscargus).
 % \fi
 %
@@ -7,12 +7,12 @@
 %
 %<package>
 %<package>%%
-%<package>%% Copyright (C) 2015, 2016, 2017 Mattias Jacobsson and contributors
+%<package>%% Copyright (C) 2015-2022 Mattias Jacobsson and contributors
 %<package>%% This work, karnaugh-map, is written from the ground up by Mattias Jacobsson. However the general implementation idea is based on the work published on [TeX - LaTeX Stack Exchange](https://tex.stackexchange.com) by [Ignasi](https://tex.stackexchange.com/users/1952/ignasi) found [here](https://tex.stackexchange.com/a/140581) and [here](https://tex.stackexchange.com/a/36879) which is licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). karnaugh-map is therefore licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). Contributors include [Oscar Gustafsson](https://github.com/oscargus).
 %<package>%%
 %<package>
 %<package>\NeedsTeXFormat{LaTeX2e}
-%<package>\ProvidesPackage{karnaugh-map}[2017/02/20 v1.1 Draw Karnaugh Maps]
+%<package>\ProvidesPackage{karnaugh-map}[2022/01/15 v2.0 Draw Karnaugh Maps]
 %
 %<*driver>
   \documentclass{ltxdoc}
@@ -69,7 +69,7 @@
 % \end{abstract}
 % \begin{figure}[H]
 %   \centering
-%   \begin{karnaugh-map}[2][2][1][$X_0$][$X_1$]
+%   \begin{karnaugh-map}[2][2][1]
 %     \minterms{1,2}
 %     \autoterms[0]
 %     \implicant{1}{1}
@@ -91,7 +91,9 @@
 %% Dependencies
 %%
 
-%% parsing arguments
+%% parsing arguments and options
+\RequirePackage{kvoptions}
+\RequirePackage{keyval}
 \RequirePackage{xparse}
 
 %% working with strings
@@ -105,15 +107,17 @@
 %% Helpers
 %%
 
-%% convert decimal to color
-\newcommand{\@karnaughmap at func@decimaltocolor@}[1]{%
-  \ifnum#1=0 red\fi
-  \ifnum#1=1 green\fi
-  \ifnum#1=2 yellow\fi
-  \ifnum#1=3 cyan\fi
-  \ifnum#1=4 blue\fi
-  \ifnum#1=5 magenta\fi
-  \ifnum#1>5 cyan\fi
+%% update color
+\newcommand{\@karnaughmap at func@updatecolor@}{%
+  % jump to next color
+  \advance\@karnaughmap at var@colorindex@ by 1\relax
+  \advance\@karnaughmap at var@colorindexnext@ by 1\relax
+  % store color
+  \StrBetween[\@karnaughmap at var@colorindex@,\@karnaughmap at var@colorindexnext@]{\@karnaughmap at var@colors@}{,}{,}[\@karnaughmap at var@color@]
+  % if color is empty (eg. when there are more implicants than colors) return cyan
+  \IfStrEq{\@karnaughmap at var@color@}{}{%
+    \renewcommand{\@karnaughmap at var@color@}{cyan}
+  }{}
 }
 
 %% convert decimal to binary 6-bit
@@ -200,6 +204,36 @@
 \newcommand{\@karnaughmap at var@mapsizey@}{0}
 \newcommand{\@karnaughmap at var@mapsizez@}{0}
 
+%% store map labels
+\newcommand{\@karnaughmap at var@labelA@}{$X_0$}
+\newcommand{\@karnaughmap at var@labelB@}{$X_1$}
+\newcommand{\@karnaughmap at var@labelC@}{$X_2$}
+\newcommand{\@karnaughmap at var@labelD@}{$X_3$}
+\newcommand{\@karnaughmap at var@labelE@}{$X_4$}
+\newcommand{\@karnaughmap at var@labelF@}{$X_5$}
+\newcommand{\@karnaughmap at var@labelX@}{$X_1$$X_0$}
+\newcommand{\@karnaughmap at var@labelY@}{$X_3$$X_2$}
+\newcommand{\@karnaughmap at var@labelZ@}{$X_5$$X_4$}
+%% if map labels are defined using API version unknown(0), v1(1) or v2(2)
+\newcommand{\@karnaughmap at var@labeltype@}{0}
+
+%% store colors
+\newcommand{\@karnaughmap at var@colors@}{,red,green,yellow,cyan,blue,magenta,}
+\newcommand{\@karnaughmap at var@color@}{}
+
+%% declare package and environment options
+%% package options
+\SetupKeyvalOptions{
+  family=@karnaughmap at option,
+  prefix=@karnaughmap at option@,
+}
+\DeclareStringOption[middle]{label}[middle]
+\DeclareStringOption[]{implicantcolors}[]
+\ProcessKeyvalOptions*
+%% environment options
+\define at key{karnaugh-map}{label}[middle]{\renewcommand{\@karnaughmap at option@label}{#1}}
+\define at key{karnaugh-map}{implicantcolors}[]{\renewcommand{\@karnaughmap at option@implicantcolors}{#1}}
+
 %% render in black and white or color default to '0'(false/color)
 \newcommand{\@karnaughmap at var@bw@}{0}
 % ^^A ##########################################################################
@@ -232,6 +266,7 @@
 %    \end{macrocode}
 % \fi
 % \begin{environment}{karnaugh-map}
+%    \changes{v2.0}{2018/12/13}{API change: variable labels are now specified separately.}
 %    The |karnaugh-map| environment is the base for this package, and everything related to this package happens inside an instances of this environment.
 %
 %    \textbf{Usage:}
@@ -238,15 +273,21 @@
 %
 %    \begin{tabularx}{\textwidth}{l X}
 %      \small{|\begin{karnaugh-map}|} & \\
+%      \small{\parg{options}}     & \small{See section \ref{sec:usage:options}. Default: ''''} \\
 %      \small{\meta{*}}           & \small{One asterisk for black and white implicants, non for colorized implicants} \\
 %      \small{\oarg{X size}}      & \small{Number of X-axis cells. Default: ''4''} \\
 %      \small{\oarg{Y size}}      & \small{Number of Y-axis cells. Default: ''4''} \\
 %      \small{\oarg{Z size}}      & \small{Number of X$\times$Y submaps. Default: ''1''} \\
-%      \small{\oarg{X label}}     & \small{Label for the X-axis. Default: ''$X_1X_0$''} \\
-%      \small{\oarg{Y label}}     & \small{Label for the Y-axis. Default: ''$X_3X_2$''} \\
-%      \small{\oarg{Z label}}     & \small{Label for the submaps. Default: ''$X_5X_4$''} \\
+%      \small{\oarg{label A}}\footnotemark     & \small{Label for the variable one. Default: ''$X_0$''} \\
+%      \small{\oarg{label B}}\footnotemark[\value{footnote}]     & \small{Label for the variable two. Default: ''$X_1$''} \\
+%      \small{\oarg{label C}}\footnotemark[\value{footnote}]     & \small{Label for the variable three. Default: ''$X_2$''} \\
+%      \small{\oarg{label D}}     & \small{Label for the variable four. Default: ''$X_3$''} \\
+%      \small{\oarg{label E}}     & \small{Label for the variable five. Default: ''$X_4$''} \\
+%      \small{\oarg{label F}}     & \small{Label for the variable six. Default: ''$X_5$''} \\
 %    \end{tabularx}
 %
+%     \footnotetext{The arguments \oarg{label A}, \oarg{label B}, and \oarg{label C} are currently backward compatible with \oarg{X label}, \oarg{Y label}, and \oarg{Z label} in version v1's definition of the |karnaugh-map| environment. This works through a heuristic method. However the v1 definition is now deprecated and this backward compatibility may disappear in a later version.}
+%
 %    \textbf{Example:}
 %
 %    Four variable karnaugh map, colorized, with X label $X_1X_0$, and Y label $X_3X_2$.
@@ -256,12 +297,12 @@
 %
 %or
 %
-%\begin{karnaugh-map}[4][4][1][$X_1X_0$][$X_3X_2$]
+%\begin{karnaugh-map}[4][4][1][$X_0$][$X_1$][$X_2$][$X_3$]
 %\end{karnaugh-map}
 %    \end{verbatim}
 %    Six variable karnaugh map, black and white, with X label $ba$, Y label $dc$, and Z label $fe$.
 %    \begin{verbatim}
-%\begin{karnaugh-map}*[4][4][4][$ba$][$dc$][$fe$]
+%\begin{karnaugh-map}*[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
 %\end{karnaugh-map}
 %    \end{verbatim}
 % \iffalse code
@@ -271,15 +312,27 @@
 % ^^A ####                              CODE                                ####
 % ^^A ##########################################################################
 % ^^A ##########################################################################
-\NewDocumentEnvironment{karnaugh-map}{s O{4} O{4} O{1} O{$X_1X_0$} O{$X_3X_2$} O{$X_5X_4$}} {%
+\NewDocumentEnvironment{karnaugh-map}{D(){} s O{4} O{4} O{1}} {%
   \begingroup
-    % store map size {[START]
-      \renewcommand{\@karnaughmap at var@mapsizex@}{#2}%
-      \renewcommand{\@karnaughmap at var@mapsizey@}{#3}%
-      \renewcommand{\@karnaughmap at var@mapsizez@}{#4}%
-    % [END]}
+    % parse environment options
+    \setkeys{karnaugh-map}{#1}%
+    %
+    % check if implicant colors are specified
+    \IfStrEq{\@karnaughmap at option@implicantcolors}{}{}{%
+      % ensure no empty colors are specified
+      \IfSubStr{\@karnaughmap at option@implicantcolors}{,,}{%
+        \PackageError{karnaugh-map}{%
+          Incorrect usage of option implicantcolors%
+        }{%
+          The option implicantcolors is a comma separated list of colors with no gap. You used two consecutive commas.%
+        }%
+      }{}%
+      % add comma at beginning and end. then remove duplicates
+      \StrSubstitute{,\@karnaughmap at option@implicantcolors,}{,,}{,}[\@karnaughmap at var@colors@]%
+    }%
+    %
     % determinate if markings should be color or black and white
-    \IfBooleanTF{#1}{%
+    \IfBooleanTF{#2}{%
       % should be black and white
       \renewcommand{\@karnaughmap at var@bw@}{1}%
     }{%
@@ -287,86 +340,216 @@
       \renewcommand{\@karnaughmap at var@bw@}{0}%
     }%
     %
-    % find matching matrix template and alignment parameters {[START]
-      \newcommand{\@karnaughmap at local@matrixtemplate@}{0}% '0' is considered as missing matrix template
-      \newcommand{\@karnaughmap at local@maprealignmentx@}{0}%
-      \newcommand{\@karnaughmap at local@maprealignmenty@}{0}%
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                       0 \&                       1 \& \phantom{0} \\
-                     0 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&             \\
-                     1 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&             \\
-          \phantom{0}  \&                         \&                         \&             \\
-        }%
+    % store map size {[START]
+      \renewcommand{\@karnaughmap at var@mapsizex@}{#3}%
+      \renewcommand{\@karnaughmap at var@mapsizey@}{#4}%
+      \renewcommand{\@karnaughmap at var@mapsizez@}{#5}%
+    % [END]}
+    %
+    % only 9 arguments are directly supported. jump to helper function
+    % to parse remaining arguments and finish initialization.
+    \@karnaughmap at func@karnaughstart@%
+}{
+    \end{tikzpicture}
+  \endgroup
+}
+\DeclareDocumentCommand{\@karnaughmap at func@karnaughstart@}{oooooo} {%
+  % parse label args {[START]
+    % try to maintain backwards compatibility with v1 while enabling users to separatly
+    % specify each input label variable
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
+      % no difference
+      \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+      \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+      \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelA@}%
+      \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelB@}%
+      \renewcommand{\@karnaughmap at var@labeltype@}{2}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelC@\@karnaughmap at var@labelB@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                       0 \&                       1 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&              \\
-                    01 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&              \\
-                    11 \& |(000110)|  \phantom{0} \& |(000111)|  \phantom{0} \&              \\
-                    10 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    0  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
-                    1  \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{#3}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \IfValueT{#5}{\renewcommand{\@karnaughmap at var@labelE@}{#5}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{\@karnaughmap at var@labelE@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-        }%
-        \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{#3}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \IfValueT{#5}{\renewcommand{\@karnaughmap at var@labelE@}{#5}}%
+        \IfValueT{#6}{\renewcommand{\@karnaughmap at var@labelF@}{#6}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{\@karnaughmap at var@labelF@\@karnaughmap at var@labelE@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-                    00 \& |(100000)|  \phantom{0} \& |(100001)|  \phantom{0} \& |(100011)|  \phantom{0} \& |(100010)|  \phantom{0} \&              \& |(110000)|  \phantom{0} \& |(110001)|  \phantom{0} \& |(110011)|  \phantom{0} \& |(110010)|  \phantom{0} \&              \\
-                    01 \& |(100100)|  \phantom{0} \& |(100101)|  \phantom{0} \& |(100111)|  \phantom{0} \& |(100110)|  \phantom{0} \&              \& |(110100)|  \phantom{0} \& |(110101)|  \phantom{0} \& |(110111)|  \phantom{0} \& |(110110)|  \phantom{0} \&              \\
-                    11 \& |(101100)|  \phantom{0} \& |(101101)|  \phantom{0} \& |(101111)|  \phantom{0} \& |(101110)|  \phantom{0} \&              \& |(111100)|  \phantom{0} \& |(111101)|  \phantom{0} \& |(111111)|  \phantom{0} \& |(111110)|  \phantom{0} \&              \\
-                    10 \& |(101000)|  \phantom{0} \& |(101001)|  \phantom{0} \& |(101011)|  \phantom{0} \& |(101010)|  \phantom{0} \&              \& |(111000)|  \phantom{0} \& |(111001)|  \phantom{0} \& |(111011)|  \phantom{0} \& |(111010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-        }%
-        \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
-        \renewcommand{\@karnaughmap at local@maprealignmenty@}{-2.5}%
-      \fi
-    % [END]}
-    % test if a matrix template is found or not(aka "\@karnaughmap at local@matrixtemplate@" equals to '0')
-    \ifnum0=\@karnaughmap at local@matrixtemplate@
-      % print error if no template could be found
-      \PackageError{karnaugh-map}{%
-        Can not find a template fitting your specification (\@karnaughmap at var@mapsizex@\space x \@karnaughmap at var@mapsizey@\space x \@karnaughmap at var@mapsizez@)%
-      }{%
-        Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
+    \fi
+    % warn when using API v1
+    \ifnum\@karnaughmap at var@labeltype@=1
+      \PackageWarning{karnaugh-map}{%
+        The API for specifying variable labels have been updated. You are currently using the old API(v1).
+        In the new API each variable label is specified separately. See the documentation for more details.
+        Backward compatibility may disappear in a future release.%
       }%
     \fi
-    \begin{tikzpicture}
-      % grid
+  % [END]}
+  %
+  % find matching matrix template and alignment parameters {[START]
+    \newcommand{\@karnaughmap at local@matrixtemplate@}{0}% '0' is considered as missing matrix template
+    \newcommand{\@karnaughmap at local@maprealignmentx@}{0}%
+    \newcommand{\@karnaughmap at local@maprealignmenty@}{0}%
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                       0 \&                       1 \& \phantom{0} \\
+                   0 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&             \\
+                   1 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&             \\
+        \phantom{0}  \&                         \&                         \&             \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                       0 \&                       1 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&              \\
+                  01 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&              \\
+                  11 \& |(000110)|  \phantom{0} \& |(000111)|  \phantom{0} \&              \\
+                  10 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  0  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
+                  1  \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+      }%
+      \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+                  00 \& |(100000)|  \phantom{0} \& |(100001)|  \phantom{0} \& |(100011)|  \phantom{0} \& |(100010)|  \phantom{0} \&              \& |(110000)|  \phantom{0} \& |(110001)|  \phantom{0} \& |(110011)|  \phantom{0} \& |(110010)|  \phantom{0} \&              \\
+                  01 \& |(100100)|  \phantom{0} \& |(100101)|  \phantom{0} \& |(100111)|  \phantom{0} \& |(100110)|  \phantom{0} \&              \& |(110100)|  \phantom{0} \& |(110101)|  \phantom{0} \& |(110111)|  \phantom{0} \& |(110110)|  \phantom{0} \&              \\
+                  11 \& |(101100)|  \phantom{0} \& |(101101)|  \phantom{0} \& |(101111)|  \phantom{0} \& |(101110)|  \phantom{0} \&              \& |(111100)|  \phantom{0} \& |(111101)|  \phantom{0} \& |(111111)|  \phantom{0} \& |(111110)|  \phantom{0} \&              \\
+                  10 \& |(101000)|  \phantom{0} \& |(101001)|  \phantom{0} \& |(101011)|  \phantom{0} \& |(101010)|  \phantom{0} \&              \& |(111000)|  \phantom{0} \& |(111001)|  \phantom{0} \& |(111011)|  \phantom{0} \& |(111010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+      }%
+      \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+      \renewcommand{\@karnaughmap at local@maprealignmenty@}{-2.5}%
+    \fi
+  % [END]}
+  % test if a matrix template is found or not(aka "\@karnaughmap at local@matrixtemplate@" equals to '0')
+  \ifnum0=\@karnaughmap at local@matrixtemplate@
+    % print error if no template could be found
+    \PackageError{karnaugh-map}{%
+      Can not find a template fitting your specification (\@karnaughmap at var@mapsizex@\space x \@karnaughmap at var@mapsizey@\space x \@karnaughmap at var@mapsizez@)%
+    }{%
+      Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
+    }%
+  \fi
+  \begin{tikzpicture}
+    % grid {[START]
       % for all dimensions
       \draw[color=black, ultra thin] (0,0) grid (\@karnaughmap at var@mapsizex@,\@karnaughmap at var@mapsizey@);
       % when there are 2 sub maps
@@ -379,39 +562,64 @@
         \draw[color=black, ultra thin] (0,-5) grid (4,-1);
         \draw[color=black, ultra thin] (5,-5) grid (9,-1);
       \fi
-      % labels
-      % for all dimensions
-      \node[above] at (\@karnaughmap at var@mapsizex@*0.5,\@karnaughmap at var@mapsizey at +0.9) {\small{#5}};
-      \node[left] at (-0.9,\@karnaughmap at var@mapsizey@*0.5) {\small{#6}};
-      % when there are 2 sub maps
-      \ifnum\@karnaughmap at var@mapsizez@=2
-        \node[above] at (7,4.9) {\small{#5}};
-        % extra sub maps labels
-        \node[below] at (2,-0.1) {\small{#7$=0$}};
-        \node[below] at (7,-0.1) {\small{#7$=1$}};
-      \fi
-      % when there are 4 sub maps
-      \ifnum\@karnaughmap at var@mapsizez@=4
-        \node[above] at (7,4.9) {\small{#5}};
-        \node[left] at (-0.9,-3) {\small{#6}};
-        % extra sub maps labels
-        \node[below] at (2,-0.1) {\small{#7$=00$}};
-        \node[below] at (7,-0.1) {\small{#7$=01$}};
-        \node[below] at (2,-5.1) {\small{#7$=10$}};
-        \node[below] at (7,-5.1) {\small{#7$=11$}};
-      \fi
-      % data
-      \matrix[
-        matrix of nodes,
-        ampersand replacement=\&,
-        column sep={1cm,between origins},
-        row sep={1cm,between origins},
-      ] at (\@karnaughmap at var@mapsizex@*0.5+\@karnaughmap at local@maprealignmentx@,\@karnaughmap at var@mapsizey@*0.5+\@karnaughmap at local@maprealignmenty@) {
-        \@karnaughmap at local@matrixtemplate@%
-      };
-}{
-    \end{tikzpicture}
-  \endgroup
+    % [END]}
+    % labels {[START]
+      \IfStrEq{\@karnaughmap at option@label}{corner}{%
+        % if variables should be positioned at the corner
+        %
+        % for all dimensions
+        \draw[color=black, ultra thin] (0,\@karnaughmap at var@mapsizey@) --
+          node[pos=0.5, above right, anchor=south, rotate=-45] {\small{\@karnaughmap at var@labelX@}}
+          node[pos=0.5, below left, anchor=north, rotate=-45] {\small{\@karnaughmap at var@labelY@}}
+          ++(135:1);
+        % when there are 2 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=2
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=0$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=1$}};
+        \fi
+        % when there are 4 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=4
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=00$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=01$}};
+          \node[below] at (2,-5.1) {\small{\@karnaughmap at var@labelZ@$=10$}};
+          \node[below] at (7,-5.1) {\small{\@karnaughmap at var@labelZ@$=11$}};
+        \fi
+      }{%
+        % if variables should be positioned in the middle(top and side). Default.
+        %
+        % for all dimensions
+        \node[above] at (\@karnaughmap at var@mapsizex@*0.5,\@karnaughmap at var@mapsizey at +0.9) {\small{\@karnaughmap at var@labelX@}};
+        \node[left] at (-0.9,\@karnaughmap at var@mapsizey@*0.5) {\small{\@karnaughmap at var@labelY@}};
+        % when there are 2 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=2
+          \node[above] at (7,4.9) {\small{\@karnaughmap at var@labelX@}};
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=0$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=1$}};
+        \fi
+        % when there are 4 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=4
+          \node[above] at (7,4.9) {\small{\@karnaughmap at var@labelX@}};
+          \node[left] at (-0.9,-3) {\small{\@karnaughmap at var@labelY@}};
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=00$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=01$}};
+          \node[below] at (2,-5.1) {\small{\@karnaughmap at var@labelZ@$=10$}};
+          \node[below] at (7,-5.1) {\small{\@karnaughmap at var@labelZ@$=11$}};
+        \fi
+      }
+    % [END]}
+    % data
+    \matrix[
+      matrix of nodes,
+      ampersand replacement=\&,
+      column sep={1cm,between origins},
+      row sep={1cm,between origins},
+    ] at (\@karnaughmap at var@mapsizex@*0.5+\@karnaughmap at local@maprealignmentx@,\@karnaughmap at var@mapsizey@*0.5+\@karnaughmap at local@maprealignmenty@) {
+      \@karnaughmap at local@matrixtemplate@%
+    };
 }
 % ^^A ##########################################################################
 % ^^A ##########################################################################
@@ -746,7 +954,9 @@
 
 %% keep track of used colors
 \newcount\@karnaughmap at var@colorindex@\relax
+\newcount\@karnaughmap at var@colorindexnext@\relax
 \@karnaughmap at var@colorindex@=0\relax
+\@karnaughmap at var@colorindexnext@=1\relax
 
 % ^^A ##########################################################################
 % ^^A ##########################################################################
@@ -780,10 +990,10 @@
 %\end{karnaugh-map}
 %      \end{verbatim}
 %      \columnbreak
-%      \resizebox{\columnwidth}{!}{
+%      \resizebox{\columnwidth}{!}{%
 %        \begin{karnaugh-map}
 %          \implicant{5}{15}
-%        \end{karnaugh-map}
+%        \end{karnaugh-map}%
 %      }
 %    \end{multicols}
 %    \begin{multicols}{2}
@@ -794,10 +1004,10 @@
 %\end{karnaugh-map}
 %      \end{verbatim}
 %      \columnbreak
-%      \resizebox{\columnwidth}{!}{
+%      \resizebox{\columnwidth}{!}{%
 %        \begin{karnaugh-map}[4][4][4]
 %          \implicant{0}{0}[0,1,2,3]
-%        \end{karnaugh-map}
+%        \end{karnaugh-map}%
 %      }
 %    \end{multicols}
 % \iffalse code
@@ -811,6 +1021,9 @@
   % bail if outside environment karnaugh-map
   \@karnaughmap at func@bailoutsideenvironment@{}
   %
+  % fetch new color
+  \@karnaughmap at func@updatecolor@{}
+  %
   \begingroup
     % loop through specified sub maps
     \foreach \map in {#3} {%
@@ -830,7 +1043,7 @@
         \ifnum0=\@karnaughmap at var@bw@
           \fill[
             rounded corners=3pt,
-            fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+            fill=\@karnaughmap at var@color@,
             fill opacity=0.25,
           ] {
             ($(\@karnaughmap at func@decimaltobin@{\@karnaughmap at local@northwest@}.center)+(-0.3,0.3)$)
@@ -854,8 +1067,6 @@
       \fi
     }
   \endgroup
-  % mark color as used
-  \advance\@karnaughmap at var@colorindex@ by 1\relax
 }
 % ^^A ##########################################################################
 % ^^A ##########################################################################
@@ -891,10 +1102,10 @@
 %\end{karnaugh-map}
 %      \end{verbatim}
 %      \columnbreak
-%      \resizebox{\columnwidth}{!}{
+%      \resizebox{\columnwidth}{!}{%
 %        \begin{karnaugh-map}
 %          \implicantedge{4}{12}{6}{14}
-%        \end{karnaugh-map}
+%        \end{karnaugh-map}%
 %      }
 %    \end{multicols}
 % \iffalse code
@@ -908,6 +1119,9 @@
   % bail if outside environment karnaugh-map
   \@karnaughmap at func@bailoutsideenvironment@{}
   %
+  % fetch new color
+  \@karnaughmap at func@updatecolor@{}
+  %
   \begingroup
     % helper variables {[START]
       \newcommand{\@karnaughmap at local@orientation@}{0} % '0' is a vertical and '1' is a horizontal implicant
@@ -1019,7 +1233,7 @@
           \ifnum0=\@karnaughmap at var@bw@
             \fill[
               sharp corners,
-              fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+              fill=\@karnaughmap at var@color@,
               fill opacity=0.25,
             ] {
               \@karnaughmap at local@fillcontent@%
@@ -1040,8 +1254,6 @@
       \fi
     }
   \endgroup
-  % mark color as used
-  \advance\@karnaughmap at var@colorindex@ by 1\relax
 }
 % ^^A ##########################################################################
 % ^^A ##########################################################################
@@ -1073,10 +1285,10 @@
 %\end{karnaugh-map}
 %      \end{verbatim}
 %      \columnbreak
-%      \resizebox{\columnwidth}{!}{
+%      \resizebox{\columnwidth}{!}{%
 %        \begin{karnaugh-map}[4][4][4]
 %          \implicantcorner[0,2]
-%        \end{karnaugh-map}
+%        \end{karnaugh-map}%
 %      }
 %    \end{multicols}
 % \iffalse code
@@ -1092,6 +1304,8 @@
   %
   % make sure "\implicantcorner" only are used on 4x4 maps
   \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@=44
+    % fetch new color
+    \@karnaughmap at func@updatecolor@{}
     % loop through specified sub maps
     \foreach \map in {#1} {%
       % make sure we don't try to draw on non existing sub maps
@@ -1115,7 +1329,7 @@
           \ifnum0=\@karnaughmap at var@bw@
             \fill[
               sharp corners,
-              fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+              fill=\@karnaughmap at var@color@,
               fill opacity=0.25,
             ]
             ($(\@karnaughmap at func@decimaltobin@{\@karnaughmap at local@coordinate@}.center)+(-.6*\@karnaughmap at local@mirrorx@,.6*\@karnaughmap at local@mirrory@)$)
@@ -1144,8 +1358,6 @@
         }
       \fi
     }
-    % mark color as used
-    \advance\@karnaughmap at var@colorindex@ by 1\relax
   \else
     % print error if "\implicantcorner" are used on non 4x4 map
     \PackageError{karnaugh-map}{%
@@ -1165,11 +1377,55 @@
 % \end{macro}
 %
 % \newpage
+% \subsection{Options}\label{sec:usage:options}
+% There are two available method for customizing the package, either globally or locally to one |karnaugh-map| environment. Multiple options are comma separated. The global options are defined when the package is loaded.
+%    \begin{verbatim}
+%\usepackage[options]{karnaugh-map}
+%\end{verbatim}
+%
+% The local options, which have precedence over the global options, are defined when a |karnaugh-map| environment is started.
+%
+%    \begin{verbatim}
+%\begin{karnaugh-map}(options)
+%\end{karnaugh-map}
+%\end{verbatim}
+%
+% \textbf{Available options are:}
+%
+% \texttt{implicantcolors}: Use this option to specify a comma separated list of implicant colors to be used. Each color is used in order and only once per map, when there are no colors left the remaining implicants are colored in \texttt{cyan}. Note; the opacity of the colors are turned down. Default: \texttt{\{red,green,yellow,cyan,blue,magenta\}}.
+% \changes{v2.0}{2021/12/15}{Support custom implicant colors}
+%
+% \begin{figure}[H]
+%   \centering
+%   \resizebox{.25\textwidth}{!}{%
+%     \begin{karnaugh-map}(implicantcolors={orange,violet})[2][2][1]
+%       \minterms{1,2}
+%       \autoterms[0]
+%       \implicant{1}{1}
+%       \implicant{2}{2}
+%     \end{karnaugh-map}%
+%   }
+% \end{figure}
+%
+% \texttt{label}: The input variable labels can either be positioned on the top and the side of the karnaugh-map(\texttt{label=middle}). Alternatively they can be positioned in the top--left corner(\texttt{label=corner}). Default: \texttt{middle}.
+% \changes{v2.0}{2018/11/20}{Support alternate input label position}
+%
+% \begin{figure}[H]
+%   \centering
+%   \resizebox{.75\textwidth}{!}{%
+%     \begin{karnaugh-map}
+%     \end{karnaugh-map}%
+%     \begin{karnaugh-map}(label=corner)
+%     \end{karnaugh-map}%
+%   }
+% \end{figure}
+%
+% \newpage
 % \section{Examples}
 %   \begin{multicols}{2}
 %     [Draw a karnaugh map for \small{$f(a,b,c,d,e,f) =$\\$\Sigma(0,1,2,3,8,13,17,20,22,28,33,32,30,19,40,35,49,42,34,10,60,54,62,51,52)$\\$+d(15,45,47)$}.]
 %     \begin{verbatim}
-%\begin{karnaugh-map}[4][4][4][$ba$][$dc$][$fe$]
+%\begin{karnaugh-map}[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
 %  \minterms{0,1,2,3,8,13,17,20,22,28,
 %    33,32,30,19,40,35,49,42,34,10,60,
 %    54,62,51,52}
@@ -1182,8 +1438,9 @@
 %\end{karnaugh-map}
 %     \end{verbatim}
 %     \columnbreak
-%     \resizebox{\columnwidth}{!}{
-%       \begin{karnaugh-map}[4][4][4][$ba$][$dc$][$fe$]
+%     \vspace*{0.25em}
+%     \resizebox{\columnwidth}{!}{%
+%       \begin{karnaugh-map}[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
 %         \minterms{0,1,2,3,8,13,17,20,22,28,33,32,30,19,40,35,49,42,34,10,60,54,62,51,52}
 %         \indeterminants{15,45,47}
 %         \autoterms[0]
@@ -1191,7 +1448,7 @@
 %         \implicant{1}{3}[0,1,2,3]
 %         \implicantedge{4}{12}{6}{14}[1,3]
 %         \implicant{13}{15}[0,2]
-%       \end{karnaugh-map}
+%       \end{karnaugh-map}%
 %     }
 %   \end{multicols}
 %
@@ -1198,7 +1455,7 @@
 %   \begin{multicols}{2}
 %     [Draw a karnaugh map for \small{$f(X_0,X_1) = \Pi(0,2,3)$} in black and white.]
 %     \begin{verbatim}
-%\begin{karnaugh-map}*[2][2][1][$X_0$][$X_1$]
+%\begin{karnaugh-map}*[2][2][1]
 %  \maxterms{0,2,3}
 %  \autoterms[1]
 %  \implicant{1}{1}
@@ -1205,12 +1462,12 @@
 %\end{karnaugh-map}
 %     \end{verbatim}
 %     \columnbreak
-%     \resizebox{\columnwidth}{!}{
-%       \begin{karnaugh-map}*[2][2][1][$X_0$][$X_1$]
+%     \resizebox{\columnwidth}{!}{%
+%       \begin{karnaugh-map}*[2][2][1]
 %         \maxterms{0,2,3}
 %         \autoterms[1]
 %         \implicant{1}{1}
-%       \end{karnaugh-map}
+%       \end{karnaugh-map}%
 %     }
 %   \end{multicols}
 %
@@ -1218,7 +1475,7 @@
 %   \begin{multicols}{2}
 %     [Draw a variable entered map.]
 %     \begin{verbatim}
-%\begin{karnaugh-map}[4][2][1][$ab$][$c$]
+%\begin{karnaugh-map}[4][2][1][$a$][$b$][$c$]
 %  \maxterms{0,2,4,5,6}
 %  \minterms{3}
 %  \terms{1}{$d$}
@@ -1228,8 +1485,8 @@
 %\end{karnaugh-map}
 %     \end{verbatim}
 %     \columnbreak
-%     \resizebox{\columnwidth}{!}{
-%       \begin{karnaugh-map}[4][2][1][$ab$][$c$]
+%     \resizebox{\columnwidth}{!}{%
+%       \begin{karnaugh-map}[4][2][1][$a$][$b$][$c$]
 %         \maxterms{0,2,4,5,6}
 %         \minterms{3}
 %         \terms{1}{$d$}
@@ -1236,12 +1493,14 @@
 %         \terms{7}{$d'$}
 %         \implicant{1}{3}
 %         \implicant{3}{7}
-%       \end{karnaugh-map}
+%       \end{karnaugh-map}%
 %     }
 %   \end{multicols}
 %
 % \section{Dependencies}
 % \begin{itemize}
+%   \item keyval
+%   \item kvoptions
 %   \item tikz
 %   \item xparse
 %   \item xstring
@@ -1252,14 +1511,14 @@
 % \subsection*{Resizing}
 % The karnaugh maps produced with this package have a prespecified size which can not be changed. However you can resize the karnaugh map to your desired size. Resizing can be done using the |\resizebox| command from the graphicx package. Scaling the karnaugh map to fill the column width while preserving the aspect ratio can be done as follows.
 % \begin{verbatim}
-%\resizebox{\columnwidth}{!}{
+%\resizebox{\columnwidth}{!}{%
 %  \begin{karnaugh-map}
-%  \end{karnaugh-map}
+%  \end{karnaugh-map}%
 %}
 % \end{verbatim}
 %
 % \subsection*{Comma separated lists}
-% Anywhere in this package where a comma separated list is used data should only be comma separated. Therefore a comma and space separeated list will for example \textit{not} work properly.
+% Anywhere in this package where a comma separated list is used data should only be comma separated. Therefore a comma and space separated list will for example \textit{not} work properly.
 %
 % An example of errorious usage related to the \small{\marg{cells}} parameter in the terms related commands can result in multiple zeros, ones and other terms overlapping in the same cell in the outputted karnaugh map.
 %

Modified: trunk/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty	2022-01-15 21:37:19 UTC (rev 61613)
+++ trunk/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty	2022-01-15 21:37:34 UTC (rev 61614)
@@ -10,18 +10,20 @@
 %% 
 
 %%
-%% Copyright (C) 2015, 2016, 2017 Mattias Jacobsson and contributors
+%% Copyright (C) 2015-2022 Mattias Jacobsson and contributors
 %% This work, karnaugh-map, is written from the ground up by Mattias Jacobsson. However the general implementation idea is based on the work published on [TeX - LaTeX Stack Exchange](https://tex.stackexchange.com) by [Ignasi](https://tex.stackexchange.com/users/1952/ignasi) found [here](https://tex.stackexchange.com/a/140581) and [here](https://tex.stackexchange.com/a/36879) which is licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). karnaugh-map is therefore licensed under [CC BY-SA](https://creativecommons.org/licenses/by-sa/3.0/). Contributors include [Oscar Gustafsson](https://github.com/oscargus).
 %%
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{karnaugh-map}[2017/02/20 v1.1 Draw Karnaugh Maps]
+\ProvidesPackage{karnaugh-map}[2022/01/15 v2.0 Draw Karnaugh Maps]
 
 %%
 %% Dependencies
 %%
 
-%% parsing arguments
+%% parsing arguments and options
+\RequirePackage{kvoptions}
+\RequirePackage{keyval}
 \RequirePackage{xparse}
 
 %% working with strings
@@ -35,15 +37,17 @@
 %% Helpers
 %%
 
-%% convert decimal to color
-\newcommand{\@karnaughmap at func@decimaltocolor@}[1]{%
-  \ifnum#1=0 red\fi
-  \ifnum#1=1 green\fi
-  \ifnum#1=2 yellow\fi
-  \ifnum#1=3 cyan\fi
-  \ifnum#1=4 blue\fi
-  \ifnum#1=5 magenta\fi
-  \ifnum#1>5 cyan\fi
+%% update color
+\newcommand{\@karnaughmap at func@updatecolor@}{%
+  % jump to next color
+  \advance\@karnaughmap at var@colorindex@ by 1\relax
+  \advance\@karnaughmap at var@colorindexnext@ by 1\relax
+  % store color
+  \StrBetween[\@karnaughmap at var@colorindex@,\@karnaughmap at var@colorindexnext@]{\@karnaughmap at var@colors@}{,}{,}[\@karnaughmap at var@color@]
+  % if color is empty (eg. when there are more implicants than colors) return cyan
+  \IfStrEq{\@karnaughmap at var@color@}{}{%
+    \renewcommand{\@karnaughmap at var@color@}{cyan}
+  }{}
 }
 
 %% convert decimal to binary 6-bit
@@ -130,6 +134,36 @@
 \newcommand{\@karnaughmap at var@mapsizey@}{0}
 \newcommand{\@karnaughmap at var@mapsizez@}{0}
 
+%% store map labels
+\newcommand{\@karnaughmap at var@labelA@}{$X_0$}
+\newcommand{\@karnaughmap at var@labelB@}{$X_1$}
+\newcommand{\@karnaughmap at var@labelC@}{$X_2$}
+\newcommand{\@karnaughmap at var@labelD@}{$X_3$}
+\newcommand{\@karnaughmap at var@labelE@}{$X_4$}
+\newcommand{\@karnaughmap at var@labelF@}{$X_5$}
+\newcommand{\@karnaughmap at var@labelX@}{$X_1$$X_0$}
+\newcommand{\@karnaughmap at var@labelY@}{$X_3$$X_2$}
+\newcommand{\@karnaughmap at var@labelZ@}{$X_5$$X_4$}
+%% if map labels are defined using API version unknown(0), v1(1) or v2(2)
+\newcommand{\@karnaughmap at var@labeltype@}{0}
+
+%% store colors
+\newcommand{\@karnaughmap at var@colors@}{,red,green,yellow,cyan,blue,magenta,}
+\newcommand{\@karnaughmap at var@color@}{}
+
+%% declare package and environment options
+%% package options
+\SetupKeyvalOptions{
+  family=@karnaughmap at option,
+  prefix=@karnaughmap at option@,
+}
+\DeclareStringOption[middle]{label}[middle]
+\DeclareStringOption[]{implicantcolors}[]
+\ProcessKeyvalOptions*
+%% environment options
+\define at key{karnaugh-map}{label}[middle]{\renewcommand{\@karnaughmap at option@label}{#1}}
+\define at key{karnaugh-map}{implicantcolors}[]{\renewcommand{\@karnaughmap at option@implicantcolors}{#1}}
+
 %% render in black and white or color default to '0'(false/color)
 \newcommand{\@karnaughmap at var@bw@}{0}
 
@@ -137,15 +171,27 @@
 %% Environment
 %%
 
-\NewDocumentEnvironment{karnaugh-map}{s O{4} O{4} O{1} O{$X_1X_0$} O{$X_3X_2$} O{$X_5X_4$}} {%
+\NewDocumentEnvironment{karnaugh-map}{D(){} s O{4} O{4} O{1}} {%
   \begingroup
-    % store map size {[START]
-      \renewcommand{\@karnaughmap at var@mapsizex@}{#2}%
-      \renewcommand{\@karnaughmap at var@mapsizey@}{#3}%
-      \renewcommand{\@karnaughmap at var@mapsizez@}{#4}%
-    % [END]}
+    % parse environment options
+    \setkeys{karnaugh-map}{#1}%
+    %
+    % check if implicant colors are specified
+    \IfStrEq{\@karnaughmap at option@implicantcolors}{}{}{%
+      % ensure no empty colors are specified
+      \IfSubStr{\@karnaughmap at option@implicantcolors}{,,}{%
+        \PackageError{karnaugh-map}{%
+          Incorrect usage of option implicantcolors%
+        }{%
+          The option implicantcolors is a comma separated list of colors with no gap. You used two consecutive commas.%
+        }%
+      }{}%
+      % add comma at beginning and end. then remove duplicates
+      \StrSubstitute{,\@karnaughmap at option@implicantcolors,}{,,}{,}[\@karnaughmap at var@colors@]%
+    }%
+    %
     % determinate if markings should be color or black and white
-    \IfBooleanTF{#1}{%
+    \IfBooleanTF{#2}{%
       % should be black and white
       \renewcommand{\@karnaughmap at var@bw@}{1}%
     }{%
@@ -153,86 +199,216 @@
       \renewcommand{\@karnaughmap at var@bw@}{0}%
     }%
     %
-    % find matching matrix template and alignment parameters {[START]
-      \newcommand{\@karnaughmap at local@matrixtemplate@}{0}% '0' is considered as missing matrix template
-      \newcommand{\@karnaughmap at local@maprealignmentx@}{0}%
-      \newcommand{\@karnaughmap at local@maprealignmenty@}{0}%
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                       0 \&                       1 \& \phantom{0} \\
-                     0 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&             \\
-                     1 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&             \\
-          \phantom{0}  \&                         \&                         \&             \\
-        }%
+    % store map size {[START]
+      \renewcommand{\@karnaughmap at var@mapsizex@}{#3}%
+      \renewcommand{\@karnaughmap at var@mapsizey@}{#4}%
+      \renewcommand{\@karnaughmap at var@mapsizez@}{#5}%
+    % [END]}
+    %
+    % only 9 arguments are directly supported. jump to helper function
+    % to parse remaining arguments and finish initialization.
+    \@karnaughmap at func@karnaughstart@%
+}{
+    \end{tikzpicture}
+  \endgroup
+}
+\DeclareDocumentCommand{\@karnaughmap at func@karnaughstart@}{oooooo} {%
+  % parse label args {[START]
+    % try to maintain backwards compatibility with v1 while enabling users to separatly
+    % specify each input label variable
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
+      % no difference
+      \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+      \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+      \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelA@}%
+      \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelB@}%
+      \renewcommand{\@karnaughmap at var@labeltype@}{2}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelC@\@karnaughmap at var@labelB@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                       0 \&                       1 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&              \\
-                    01 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&              \\
-                    11 \& |(000110)|  \phantom{0} \& |(000111)|  \phantom{0} \&              \\
-                    10 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    0  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
-                    1  \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \\
-        }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{#3}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \IfValueT{#5}{\renewcommand{\@karnaughmap at var@labelE@}{#5}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{\@karnaughmap at var@labelE@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-        }%
-        \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
+      \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+        % API v1
+        \renewcommand{\@karnaughmap at var@labelX@}{#1}%
+        \renewcommand{\@karnaughmap at var@labelY@}{#2}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{#3}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{1}%
+      }}}}%
+      \ifnum\@karnaughmap at var@labeltype@=0
+        % API v2
+        \IfValueT{#1}{\renewcommand{\@karnaughmap at var@labelA@}{#1}}%
+        \IfValueT{#2}{\renewcommand{\@karnaughmap at var@labelB@}{#2}}%
+        \IfValueT{#3}{\renewcommand{\@karnaughmap at var@labelC@}{#3}}%
+        \IfValueT{#4}{\renewcommand{\@karnaughmap at var@labelD@}{#4}}%
+        \IfValueT{#5}{\renewcommand{\@karnaughmap at var@labelE@}{#5}}%
+        \IfValueT{#6}{\renewcommand{\@karnaughmap at var@labelF@}{#6}}%
+        \renewcommand{\@karnaughmap at var@labelX@}{\@karnaughmap at var@labelB@\@karnaughmap at var@labelA@}%
+        \renewcommand{\@karnaughmap at var@labelY@}{\@karnaughmap at var@labelD@\@karnaughmap at var@labelC@}%
+        \renewcommand{\@karnaughmap at var@labelZ@}{\@karnaughmap at var@labelF@\@karnaughmap at var@labelE@}%
+        \renewcommand{\@karnaughmap at var@labeltype@}{2}%
       \fi
-      \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
-        \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
-                       \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                    00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
-                    01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
-                    11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
-                    10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-                    00 \& |(100000)|  \phantom{0} \& |(100001)|  \phantom{0} \& |(100011)|  \phantom{0} \& |(100010)|  \phantom{0} \&              \& |(110000)|  \phantom{0} \& |(110001)|  \phantom{0} \& |(110011)|  \phantom{0} \& |(110010)|  \phantom{0} \&              \\
-                    01 \& |(100100)|  \phantom{0} \& |(100101)|  \phantom{0} \& |(100111)|  \phantom{0} \& |(100110)|  \phantom{0} \&              \& |(110100)|  \phantom{0} \& |(110101)|  \phantom{0} \& |(110111)|  \phantom{0} \& |(110110)|  \phantom{0} \&              \\
-                    11 \& |(101100)|  \phantom{0} \& |(101101)|  \phantom{0} \& |(101111)|  \phantom{0} \& |(101110)|  \phantom{0} \&              \& |(111100)|  \phantom{0} \& |(111101)|  \phantom{0} \& |(111111)|  \phantom{0} \& |(111110)|  \phantom{0} \&              \\
-                    10 \& |(101000)|  \phantom{0} \& |(101001)|  \phantom{0} \& |(101011)|  \phantom{0} \& |(101010)|  \phantom{0} \&              \& |(111000)|  \phantom{0} \& |(111001)|  \phantom{0} \& |(111011)|  \phantom{0} \& |(111010)|  \phantom{0} \&              \\
-          \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
-        }%
-        \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
-        \renewcommand{\@karnaughmap at local@maprealignmenty@}{-2.5}%
-      \fi
-    % [END]}
-    % test if a matrix template is found or not(aka "\@karnaughmap at local@matrixtemplate@" equals to '0')
-    \ifnum0=\@karnaughmap at local@matrixtemplate@
-      % print error if no template could be found
-      \PackageError{karnaugh-map}{%
-        Can not find a template fitting your specification (\@karnaughmap at var@mapsizex@\space x \@karnaughmap at var@mapsizey@\space x \@karnaughmap at var@mapsizez@)%
-      }{%
-        Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
+    \fi
+    % warn when using API v1
+    \ifnum\@karnaughmap at var@labeltype@=1
+      \PackageWarning{karnaugh-map}{%
+        The API for specifying variable labels have been updated. You are currently using the old API(v1).
+        In the new API each variable label is specified separately. See the documentation for more details.
+        Backward compatibility may disappear in a future release.%
       }%
     \fi
-    \begin{tikzpicture}
-      % grid
+  % [END]}
+  %
+  % find matching matrix template and alignment parameters {[START]
+    \newcommand{\@karnaughmap at local@matrixtemplate@}{0}% '0' is considered as missing matrix template
+    \newcommand{\@karnaughmap at local@maprealignmentx@}{0}%
+    \newcommand{\@karnaughmap at local@maprealignmenty@}{0}%
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=221
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                       0 \&                       1 \& \phantom{0} \\
+                   0 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&             \\
+                   1 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&             \\
+        \phantom{0}  \&                         \&                         \&             \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=241
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                       0 \&                       1 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \&              \\
+                  01 \& |(000010)|  \phantom{0} \& |(000011)|  \phantom{0} \&              \\
+                  11 \& |(000110)|  \phantom{0} \& |(000111)|  \phantom{0} \&              \\
+                  10 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=421
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  0  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
+                  1  \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=441
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \\
+      }%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=442
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+      }%
+      \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+    \fi
+    \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@\@karnaughmap at var@mapsizez@=444
+      \renewcommand{\@karnaughmap at local@matrixtemplate@}{%
+                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
+                  00 \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \& |(010000)|  \phantom{0} \& |(010001)|  \phantom{0} \& |(010011)|  \phantom{0} \& |(010010)|  \phantom{0} \&              \\
+                  01 \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \& |(010100)|  \phantom{0} \& |(010101)|  \phantom{0} \& |(010111)|  \phantom{0} \& |(010110)|  \phantom{0} \&              \\
+                  11 \& |(001100)|  \phantom{0} \& |(001101)|  \phantom{0} \& |(001111)|  \phantom{0} \& |(001110)|  \phantom{0} \&              \& |(011100)|  \phantom{0} \& |(011101)|  \phantom{0} \& |(011111)|  \phantom{0} \& |(011110)|  \phantom{0} \&              \\
+                  10 \& |(001000)|  \phantom{0} \& |(001001)|  \phantom{0} \& |(001011)|  \phantom{0} \& |(001010)|  \phantom{0} \&              \& |(011000)|  \phantom{0} \& |(011001)|  \phantom{0} \& |(011011)|  \phantom{0} \& |(011010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+                  00 \& |(100000)|  \phantom{0} \& |(100001)|  \phantom{0} \& |(100011)|  \phantom{0} \& |(100010)|  \phantom{0} \&              \& |(110000)|  \phantom{0} \& |(110001)|  \phantom{0} \& |(110011)|  \phantom{0} \& |(110010)|  \phantom{0} \&              \\
+                  01 \& |(100100)|  \phantom{0} \& |(100101)|  \phantom{0} \& |(100111)|  \phantom{0} \& |(100110)|  \phantom{0} \&              \& |(110100)|  \phantom{0} \& |(110101)|  \phantom{0} \& |(110111)|  \phantom{0} \& |(110110)|  \phantom{0} \&              \\
+                  11 \& |(101100)|  \phantom{0} \& |(101101)|  \phantom{0} \& |(101111)|  \phantom{0} \& |(101110)|  \phantom{0} \&              \& |(111100)|  \phantom{0} \& |(111101)|  \phantom{0} \& |(111111)|  \phantom{0} \& |(111110)|  \phantom{0} \&              \\
+                  10 \& |(101000)|  \phantom{0} \& |(101001)|  \phantom{0} \& |(101011)|  \phantom{0} \& |(101010)|  \phantom{0} \&              \& |(111000)|  \phantom{0} \& |(111001)|  \phantom{0} \& |(111011)|  \phantom{0} \& |(111010)|  \phantom{0} \&              \\
+        \phantom{00} \&                         \&                         \&                         \&                         \&              \&                         \&                         \&                         \&                         \&              \\
+      }%
+      \renewcommand{\@karnaughmap at local@maprealignmentx@}{2.5}%
+      \renewcommand{\@karnaughmap at local@maprealignmenty@}{-2.5}%
+    \fi
+  % [END]}
+  % test if a matrix template is found or not(aka "\@karnaughmap at local@matrixtemplate@" equals to '0')
+  \ifnum0=\@karnaughmap at local@matrixtemplate@
+    % print error if no template could be found
+    \PackageError{karnaugh-map}{%
+      Can not find a template fitting your specification (\@karnaughmap at var@mapsizex@\space x \@karnaughmap at var@mapsizey@\space x \@karnaughmap at var@mapsizez@)%
+    }{%
+      Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
+    }%
+  \fi
+  \begin{tikzpicture}
+    % grid {[START]
       % for all dimensions
       \draw[color=black, ultra thin] (0,0) grid (\@karnaughmap at var@mapsizex@,\@karnaughmap at var@mapsizey@);
       % when there are 2 sub maps
@@ -245,39 +421,64 @@
         \draw[color=black, ultra thin] (0,-5) grid (4,-1);
         \draw[color=black, ultra thin] (5,-5) grid (9,-1);
       \fi
-      % labels
-      % for all dimensions
-      \node[above] at (\@karnaughmap at var@mapsizex@*0.5,\@karnaughmap at var@mapsizey at +0.9) {\small{#5}};
-      \node[left] at (-0.9,\@karnaughmap at var@mapsizey@*0.5) {\small{#6}};
-      % when there are 2 sub maps
-      \ifnum\@karnaughmap at var@mapsizez@=2
-        \node[above] at (7,4.9) {\small{#5}};
-        % extra sub maps labels
-        \node[below] at (2,-0.1) {\small{#7$=0$}};
-        \node[below] at (7,-0.1) {\small{#7$=1$}};
-      \fi
-      % when there are 4 sub maps
-      \ifnum\@karnaughmap at var@mapsizez@=4
-        \node[above] at (7,4.9) {\small{#5}};
-        \node[left] at (-0.9,-3) {\small{#6}};
-        % extra sub maps labels
-        \node[below] at (2,-0.1) {\small{#7$=00$}};
-        \node[below] at (7,-0.1) {\small{#7$=01$}};
-        \node[below] at (2,-5.1) {\small{#7$=10$}};
-        \node[below] at (7,-5.1) {\small{#7$=11$}};
-      \fi
-      % data
-      \matrix[
-        matrix of nodes,
-        ampersand replacement=\&,
-        column sep={1cm,between origins},
-        row sep={1cm,between origins},
-      ] at (\@karnaughmap at var@mapsizex@*0.5+\@karnaughmap at local@maprealignmentx@,\@karnaughmap at var@mapsizey@*0.5+\@karnaughmap at local@maprealignmenty@) {
-        \@karnaughmap at local@matrixtemplate@%
-      };
-}{
-    \end{tikzpicture}
-  \endgroup
+    % [END]}
+    % labels {[START]
+      \IfStrEq{\@karnaughmap at option@label}{corner}{%
+        % if variables should be positioned at the corner
+        %
+        % for all dimensions
+        \draw[color=black, ultra thin] (0,\@karnaughmap at var@mapsizey@) --
+          node[pos=0.5, above right, anchor=south, rotate=-45] {\small{\@karnaughmap at var@labelX@}}
+          node[pos=0.5, below left, anchor=north, rotate=-45] {\small{\@karnaughmap at var@labelY@}}
+          ++(135:1);
+        % when there are 2 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=2
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=0$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=1$}};
+        \fi
+        % when there are 4 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=4
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=00$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=01$}};
+          \node[below] at (2,-5.1) {\small{\@karnaughmap at var@labelZ@$=10$}};
+          \node[below] at (7,-5.1) {\small{\@karnaughmap at var@labelZ@$=11$}};
+        \fi
+      }{%
+        % if variables should be positioned in the middle(top and side). Default.
+        %
+        % for all dimensions
+        \node[above] at (\@karnaughmap at var@mapsizex@*0.5,\@karnaughmap at var@mapsizey at +0.9) {\small{\@karnaughmap at var@labelX@}};
+        \node[left] at (-0.9,\@karnaughmap at var@mapsizey@*0.5) {\small{\@karnaughmap at var@labelY@}};
+        % when there are 2 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=2
+          \node[above] at (7,4.9) {\small{\@karnaughmap at var@labelX@}};
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=0$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=1$}};
+        \fi
+        % when there are 4 sub maps
+        \ifnum\@karnaughmap at var@mapsizez@=4
+          \node[above] at (7,4.9) {\small{\@karnaughmap at var@labelX@}};
+          \node[left] at (-0.9,-3) {\small{\@karnaughmap at var@labelY@}};
+          % extra sub map labels
+          \node[below] at (2,-0.1) {\small{\@karnaughmap at var@labelZ@$=00$}};
+          \node[below] at (7,-0.1) {\small{\@karnaughmap at var@labelZ@$=01$}};
+          \node[below] at (2,-5.1) {\small{\@karnaughmap at var@labelZ@$=10$}};
+          \node[below] at (7,-5.1) {\small{\@karnaughmap at var@labelZ@$=11$}};
+        \fi
+      }
+    % [END]}
+    % data
+    \matrix[
+      matrix of nodes,
+      ampersand replacement=\&,
+      column sep={1cm,between origins},
+      row sep={1cm,between origins},
+    ] at (\@karnaughmap at var@mapsizex@*0.5+\@karnaughmap at local@maprealignmentx@,\@karnaughmap at var@mapsizey@*0.5+\@karnaughmap at local@maprealignmenty@) {
+      \@karnaughmap at local@matrixtemplate@%
+    };
 }
 
 %%
@@ -372,12 +573,17 @@
 
 %% keep track of used colors
 \newcount\@karnaughmap at var@colorindex@\relax
+\newcount\@karnaughmap at var@colorindexnext@\relax
 \@karnaughmap at var@colorindex@=0\relax
+\@karnaughmap at var@colorindexnext@=1\relax
 
 \DeclareDocumentCommand{\implicant}{m m O{0}} {%
   % bail if outside environment karnaugh-map
   \@karnaughmap at func@bailoutsideenvironment@{}
   %
+  % fetch new color
+  \@karnaughmap at func@updatecolor@{}
+  %
   \begingroup
     % loop through specified sub maps
     \foreach \map in {#3} {%
@@ -397,7 +603,7 @@
         \ifnum0=\@karnaughmap at var@bw@
           \fill[
             rounded corners=3pt,
-            fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+            fill=\@karnaughmap at var@color@,
             fill opacity=0.25,
           ] {
             ($(\@karnaughmap at func@decimaltobin@{\@karnaughmap at local@northwest@}.center)+(-0.3,0.3)$)
@@ -421,13 +627,14 @@
       \fi
     }
   \endgroup
-  % mark color as used
-  \advance\@karnaughmap at var@colorindex@ by 1\relax
 }
 \DeclareDocumentCommand{\implicantedge}{m m m m O{0}} {%
   % bail if outside environment karnaugh-map
   \@karnaughmap at func@bailoutsideenvironment@{}
   %
+  % fetch new color
+  \@karnaughmap at func@updatecolor@{}
+  %
   \begingroup
     % helper variables {[START]
       \newcommand{\@karnaughmap at local@orientation@}{0} % '0' is a vertical and '1' is a horizontal implicant
@@ -539,7 +746,7 @@
           \ifnum0=\@karnaughmap at var@bw@
             \fill[
               sharp corners,
-              fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+              fill=\@karnaughmap at var@color@,
               fill opacity=0.25,
             ] {
               \@karnaughmap at local@fillcontent@%
@@ -560,8 +767,6 @@
       \fi
     }
   \endgroup
-  % mark color as used
-  \advance\@karnaughmap at var@colorindex@ by 1\relax
 }
 \DeclareDocumentCommand{\implicantcorner}{O{0}} {%
   % bail if outside environment karnaugh-map
@@ -569,6 +774,8 @@
   %
   % make sure "\implicantcorner" only are used on 4x4 maps
   \ifnum\@karnaughmap at var@mapsizex@\@karnaughmap at var@mapsizey@=44
+    % fetch new color
+    \@karnaughmap at func@updatecolor@{}
     % loop through specified sub maps
     \foreach \map in {#1} {%
       % make sure we don't try to draw on non existing sub maps
@@ -592,7 +799,7 @@
           \ifnum0=\@karnaughmap at var@bw@
             \fill[
               sharp corners,
-              fill=\@karnaughmap at func@decimaltocolor@{\@karnaughmap at var@colorindex@},
+              fill=\@karnaughmap at var@color@,
               fill opacity=0.25,
             ]
             ($(\@karnaughmap at func@decimaltobin@{\@karnaughmap at local@coordinate@}.center)+(-.6*\@karnaughmap at local@mirrorx@,.6*\@karnaughmap at local@mirrory@)$)
@@ -621,8 +828,6 @@
         }
       \fi
     }
-    % mark color as used
-    \advance\@karnaughmap at var@colorindex@ by 1\relax
   \else
     % print error if "\implicantcorner" are used on non 4x4 map
     \PackageError{karnaugh-map}{%



More information about the tex-live-commits mailing list.