summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
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/tex
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/tex')
-rw-r--r--Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty473
1 files changed, 339 insertions, 134 deletions
diff --git a/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty b/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty
index f4b4eb98eb4..72e2333b568 100644
--- a/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty
+++ b/Master/texmf-dist/tex/latex/karnaugh-map/karnaugh-map.sty
@@ -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@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
@@ -130,6 +134,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}
@@ -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@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}%
}{%
@@ -153,86 +199,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
+ % [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
- \begin{tikzpicture}
- % grid
+ \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
@@ -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@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@%
+ };
}
%%
@@ -372,12 +573,17 @@
%% 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
\DeclareDocumentCommand{\implicant}{m m O{0}} {%
% 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} {%
@@ -397,7 +603,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)$)
@@ -421,13 +627,14 @@
\fi
}
\endgroup
- % mark color as used
- \advance\@karnaughmap@var@colorindex@ by 1\relax
}
\DeclareDocumentCommand{\implicantedge}{m m m m O{0}} {%
% 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
@@ -539,7 +746,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@%
@@ -560,8 +767,6 @@
\fi
}
\endgroup
- % mark color as used
- \advance\@karnaughmap@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@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
@@ -592,7 +799,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@)$)
@@ -621,8 +828,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}{%