summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-01-15 21:37:34 +0000
committerKarl Berry <karl@freefriends.org>2022-01-15 21:37:34 +0000
commita2638cabdc505e66c3945729e1e6e6483d60e25f (patch)
tree2e47a42fbc716f6a48c4807a0b2a2e5ee3d1f796 /Master/texmf-dist/source
parentde9ac27df7d36ddbb79cd60c8e9920d950eb338f (diff)
karnaugh-map (15jan22)
git-svn-id: svn://tug.org/texlive/trunk@61614 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r--Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx587
1 files changed, 423 insertions, 164 deletions
diff --git a/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx b/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx
index c097998717a..55fe9c1103d 100644
--- a/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx
+++ b/Master/texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx
@@ -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@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@func@updatecolor@}{%
+ % jump to next color
+ \advance\@karnaughmap@var@colorindex@ by 1\relax
+ \advance\@karnaughmap@var@colorindexnext@ by 1\relax
+ % store color
+ \StrBetween[\@karnaughmap@var@colorindex@,\@karnaughmap@var@colorindexnext@]{\@karnaughmap@var@colors@}{,}{,}[\@karnaughmap@var@color@]
+ % if color is empty (eg. when there are more implicants than colors) return cyan
+ \IfStrEq{\@karnaughmap@var@color@}{}{%
+ \renewcommand{\@karnaughmap@var@color@}{cyan}
+ }{}
}
%% convert decimal to binary 6-bit
@@ -200,6 +204,36 @@
\newcommand{\@karnaughmap@var@mapsizey@}{0}
\newcommand{\@karnaughmap@var@mapsizez@}{0}
+%% store map labels
+\newcommand{\@karnaughmap@var@labelA@}{$X_0$}
+\newcommand{\@karnaughmap@var@labelB@}{$X_1$}
+\newcommand{\@karnaughmap@var@labelC@}{$X_2$}
+\newcommand{\@karnaughmap@var@labelD@}{$X_3$}
+\newcommand{\@karnaughmap@var@labelE@}{$X_4$}
+\newcommand{\@karnaughmap@var@labelF@}{$X_5$}
+\newcommand{\@karnaughmap@var@labelX@}{$X_1$$X_0$}
+\newcommand{\@karnaughmap@var@labelY@}{$X_3$$X_2$}
+\newcommand{\@karnaughmap@var@labelZ@}{$X_5$$X_4$}
+%% if map labels are defined using API version unknown(0), v1(1) or v2(2)
+\newcommand{\@karnaughmap@var@labeltype@}{0}
+
+%% store colors
+\newcommand{\@karnaughmap@var@colors@}{,red,green,yellow,cyan,blue,magenta,}
+\newcommand{\@karnaughmap@var@color@}{}
+
+%% declare package and environment options
+%% package options
+\SetupKeyvalOptions{
+ family=@karnaughmap@option,
+ prefix=@karnaughmap@option@,
+}
+\DeclareStringOption[middle]{label}[middle]
+\DeclareStringOption[]{implicantcolors}[]
+\ProcessKeyvalOptions*
+%% environment options
+\define@key{karnaugh-map}{label}[middle]{\renewcommand{\@karnaughmap@option@label}{#1}}
+\define@key{karnaugh-map}{implicantcolors}[]{\renewcommand{\@karnaughmap@option@implicantcolors}{#1}}
+
%% render in black and white or color default to '0'(false/color)
\newcommand{\@karnaughmap@var@bw@}{0}
% ^^A ##########################################################################
@@ -232,21 +266,28 @@
% \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:}
%
% \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@var@mapsizex@}{#2}%
- \renewcommand{\@karnaughmap@var@mapsizey@}{#3}%
- \renewcommand{\@karnaughmap@var@mapsizez@}{#4}%
- % [END]}
+ % parse environment options
+ \setkeys{karnaugh-map}{#1}%
+ %
+ % check if implicant colors are specified
+ \IfStrEq{\@karnaughmap@option@implicantcolors}{}{}{%
+ % ensure no empty colors are specified
+ \IfSubStr{\@karnaughmap@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@option@implicantcolors,}{,,}{,}[\@karnaughmap@var@colors@]%
+ }%
+ %
% determinate if markings should be color or black and white
- \IfBooleanTF{#1}{%
+ \IfBooleanTF{#2}{%
% should be black and white
\renewcommand{\@karnaughmap@var@bw@}{1}%
}{%
@@ -287,86 +340,216 @@
\renewcommand{\@karnaughmap@var@bw@}{0}%
}%
%
- % find matching matrix template and alignment parameters {[START]
- \newcommand{\@karnaughmap@local@matrixtemplate@}{0}% '0' is considered as missing matrix template
- \newcommand{\@karnaughmap@local@maprealignmentx@}{0}%
- \newcommand{\@karnaughmap@local@maprealignmenty@}{0}%
- \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=221
- \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=241
- \renewcommand{\@karnaughmap@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} \& \& \& \\
- }%
+ % store map size {[START]
+ \renewcommand{\@karnaughmap@var@mapsizex@}{#3}%
+ \renewcommand{\@karnaughmap@var@mapsizey@}{#4}%
+ \renewcommand{\@karnaughmap@var@mapsizez@}{#5}%
+ % [END]}
+ %
+ % only 9 arguments are directly supported. jump to helper function
+ % to parse remaining arguments and finish initialization.
+ \@karnaughmap@func@karnaughstart@%
+}{
+ \end{tikzpicture}
+ \endgroup
+}
+\DeclareDocumentCommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=221
+ % no difference
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelB@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
+ \fi
+ \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=241
+ \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+ % API v1
+ \renewcommand{\@karnaughmap@var@labelX@}{#1}%
+ \renewcommand{\@karnaughmap@var@labelY@}{#2}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{1}%
+ }}}%
+ \ifnum\@karnaughmap@var@labeltype@=0
+ % API v2
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelC@\@karnaughmap@var@labelB@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
\fi
- \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
- \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
+ \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+ % API v1
+ \renewcommand{\@karnaughmap@var@labelX@}{#1}%
+ \renewcommand{\@karnaughmap@var@labelY@}{#2}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{1}%
+ }}}%
+ \ifnum\@karnaughmap@var@labeltype@=0
+ % API v2
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelC@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
\fi
- \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441
- \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441
+ \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
+ % API v1
+ \renewcommand{\@karnaughmap@var@labelX@}{#1}%
+ \renewcommand{\@karnaughmap@var@labelY@}{#2}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{1}%
+ }}}%
+ \ifnum\@karnaughmap@var@labeltype@=0
+ % API v2
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
+ \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
\fi
- \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=442
- \renewcommand{\@karnaughmap@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@local@maprealignmentx@}{2.5}%
+ \fi
+ \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=442
+ \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+ % API v1
+ \renewcommand{\@karnaughmap@var@labelX@}{#1}%
+ \renewcommand{\@karnaughmap@var@labelY@}{#2}%
+ \renewcommand{\@karnaughmap@var@labelZ@}{#3}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{1}%
+ }}}}%
+ \ifnum\@karnaughmap@var@labeltype@=0
+ % API v2
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
+ \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
+ \IfValueT{#5}{\renewcommand{\@karnaughmap@var@labelE@}{#5}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
+ \renewcommand{\@karnaughmap@var@labelZ@}{\@karnaughmap@var@labelE@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
\fi
- \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=444
- \renewcommand{\@karnaughmap@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@local@maprealignmentx@}{2.5}%
- \renewcommand{\@karnaughmap@local@maprealignmenty@}{-2.5}%
+ \fi
+ \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=444
+ \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
+ % API v1
+ \renewcommand{\@karnaughmap@var@labelX@}{#1}%
+ \renewcommand{\@karnaughmap@var@labelY@}{#2}%
+ \renewcommand{\@karnaughmap@var@labelZ@}{#3}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{1}%
+ }}}}%
+ \ifnum\@karnaughmap@var@labeltype@=0
+ % API v2
+ \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
+ \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
+ \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
+ \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
+ \IfValueT{#5}{\renewcommand{\@karnaughmap@var@labelE@}{#5}}%
+ \IfValueT{#6}{\renewcommand{\@karnaughmap@var@labelF@}{#6}}%
+ \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
+ \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
+ \renewcommand{\@karnaughmap@var@labelZ@}{\@karnaughmap@var@labelF@\@karnaughmap@var@labelE@}%
+ \renewcommand{\@karnaughmap@var@labeltype@}{2}%
\fi
- % [END]}
- % test if a matrix template is found or not(aka "\@karnaughmap@local@matrixtemplate@" equals to '0')
- \ifnum0=\@karnaughmap@local@matrixtemplate@
- % print error if no template could be found
- \PackageError{karnaugh-map}{%
- Can not find a template fitting your specification (\@karnaughmap@var@mapsizex@\space x \@karnaughmap@var@mapsizey@\space x \@karnaughmap@var@mapsizez@)%
- }{%
- Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
+ \fi
+ % warn when using API v1
+ \ifnum\@karnaughmap@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@local@matrixtemplate@}{0}% '0' is considered as missing matrix template
+ \newcommand{\@karnaughmap@local@maprealignmentx@}{0}%
+ \newcommand{\@karnaughmap@local@maprealignmenty@}{0}%
+ \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=221
+ \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=241
+ \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
+ \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441
+ \renewcommand{\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=442
+ \renewcommand{\@karnaughmap@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@local@maprealignmentx@}{2.5}%
+ \fi
+ \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=444
+ \renewcommand{\@karnaughmap@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@local@maprealignmentx@}{2.5}%
+ \renewcommand{\@karnaughmap@local@maprealignmenty@}{-2.5}%
+ \fi
+ % [END]}
+ % test if a matrix template is found or not(aka "\@karnaughmap@local@matrixtemplate@" equals to '0')
+ \ifnum0=\@karnaughmap@local@matrixtemplate@
+ % print error if no template could be found
+ \PackageError{karnaugh-map}{%
+ Can not find a template fitting your specification (\@karnaughmap@var@mapsizex@\space x \@karnaughmap@var@mapsizey@\space x \@karnaughmap@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@var@mapsizex@,\@karnaughmap@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@var@mapsizex@*0.5,\@karnaughmap@var@mapsizey@+0.9) {\small{#5}};
- \node[left] at (-0.9,\@karnaughmap@var@mapsizey@*0.5) {\small{#6}};
- % when there are 2 sub maps
- \ifnum\@karnaughmap@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@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@var@mapsizex@*0.5+\@karnaughmap@local@maprealignmentx@,\@karnaughmap@var@mapsizey@*0.5+\@karnaughmap@local@maprealignmenty@) {
- \@karnaughmap@local@matrixtemplate@%
- };
-}{
- \end{tikzpicture}
- \endgroup
+ % [END]}
+ % labels {[START]
+ \IfStrEq{\@karnaughmap@option@label}{corner}{%
+ % if variables should be positioned at the corner
+ %
+ % for all dimensions
+ \draw[color=black, ultra thin] (0,\@karnaughmap@var@mapsizey@) --
+ node[pos=0.5, above right, anchor=south, rotate=-45] {\small{\@karnaughmap@var@labelX@}}
+ node[pos=0.5, below left, anchor=north, rotate=-45] {\small{\@karnaughmap@var@labelY@}}
+ ++(135:1);
+ % when there are 2 sub maps
+ \ifnum\@karnaughmap@var@mapsizez@=2
+ % extra sub map labels
+ \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=0$}};
+ \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=1$}};
+ \fi
+ % when there are 4 sub maps
+ \ifnum\@karnaughmap@var@mapsizez@=4
+ % extra sub map labels
+ \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=00$}};
+ \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=01$}};
+ \node[below] at (2,-5.1) {\small{\@karnaughmap@var@labelZ@$=10$}};
+ \node[below] at (7,-5.1) {\small{\@karnaughmap@var@labelZ@$=11$}};
+ \fi
+ }{%
+ % if variables should be positioned in the middle(top and side). Default.
+ %
+ % for all dimensions
+ \node[above] at (\@karnaughmap@var@mapsizex@*0.5,\@karnaughmap@var@mapsizey@+0.9) {\small{\@karnaughmap@var@labelX@}};
+ \node[left] at (-0.9,\@karnaughmap@var@mapsizey@*0.5) {\small{\@karnaughmap@var@labelY@}};
+ % when there are 2 sub maps
+ \ifnum\@karnaughmap@var@mapsizez@=2
+ \node[above] at (7,4.9) {\small{\@karnaughmap@var@labelX@}};
+ % extra sub map labels
+ \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=0$}};
+ \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=1$}};
+ \fi
+ % when there are 4 sub maps
+ \ifnum\@karnaughmap@var@mapsizez@=4
+ \node[above] at (7,4.9) {\small{\@karnaughmap@var@labelX@}};
+ \node[left] at (-0.9,-3) {\small{\@karnaughmap@var@labelY@}};
+ % extra sub map labels
+ \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=00$}};
+ \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=01$}};
+ \node[below] at (2,-5.1) {\small{\@karnaughmap@var@labelZ@$=10$}};
+ \node[below] at (7,-5.1) {\small{\@karnaughmap@var@labelZ@$=11$}};
+ \fi
+ }
+ % [END]}
+ % data
+ \matrix[
+ matrix of nodes,
+ ampersand replacement=\&,
+ column sep={1cm,between origins},
+ row sep={1cm,between origins},
+ ] at (\@karnaughmap@var@mapsizex@*0.5+\@karnaughmap@local@maprealignmentx@,\@karnaughmap@var@mapsizey@*0.5+\@karnaughmap@local@maprealignmenty@) {
+ \@karnaughmap@local@matrixtemplate@%
+ };
}
% ^^A ##########################################################################
% ^^A ##########################################################################
@@ -746,7 +954,9 @@
%% keep track of used colors
\newcount\@karnaughmap@var@colorindex@\relax
+\newcount\@karnaughmap@var@colorindexnext@\relax
\@karnaughmap@var@colorindex@=0\relax
+\@karnaughmap@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@func@bailoutsideenvironment@{}
%
+ % fetch new color
+ \@karnaughmap@func@updatecolor@{}
+ %
\begingroup
% loop through specified sub maps
\foreach \map in {#3} {%
@@ -830,7 +1043,7 @@
\ifnum0=\@karnaughmap@var@bw@
\fill[
rounded corners=3pt,
- fill=\@karnaughmap@func@decimaltocolor@{\@karnaughmap@var@colorindex@},
+ fill=\@karnaughmap@var@color@,
fill opacity=0.25,
] {
($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@northwest@}.center)+(-0.3,0.3)$)
@@ -854,8 +1067,6 @@
\fi
}
\endgroup
- % mark color as used
- \advance\@karnaughmap@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@func@bailoutsideenvironment@{}
%
+ % fetch new color
+ \@karnaughmap@func@updatecolor@{}
+ %
\begingroup
% helper variables {[START]
\newcommand{\@karnaughmap@local@orientation@}{0} % '0' is a vertical and '1' is a horizontal implicant
@@ -1019,7 +1233,7 @@
\ifnum0=\@karnaughmap@var@bw@
\fill[
sharp corners,
- fill=\@karnaughmap@func@decimaltocolor@{\@karnaughmap@var@colorindex@},
+ fill=\@karnaughmap@var@color@,
fill opacity=0.25,
] {
\@karnaughmap@local@fillcontent@%
@@ -1040,8 +1254,6 @@
\fi
}
\endgroup
- % mark color as used
- \advance\@karnaughmap@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@var@mapsizex@\@karnaughmap@var@mapsizey@=44
+ % fetch new color
+ \@karnaughmap@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@var@bw@
\fill[
sharp corners,
- fill=\@karnaughmap@func@decimaltocolor@{\@karnaughmap@var@colorindex@},
+ fill=\@karnaughmap@var@color@,
fill opacity=0.25,
]
($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(-.6*\@karnaughmap@local@mirrorx@,.6*\@karnaughmap@local@mirrory@)$)
@@ -1144,8 +1358,6 @@
}
\fi
}
- % mark color as used
- \advance\@karnaughmap@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,26 +1448,26 @@
% \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}
%
% \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}
%\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,20 +1485,22 @@
%\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$}
% \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.
%