Debian Codegraph @

texmf-dist/source/latex/karnaugh-map/karnaugh-map.dtx

raw
1 % \iffalse meta-comment
2 % Copyright (C) 2015-2022 Mattias Jacobsson and contributors
3 % 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).
4 % \fi
5 %
6 % \iffalse
7 %
8 %<package>
9 %<package>%%
10 %<package>%% Copyright (C) 2015-2022 Mattias Jacobsson and contributors
11 %<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).
12 %<package>%%
13 %<package>
14 %<package>\NeedsTeXFormat{LaTeX2e}
15 %<package>\ProvidesPackage{karnaugh-map}[2022/01/15 v2.0 Draw Karnaugh Maps]
16 %
17 %<*driver>
18 \documentclass{ltxdoc}
19 \usepackage{karnaugh-map}
20 \usepackage{multicol}% for documentation
21 \usepackage{tabularx}% for documentation
22 \usepackage{float}% for documentation
23 \usepackage{hyperref}% for documentation
24 \setlength{\parindent}{0pt}
25 \setlength{\parskip}{0.6em}
26 \EnableCrossrefs
27 \CodelineIndex
28 \RecordChanges
29 \OnlyDescription
30 \begin{document}
31 \DocInput{karnaugh-map.dtx}
32 \PrintChanges
33 \end{document}
34 %</driver>
35 % \fi
36 %
37 % \CharacterTable
38 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
39 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
40 % Digits \0\1\2\3\4\5\6\7\8\9
41 % Exclamation \! Double quote \" Hash (number) \#
42 % Dollar \$ Percent \% Ampersand \&
43 % Acute accent \' Left paren \( Right paren \)
44 % Asterisk \* Plus \+ Comma \,
45 % Minus \- Point \. Solidus \/
46 % Colon \: Semicolon \; Less than \<
47 % Equals \= Greater than \> Question mark \?
48 % Commercial at \@ Left bracket \[ Backslash \\
49 % Right bracket \] Circumflex \^ Underscore \_
50 % Grave accent \` Left brace \{ Vertical bar \|
51 % Right brace \} Tilde \~}
52 %
53 %
54 % \changes{v1.0}{2015/10/09}{Initial version}
55 %
56 % \GetFileInfo{karnaugh-map.sty}
57 %
58 % \title{The \textsf{karnaugh-map} package}
59 % \author{Mattias Jacobsson}
60 % \date{\textsf{karnaugh-map}~\fileversion, \filedate}
61 %
62 %\maketitle
63 %
64 % \begin{abstract}
65 % This package draws karnaugh maps with 2, 3, 4, 5, and 6 variables.
66 % It also contains commands for filling the karnaugh map with terms semi-automatically or manually.
67 % Last but not least it contains commands for drawing implicants on top of the map.
68 % Below is an example of a two variable karnaugh map of $X_0 \oplus X_1$.
69 % \end{abstract}
70 % \begin{figure}[H]
71 % \centering
72 % \begin{karnaugh-map}[2][2][1]
73 % \minterms{1,2}
74 % \autoterms[0]
75 % \implicant{1}{1}
76 % \implicant{2}{2}
77 % \end{karnaugh-map}
78 % \end{figure}
79 % \tableofcontents
80 % \pagebreak
81 %
82 % \iffalse code
83 % \begin{macrocode}
84 % ^^A ##########################################################################
85 % ^^A ##########################################################################
86 % ^^A #### CODE ####
87 % ^^A ##########################################################################
88 % ^^A ##########################################################################
89
90 %%
91 %% Dependencies
92 %%
93
94 %% parsing arguments and options
95 \RequirePackage{kvoptions}
96 \RequirePackage{keyval}
97 \RequirePackage{xparse}
98
99 %% working with strings
100 \RequirePackage{xstring}
101
102 %% drawing
103 \RequirePackage{tikz}
104 \usetikzlibrary{calc,matrix}
105
106 %%
107 %% Helpers
108 %%
109
110 %% update color
111 \newcommand{\@karnaughmap@func@updatecolor@}{%
112 % jump to next color
113 \advance\@karnaughmap@var@colorindex@ by 1\relax
114 \advance\@karnaughmap@var@colorindexnext@ by 1\relax
115 % store color
116 \StrBetween[\@karnaughmap@var@colorindex@,\@karnaughmap@var@colorindexnext@]{\@karnaughmap@var@colors@}{,}{,}[\@karnaughmap@var@color@]
117 % if color is empty (eg. when there are more implicants than colors) return cyan
118 \IfStrEq{\@karnaughmap@var@color@}{}{%
119 \renewcommand{\@karnaughmap@var@color@}{cyan}
120 }{}
121 }
122
123 %% convert decimal to binary 6-bit
124 \newcommand{\@karnaughmap@func@decimaltobin@}[1]{%
125 \ifnum#1=0 000000\fi
126 \ifnum#1=1 000001\fi
127 \ifnum#1=2 000010\fi
128 \ifnum#1=3 000011\fi
129 \ifnum#1=4 000100\fi
130 \ifnum#1=5 000101\fi
131 \ifnum#1=6 000110\fi
132 \ifnum#1=7 000111\fi
133 \ifnum#1=8 001000\fi
134 \ifnum#1=9 001001\fi
135 \ifnum#1=10 001010\fi
136 \ifnum#1=11 001011\fi
137 \ifnum#1=12 001100\fi
138 \ifnum#1=13 001101\fi
139 \ifnum#1=14 001110\fi
140 \ifnum#1=15 001111\fi
141 \ifnum#1=16 010000\fi
142 \ifnum#1=17 010001\fi
143 \ifnum#1=18 010010\fi
144 \ifnum#1=19 010011\fi
145 \ifnum#1=20 010100\fi
146 \ifnum#1=21 010101\fi
147 \ifnum#1=22 010110\fi
148 \ifnum#1=23 010111\fi
149 \ifnum#1=24 011000\fi
150 \ifnum#1=25 011001\fi
151 \ifnum#1=26 011010\fi
152 \ifnum#1=27 011011\fi
153 \ifnum#1=28 011100\fi
154 \ifnum#1=29 011101\fi
155 \ifnum#1=30 011110\fi
156 \ifnum#1=31 011111\fi
157 \ifnum#1=32 100000\fi
158 \ifnum#1=33 100001\fi
159 \ifnum#1=34 100010\fi
160 \ifnum#1=35 100011\fi
161 \ifnum#1=36 100100\fi
162 \ifnum#1=37 100101\fi
163 \ifnum#1=38 100110\fi
164 \ifnum#1=39 100111\fi
165 \ifnum#1=40 101000\fi
166 \ifnum#1=41 101001\fi
167 \ifnum#1=42 101010\fi
168 \ifnum#1=43 101011\fi
169 \ifnum#1=44 101100\fi
170 \ifnum#1=45 101101\fi
171 \ifnum#1=46 101110\fi
172 \ifnum#1=47 101111\fi
173 \ifnum#1=48 110000\fi
174 \ifnum#1=49 110001\fi
175 \ifnum#1=50 110010\fi
176 \ifnum#1=51 110011\fi
177 \ifnum#1=52 110100\fi
178 \ifnum#1=53 110101\fi
179 \ifnum#1=54 110110\fi
180 \ifnum#1=55 110111\fi
181 \ifnum#1=56 111000\fi
182 \ifnum#1=57 111001\fi
183 \ifnum#1=58 111010\fi
184 \ifnum#1=59 111011\fi
185 \ifnum#1=60 111100\fi
186 \ifnum#1=61 111101\fi
187 \ifnum#1=62 111110\fi
188 \ifnum#1=63 111111\fi
189 }
190
191 %% command raises an error if executed outside the karnaugh-map environment
192 \newcommand{\@karnaughmap@func@bailoutsideenvironment@}[0]{%
193 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=000
194 \PackageError{karnaugh-map}{%
195 Command can not be used outside karnaugh-map environment%
196 }{%
197 Do not use this command outside the karnaugh-map environment.%
198 }
199 \fi
200 }
201
202 %% store map size
203 \newcommand{\@karnaughmap@var@mapsizex@}{0}
204 \newcommand{\@karnaughmap@var@mapsizey@}{0}
205 \newcommand{\@karnaughmap@var@mapsizez@}{0}
206
207 %% store map labels
208 \newcommand{\@karnaughmap@var@labelA@}{$X_0$}
209 \newcommand{\@karnaughmap@var@labelB@}{$X_1$}
210 \newcommand{\@karnaughmap@var@labelC@}{$X_2$}
211 \newcommand{\@karnaughmap@var@labelD@}{$X_3$}
212 \newcommand{\@karnaughmap@var@labelE@}{$X_4$}
213 \newcommand{\@karnaughmap@var@labelF@}{$X_5$}
214 \newcommand{\@karnaughmap@var@labelX@}{$X_1$$X_0$}
215 \newcommand{\@karnaughmap@var@labelY@}{$X_3$$X_2$}
216 \newcommand{\@karnaughmap@var@labelZ@}{$X_5$$X_4$}
217 %% if map labels are defined using API version unknown(0), v1(1) or v2(2)
218 \newcommand{\@karnaughmap@var@labeltype@}{0}
219
220 %% store colors
221 \newcommand{\@karnaughmap@var@colors@}{,red,green,yellow,cyan,blue,magenta,}
222 \newcommand{\@karnaughmap@var@color@}{}
223
224 %% declare package and environment options
225 %% package options
226 \SetupKeyvalOptions{
227 family=@karnaughmap@option,
228 prefix=@karnaughmap@option@,
229 }
230 \DeclareStringOption[middle]{label}[middle]
231 \DeclareStringOption[]{implicantcolors}[]
232 \ProcessKeyvalOptions*
233 %% environment options
234 \define@key{karnaugh-map}{label}[middle]{\renewcommand{\@karnaughmap@option@label}{#1}}
235 \define@key{karnaugh-map}{implicantcolors}[]{\renewcommand{\@karnaughmap@option@implicantcolors}{#1}}
236
237 %% render in black and white or color default to '0'(false/color)
238 \newcommand{\@karnaughmap@var@bw@}{0}
239 % ^^A ##########################################################################
240 % ^^A ##########################################################################
241 % ^^A #### /CODE ####
242 % ^^A ##########################################################################
243 % ^^A ##########################################################################
244 % \end{macrocode}
245 % \fi
246 %
247 % \section{Usage}
248 %
249 % \iffalse code
250 % \begin{macrocode}
251 % ^^A ##########################################################################
252 % ^^A ##########################################################################
253 % ^^A #### CODE ####
254 % ^^A ##########################################################################
255 % ^^A ##########################################################################
256
257 %%
258 %% Environment
259 %%
260
261 % ^^A ##########################################################################
262 % ^^A ##########################################################################
263 % ^^A #### /CODE ####
264 % ^^A ##########################################################################
265 % ^^A ##########################################################################
266 % \end{macrocode}
267 % \fi
268 % \begin{environment}{karnaugh-map}
269 % \changes{v2.0}{2018/12/13}{API change: variable labels are now specified separately.}
270 % The |karnaugh-map| environment is the base for this package, and everything related to this package happens inside an instances of this environment.
271 %
272 % \textbf{Usage:}
273 %
274 % \begin{tabularx}{\textwidth}{l X}
275 % \small{|\begin{karnaugh-map}|} & \\
276 % \small{\parg{options}} & \small{See section \ref{sec:usage:options}. Default: ''''} \\
277 % \small{\meta{*}} & \small{One asterisk for black and white implicants, non for colorized implicants} \\
278 % \small{\oarg{X size}} & \small{Number of X-axis cells. Default: ''4''} \\
279 % \small{\oarg{Y size}} & \small{Number of Y-axis cells. Default: ''4''} \\
280 % \small{\oarg{Z size}} & \small{Number of X$\times$Y submaps. Default: ''1''} \\
281 % \small{\oarg{label A}}\footnotemark & \small{Label for the variable one. Default: ''$X_0$''} \\
282 % \small{\oarg{label B}}\footnotemark[\value{footnote}] & \small{Label for the variable two. Default: ''$X_1$''} \\
283 % \small{\oarg{label C}}\footnotemark[\value{footnote}] & \small{Label for the variable three. Default: ''$X_2$''} \\
284 % \small{\oarg{label D}} & \small{Label for the variable four. Default: ''$X_3$''} \\
285 % \small{\oarg{label E}} & \small{Label for the variable five. Default: ''$X_4$''} \\
286 % \small{\oarg{label F}} & \small{Label for the variable six. Default: ''$X_5$''} \\
287 % \end{tabularx}
288 %
289 % \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.}
290 %
291 % \textbf{Example:}
292 %
293 % Four variable karnaugh map, colorized, with X label $X_1X_0$, and Y label $X_3X_2$.
294 % \begin{verbatim}
295 %\begin{karnaugh-map}
296 %\end{karnaugh-map}
297 %
298 %or
299 %
300 %\begin{karnaugh-map}[4][4][1][$X_0$][$X_1$][$X_2$][$X_3$]
301 %\end{karnaugh-map}
302 % \end{verbatim}
303 % Six variable karnaugh map, black and white, with X label $ba$, Y label $dc$, and Z label $fe$.
304 % \begin{verbatim}
305 %\begin{karnaugh-map}*[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
306 %\end{karnaugh-map}
307 % \end{verbatim}
308 % \iffalse code
309 % \begin{macrocode}
310 % ^^A ##########################################################################
311 % ^^A ##########################################################################
312 % ^^A #### CODE ####
313 % ^^A ##########################################################################
314 % ^^A ##########################################################################
315 \NewDocumentEnvironment{karnaugh-map}{D(){} s O{4} O{4} O{1}} {%
316 \begingroup
317 % parse environment options
318 \setkeys{karnaugh-map}{#1}%
319 %
320 % check if implicant colors are specified
321 \IfStrEq{\@karnaughmap@option@implicantcolors}{}{}{%
322 % ensure no empty colors are specified
323 \IfSubStr{\@karnaughmap@option@implicantcolors}{,,}{%
324 \PackageError{karnaugh-map}{%
325 Incorrect usage of option implicantcolors%
326 }{%
327 The option implicantcolors is a comma separated list of colors with no gap. You used two consecutive commas.%
328 }%
329 }{}%
330 % add comma at beginning and end. then remove duplicates
331 \StrSubstitute{,\@karnaughmap@option@implicantcolors,}{,,}{,}[\@karnaughmap@var@colors@]%
332 }%
333 %
334 % determinate if markings should be color or black and white
335 \IfBooleanTF{#2}{%
336 % should be black and white
337 \renewcommand{\@karnaughmap@var@bw@}{1}%
338 }{%
339 % should be color
340 \renewcommand{\@karnaughmap@var@bw@}{0}%
341 }%
342 %
343 % store map size {[START]
344 \renewcommand{\@karnaughmap@var@mapsizex@}{#3}%
345 \renewcommand{\@karnaughmap@var@mapsizey@}{#4}%
346 \renewcommand{\@karnaughmap@var@mapsizez@}{#5}%
347 % [END]}
348 %
349 % only 9 arguments are directly supported. jump to helper function
350 % to parse remaining arguments and finish initialization.
351 \@karnaughmap@func@karnaughstart@%
352 }{
353 \end{tikzpicture}
354 \endgroup
355 }
356 \DeclareDocumentCommand{\@karnaughmap@func@karnaughstart@}{oooooo} {%
357 % parse label args {[START]
358 % try to maintain backwards compatibility with v1 while enabling users to separatly
359 % specify each input label variable
360 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=221
361 % no difference
362 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
363 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
364 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelA@}%
365 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelB@}%
366 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
367 \fi
368 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=241
369 \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
370 % API v1
371 \renewcommand{\@karnaughmap@var@labelX@}{#1}%
372 \renewcommand{\@karnaughmap@var@labelY@}{#2}%
373 \renewcommand{\@karnaughmap@var@labeltype@}{1}%
374 }}}%
375 \ifnum\@karnaughmap@var@labeltype@=0
376 % API v2
377 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
378 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
379 \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
380 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelA@}%
381 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelC@\@karnaughmap@var@labelB@}%
382 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
383 \fi
384 \fi
385 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
386 \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
387 % API v1
388 \renewcommand{\@karnaughmap@var@labelX@}{#1}%
389 \renewcommand{\@karnaughmap@var@labelY@}{#2}%
390 \renewcommand{\@karnaughmap@var@labeltype@}{1}%
391 }}}%
392 \ifnum\@karnaughmap@var@labeltype@=0
393 % API v2
394 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
395 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
396 \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
397 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
398 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelC@}%
399 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
400 \fi
401 \fi
402 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441
403 \IfValueT{#1}{\IfValueT{#2}{\IfValueF{#3}{%
404 % API v1
405 \renewcommand{\@karnaughmap@var@labelX@}{#1}%
406 \renewcommand{\@karnaughmap@var@labelY@}{#2}%
407 \renewcommand{\@karnaughmap@var@labeltype@}{1}%
408 }}}%
409 \ifnum\@karnaughmap@var@labeltype@=0
410 % API v2
411 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
412 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
413 \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
414 \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
415 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
416 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
417 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
418 \fi
419 \fi
420 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=442
421 \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
422 % API v1
423 \renewcommand{\@karnaughmap@var@labelX@}{#1}%
424 \renewcommand{\@karnaughmap@var@labelY@}{#2}%
425 \renewcommand{\@karnaughmap@var@labelZ@}{#3}%
426 \renewcommand{\@karnaughmap@var@labeltype@}{1}%
427 }}}}%
428 \ifnum\@karnaughmap@var@labeltype@=0
429 % API v2
430 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
431 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
432 \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
433 \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
434 \IfValueT{#5}{\renewcommand{\@karnaughmap@var@labelE@}{#5}}%
435 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
436 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
437 \renewcommand{\@karnaughmap@var@labelZ@}{\@karnaughmap@var@labelE@}%
438 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
439 \fi
440 \fi
441 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=444
442 \IfValueT{#1}{\IfValueT{#2}{\IfValueT{#3}{\IfValueF{#4}{%
443 % API v1
444 \renewcommand{\@karnaughmap@var@labelX@}{#1}%
445 \renewcommand{\@karnaughmap@var@labelY@}{#2}%
446 \renewcommand{\@karnaughmap@var@labelZ@}{#3}%
447 \renewcommand{\@karnaughmap@var@labeltype@}{1}%
448 }}}}%
449 \ifnum\@karnaughmap@var@labeltype@=0
450 % API v2
451 \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
452 \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
453 \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
454 \IfValueT{#4}{\renewcommand{\@karnaughmap@var@labelD@}{#4}}%
455 \IfValueT{#5}{\renewcommand{\@karnaughmap@var@labelE@}{#5}}%
456 \IfValueT{#6}{\renewcommand{\@karnaughmap@var@labelF@}{#6}}%
457 \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
458 \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelD@\@karnaughmap@var@labelC@}%
459 \renewcommand{\@karnaughmap@var@labelZ@}{\@karnaughmap@var@labelF@\@karnaughmap@var@labelE@}%
460 \renewcommand{\@karnaughmap@var@labeltype@}{2}%
461 \fi
462 \fi
463 % warn when using API v1
464 \ifnum\@karnaughmap@var@labeltype@=1
465 \PackageWarning{karnaugh-map}{%
466 The API for specifying variable labels have been updated. You are currently using the old API(v1).
467 In the new API each variable label is specified separately. See the documentation for more details.
468 Backward compatibility may disappear in a future release.%
469 }%
470 \fi
471 % [END]}
472 %
473 % find matching matrix template and alignment parameters {[START]
474 \newcommand{\@karnaughmap@local@matrixtemplate@}{0}% '0' is considered as missing matrix template
475 \newcommand{\@karnaughmap@local@maprealignmentx@}{0}%
476 \newcommand{\@karnaughmap@local@maprealignmenty@}{0}%
477 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=221
478 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
479 \& 0 \& 1 \& \phantom{0} \\
480 0 \& |(000000)| \phantom{0} \& |(000001)| \phantom{0} \& \\
481 1 \& |(000010)| \phantom{0} \& |(000011)| \phantom{0} \& \\
482 \phantom{0} \& \& \& \\
483 }%
484 \fi
485 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=241
486 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
487 \& 0 \& 1 \& \phantom{00} \\
488 00 \& |(000000)| \phantom{0} \& |(000001)| \phantom{0} \& \\
489 01 \& |(000010)| \phantom{0} \& |(000011)| \phantom{0} \& \\
490 11 \& |(000110)| \phantom{0} \& |(000111)| \phantom{0} \& \\
491 10 \& |(000100)| \phantom{0} \& |(000101)| \phantom{0} \& \\
492 \phantom{00} \& \& \& \\
493 }%
494 \fi
495 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
496 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
497 \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \\
498 0 \& |(000000)| \phantom{0} \& |(000001)| \phantom{0} \& |(000011)| \phantom{0} \& |(000010)| \phantom{0} \& \\
499 1 \& |(000100)| \phantom{0} \& |(000101)| \phantom{0} \& |(000111)| \phantom{0} \& |(000110)| \phantom{0} \& \\
500 \phantom{00} \& \& \& \& \& \\
501 }%
502 \fi
503 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441
504 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
505 \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \\
506 00 \& |(000000)| \phantom{0} \& |(000001)| \phantom{0} \& |(000011)| \phantom{0} \& |(000010)| \phantom{0} \& \\
507 01 \& |(000100)| \phantom{0} \& |(000101)| \phantom{0} \& |(000111)| \phantom{0} \& |(000110)| \phantom{0} \& \\
508 11 \& |(001100)| \phantom{0} \& |(001101)| \phantom{0} \& |(001111)| \phantom{0} \& |(001110)| \phantom{0} \& \\
509 10 \& |(001000)| \phantom{0} \& |(001001)| \phantom{0} \& |(001011)| \phantom{0} \& |(001010)| \phantom{0} \& \\
510 \phantom{00} \& \& \& \& \& \\
511 }%
512 \fi
513 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=442
514 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
515 \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \\
516 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} \& \\
517 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} \& \\
518 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} \& \\
519 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} \& \\
520 \phantom{00} \& \& \& \& \& \& \& \& \& \& \\
521 }%
522 \renewcommand{\@karnaughmap@local@maprealignmentx@}{2.5}%
523 \fi
524 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=444
525 \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
526 \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \& 00 \& 01 \& 11 \& 10 \& \phantom{00} \\
527 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} \& \\
528 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} \& \\
529 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} \& \\
530 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} \& \\
531 \phantom{00} \& \& \& \& \& \& \& \& \& \& \\
532 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} \& \\
533 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} \& \\
534 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} \& \\
535 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} \& \\
536 \phantom{00} \& \& \& \& \& \& \& \& \& \& \\
537 }%
538 \renewcommand{\@karnaughmap@local@maprealignmentx@}{2.5}%
539 \renewcommand{\@karnaughmap@local@maprealignmenty@}{-2.5}%
540 \fi
541 % [END]}
542 % test if a matrix template is found or not(aka "\@karnaughmap@local@matrixtemplate@" equals to '0')
543 \ifnum0=\@karnaughmap@local@matrixtemplate@
544 % print error if no template could be found
545 \PackageError{karnaugh-map}{%
546 Can not find a template fitting your specification (\@karnaughmap@var@mapsizex@\space x \@karnaughmap@var@mapsizey@\space x \@karnaughmap@var@mapsizez@)%
547 }{%
548 Existing templates have the following dimensions: 2x2x1, 2x4x1, 4x2x1, 4x4x1, 4x4x2, and 4x4x4.
549 }%
550 \fi
551 \begin{tikzpicture}
552 % grid {[START]
553 % for all dimensions
554 \draw[color=black, ultra thin] (0,0) grid (\@karnaughmap@var@mapsizex@,\@karnaughmap@var@mapsizey@);
555 % when there are 2 sub maps
556 \ifnum\@karnaughmap@var@mapsizez@=2
557 \draw[color=black, ultra thin] (5,0) grid (9,4);
558 \fi
559 % when there are 4 sub maps
560 \ifnum\@karnaughmap@var@mapsizez@=4
561 \draw[color=black, ultra thin] (5,0) grid (9,4);
562 \draw[color=black, ultra thin] (0,-5) grid (4,-1);
563 \draw[color=black, ultra thin] (5,-5) grid (9,-1);
564 \fi
565 % [END]}
566 % labels {[START]
567 \IfStrEq{\@karnaughmap@option@label}{corner}{%
568 % if variables should be positioned at the corner
569 %
570 % for all dimensions
571 \draw[color=black, ultra thin] (0,\@karnaughmap@var@mapsizey@) --
572 node[pos=0.5, above right, anchor=south, rotate=-45] {\small{\@karnaughmap@var@labelX@}}
573 node[pos=0.5, below left, anchor=north, rotate=-45] {\small{\@karnaughmap@var@labelY@}}
574 ++(135:1);
575 % when there are 2 sub maps
576 \ifnum\@karnaughmap@var@mapsizez@=2
577 % extra sub map labels
578 \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=0$}};
579 \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=1$}};
580 \fi
581 % when there are 4 sub maps
582 \ifnum\@karnaughmap@var@mapsizez@=4
583 % extra sub map labels
584 \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=00$}};
585 \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=01$}};
586 \node[below] at (2,-5.1) {\small{\@karnaughmap@var@labelZ@$=10$}};
587 \node[below] at (7,-5.1) {\small{\@karnaughmap@var@labelZ@$=11$}};
588 \fi
589 }{%
590 % if variables should be positioned in the middle(top and side). Default.
591 %
592 % for all dimensions
593 \node[above] at (\@karnaughmap@var@mapsizex@*0.5,\@karnaughmap@var@mapsizey@+0.9) {\small{\@karnaughmap@var@labelX@}};
594 \node[left] at (-0.9,\@karnaughmap@var@mapsizey@*0.5) {\small{\@karnaughmap@var@labelY@}};
595 % when there are 2 sub maps
596 \ifnum\@karnaughmap@var@mapsizez@=2
597 \node[above] at (7,4.9) {\small{\@karnaughmap@var@labelX@}};
598 % extra sub map labels
599 \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=0$}};
600 \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=1$}};
601 \fi
602 % when there are 4 sub maps
603 \ifnum\@karnaughmap@var@mapsizez@=4
604 \node[above] at (7,4.9) {\small{\@karnaughmap@var@labelX@}};
605 \node[left] at (-0.9,-3) {\small{\@karnaughmap@var@labelY@}};
606 % extra sub map labels
607 \node[below] at (2,-0.1) {\small{\@karnaughmap@var@labelZ@$=00$}};
608 \node[below] at (7,-0.1) {\small{\@karnaughmap@var@labelZ@$=01$}};
609 \node[below] at (2,-5.1) {\small{\@karnaughmap@var@labelZ@$=10$}};
610 \node[below] at (7,-5.1) {\small{\@karnaughmap@var@labelZ@$=11$}};
611 \fi
612 }
613 % [END]}
614 % data
615 \matrix[
616 matrix of nodes,
617 ampersand replacement=\&,
618 column sep={1cm,between origins},
619 row sep={1cm,between origins},
620 ] at (\@karnaughmap@var@mapsizex@*0.5+\@karnaughmap@local@maprealignmentx@,\@karnaughmap@var@mapsizey@*0.5+\@karnaughmap@local@maprealignmenty@) {
621 \@karnaughmap@local@matrixtemplate@%
622 };
623 }
624 % ^^A ##########################################################################
625 % ^^A ##########################################################################
626 % ^^A #### /CODE ####
627 % ^^A ##########################################################################
628 % ^^A ##########################################################################
629 % \end{macrocode}
630 % \fi
631 % \end{environment}
632 %
633 % \iffalse code
634 % \begin{macrocode}
635 % ^^A ##########################################################################
636 % ^^A ##########################################################################
637 % ^^A #### CODE ####
638 % ^^A ##########################################################################
639 % ^^A ##########################################################################
640
641 %%
642 %% Commands for filling out the cells
643 %%
644
645 %% store already used cells to avoid double filled cells and for auto completion
646 \newcommand{\@karnaughmap@var@usedcells@}{,}
647
648 % ^^A ##########################################################################
649 % ^^A ##########################################################################
650 % ^^A #### /CODE ####
651 % ^^A ##########################################################################
652 % ^^A ##########################################################################
653 % \end{macrocode}
654 % \fi
655 %
656 % \newpage
657 % \subsection{Terms}
658 % \begin{macro}{\autoterms}
659 % The |\autoterms| command fills the remaining unfilled cells of the karnaugh map with the contents of the optional argument.
660 %
661 % \textbf{Usage:}
662 %
663 % \begin{tabularx}{\textwidth}{l X}
664 % \small{|\autoterms|} & \\
665 % \small{\oarg{content}} & \small{Content for the remaining unfilled cells. Default: ''-''}
666 % \end{tabularx}
667 %
668 % \textbf{Example:}
669 %
670 % Fill all remaining unfilled cells with ''-''.
671 % \begin{verbatim}
672 %\begin{karnaugh-map}
673 % \autoterms[-]
674 %\end{karnaugh-map}
675 % \end{verbatim}
676 % \iffalse code
677 % \begin{macrocode}
678 % ^^A ##########################################################################
679 % ^^A ##########################################################################
680 % ^^A #### CODE ####
681 % ^^A ##########################################################################
682 % ^^A ##########################################################################
683 \DeclareDocumentCommand{\autoterms}{O{-}} {%
684 % bail if outside environment karnaugh-map
685 \@karnaughmap@func@bailoutsideenvironment@{}
686 %
687 \begingroup
688 % calculate max cell number {[START]
689 \newcount\@karnaughmap@local@max@\relax
690 \@karnaughmap@local@max@=\@karnaughmap@var@mapsizex@\relax
691 \multiply\@karnaughmap@local@max@ by \@karnaughmap@var@mapsizey@\relax
692 \multiply\@karnaughmap@local@max@ by \@karnaughmap@var@mapsizez@\relax
693 \advance\@karnaughmap@local@max@ by -1\relax
694 % [END]}
695 % fill terms
696 \foreach \cell in {0,1,2,...,\@karnaughmap@local@max@} {%
697 \IfSubStr{\@karnaughmap@var@usedcells@}{,\cell,}{}{%
698 \path (\@karnaughmap@func@decimaltobin@{\cell}) node {#1};
699 }
700 }
701 \endgroup
702 % update \@karnaughmap@var@usedcells@ (all cells are used now)
703 \renewcommand{\@karnaughmap@var@usedcells@}{,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,}
704 }
705 % ^^A ##########################################################################
706 % ^^A ##########################################################################
707 % ^^A #### /CODE ####
708 % ^^A ##########################################################################
709 % ^^A ##########################################################################
710 % \end{macrocode}
711 % \fi
712 % \end{macro}
713 %
714 % \begin{macro}{\indeterminants}
715 % The |\indeterminants| command fills the specified cells with ''-'' if they aren't already filled. Order of the cell numbers does not matter.
716 %
717 % \textbf{Usage:}
718 %
719 % \begin{tabularx}{\textwidth}{l X}
720 % \small{|\indeterminants|} & \\
721 % \small{\marg{cells}} & \small{Comma separated list of cells to fill with ''-''}
722 % \end{tabularx}
723 %
724 % \textbf{Example:}
725 %
726 % Fill the top left and right cell with ''-''.
727 % \begin{verbatim}
728 %\begin{karnaugh-map}
729 % \indeterminants{0,2}
730 %\end{karnaugh-map}
731 % \end{verbatim}
732 % \iffalse code
733 % \begin{macrocode}
734 % ^^A ##########################################################################
735 % ^^A ##########################################################################
736 % ^^A #### CODE ####
737 % ^^A ##########################################################################
738 % ^^A ##########################################################################
739 \DeclareDocumentCommand{\indeterminants}{m} {%
740 % bail if outside environment karnaugh-map
741 \@karnaughmap@func@bailoutsideenvironment@{}
742 %
743 \terms{#1}{-}
744 }
745 % ^^A ##########################################################################
746 % ^^A ##########################################################################
747 % ^^A #### /CODE ####
748 % ^^A ##########################################################################
749 % ^^A ##########################################################################
750 % \end{macrocode}
751 % \fi
752 % \end{macro}
753 %
754 % \begin{macro}{\manualterms}
755 % The |\manualterms| command fills the 0th cell with the first element in the argument, the 1st cell with the second element in the argument, and so on. If any of the cells already is filled, it is left as it was.
756 %
757 % \textbf{Usage:}
758 %
759 % \begin{tabularx}{\textwidth}{l X}
760 % \small{|\manualterms|} & \\
761 % \small{\marg{content}} & \small{Comma separated list of cell contents}
762 % \end{tabularx}
763 %
764 % \textbf{Example:}
765 %
766 % Fill the first four cells with 0, 1, 0, and 1 respectively.
767 % \begin{verbatim}
768 %\begin{karnaugh-map}
769 % \manualterms{0,1,0,1}
770 %\end{karnaugh-map}
771 % \end{verbatim}
772 % \iffalse code
773 % \begin{macrocode}
774 % ^^A ##########################################################################
775 % ^^A ##########################################################################
776 % ^^A #### CODE ####
777 % ^^A ##########################################################################
778 % ^^A ##########################################################################
779 \DeclareDocumentCommand{\manualterms}{m} {%
780 % bail if outside environment karnaugh-map
781 \@karnaughmap@func@bailoutsideenvironment@{}
782 %
783 \foreach \cellinfo [count=\cell from 0] in {#1} {%
784 % only write to cell if it is empty otherwise fail silently
785 \IfSubStr{\@karnaughmap@var@usedcells@}{,\cell,}{}{%
786 \path (\@karnaughmap@func@decimaltobin@{\cell}) node {\cellinfo};
787 }
788 }
789 % update \@karnaughmap@var@usedcells@ (previous cells + all cells up to \@karnaughmap@local@cellcount@ are used now) {[START]
790 \newcommand{\@karnaughmap@local@tmpusedcells@}{}
791 \newcount\@karnaughmap@local@cellcount@\relax
792 % count number of cells in #1 {[START]
793 \StrCount{#1}{,}[\@karnaughmap@local@tmpusedcells@]
794 \@karnaughmap@local@cellcount@=\@karnaughmap@local@tmpusedcells@\relax
795 \advance\@karnaughmap@local@cellcount@ by 1\relax
796 \multiply\@karnaughmap@local@cellcount@ by 2\relax
797 % [END]}
798 % create sequence for \@karnaughmap@local@tmpusedcells@
799 \StrLeft{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,}{\@karnaughmap@local@cellcount@}[\@karnaughmap@local@tmpusedcells@]
800 % update \@karnaughmap@var@usedcells@ (append \@karnaughmap@local@tmpusedcells@)
801 \expandafter\def\expandafter\@karnaughmap@var@usedcells@\expandafter{\@karnaughmap@var@usedcells@\@karnaughmap@local@tmpusedcells@}
802 % [END]}
803 }
804 % ^^A ##########################################################################
805 % ^^A ##########################################################################
806 % ^^A #### /CODE ####
807 % ^^A ##########################################################################
808 % ^^A ##########################################################################
809 % \end{macrocode}
810 % \fi
811 % \end{macro}
812 %
813 % \newpage
814 % \begin{macro}{\maxterms}
815 % The |\maxterms| command fills the specified cells with ''0'' if they aren't already filled. Order of the cell numbers does not matter.
816 %
817 % \textbf{Usage:}
818 %
819 % \begin{tabularx}{\textwidth}{l X}
820 % \small{|\maxterms|} & \\
821 % \small{\marg{cells}} & \small{Comma separated list of cells to fill with ''0''} \\
822 % \end{tabularx}
823 %
824 % \textbf{Example:}
825 %
826 % Fill the top left and right cell with ''0''.
827 % \begin{verbatim}
828 %\begin{karnaugh-map}
829 % \maxterms{0,2}
830 %\end{karnaugh-map}
831 % \end{verbatim}
832 % \iffalse code
833 % \begin{macrocode}
834 % ^^A ##########################################################################
835 % ^^A ##########################################################################
836 % ^^A #### CODE ####
837 % ^^A ##########################################################################
838 % ^^A ##########################################################################
839 \DeclareDocumentCommand{\maxterms}{m} {%
840 % bail if outside environment karnaugh-map
841 \@karnaughmap@func@bailoutsideenvironment@{}
842 %
843 \terms{#1}{0}
844 }
845 % ^^A ##########################################################################
846 % ^^A ##########################################################################
847 % ^^A #### /CODE ####
848 % ^^A ##########################################################################
849 % ^^A ##########################################################################
850 % \end{macrocode}
851 % \fi
852 % \end{macro}
853 %
854 % \begin{macro}{\minterms}
855 % The |\minterms| command fills the specified cells with ''1'' if they aren't already filled. Order of the cell numbers does not matter.
856 %
857 % \textbf{Usage:}
858 %
859 % \begin{tabularx}{\textwidth}{l X}
860 % \small{|\minterms|} & \\
861 % \small{\marg{cells}} & \small{Comma separated list of cells to fill with ''1''} \\
862 % \end{tabularx}
863 %
864 % \textbf{Example:}
865 %
866 % Fill the top left and right cell with ''1''.
867 % \begin{verbatim}
868 %\begin{karnaugh-map}
869 % \minterms{0,2}
870 %\end{karnaugh-map}
871 % \end{verbatim}
872 % \iffalse code
873 % \begin{macrocode}
874 % ^^A ##########################################################################
875 % ^^A ##########################################################################
876 % ^^A #### CODE ####
877 % ^^A ##########################################################################
878 % ^^A ##########################################################################
879 \DeclareDocumentCommand{\minterms}{m} {%
880 % bail if outside environment karnaugh-map
881 \@karnaughmap@func@bailoutsideenvironment@{}
882 %
883 \terms{#1}{1}
884 }
885 % ^^A ##########################################################################
886 % ^^A ##########################################################################
887 % ^^A #### /CODE ####
888 % ^^A ##########################################################################
889 % ^^A ##########################################################################
890 % \end{macrocode}
891 % \fi
892 % \end{macro}
893 %
894 % \begin{macro}{\terms}
895 % \changes{v1.1}{2017/02/06}{Support user specified term content and variable entered maps}
896 % The |\terms| command fills the specified cells with the specified content if they aren't already filled. Order of the cell numbers does not matter.
897 %
898 % \textbf{Usage:}
899 %
900 % \begin{tabularx}{\textwidth}{l X}
901 % \small{|\terms|} & \\
902 % \small{\marg{cells}} & \small{Comma separated list of cells to fill with content} \\
903 % \small{\marg{content}} & \small{Content to fill the cells with} \\
904 % \end{tabularx}
905 %
906 % \textbf{Example:}
907 %
908 % Fill the top left and right cell with ''X''.
909 % \begin{verbatim}
910 %\begin{karnaugh-map}
911 % \terms{0,2}{X}
912 %\end{karnaugh-map}
913 % \end{verbatim}
914 % \iffalse code
915 % \begin{macrocode}
916 % ^^A ##########################################################################
917 % ^^A ##########################################################################
918 % ^^A #### CODE ####
919 % ^^A ##########################################################################
920 % ^^A ##########################################################################
921 \DeclareDocumentCommand{\terms}{m m} {%
922 % bail if outside environment karnaugh-map
923 \@karnaughmap@func@bailoutsideenvironment@{}
924 %
925 \foreach \cell in {#1} {%
926 % only write to cell if it is empty otherwise fail silently
927 \IfSubStr{\@karnaughmap@var@usedcells@}{,\cell,}{}{%
928 \path (\@karnaughmap@func@decimaltobin@{\cell}) node {#2};
929 }
930 }
931 % update \@karnaughmap@var@usedcells@
932 \expandafter\def\expandafter\@karnaughmap@var@usedcells@\expandafter{\@karnaughmap@var@usedcells@#1,}
933 }
934 % ^^A ##########################################################################
935 % ^^A ##########################################################################
936 % ^^A #### /CODE ####
937 % ^^A ##########################################################################
938 % ^^A ##########################################################################
939 % \end{macrocode}
940 % \fi
941 % \end{macro}
942 %
943 % \iffalse code
944 % \begin{macrocode}
945 % ^^A ##########################################################################
946 % ^^A ##########################################################################
947 % ^^A #### CODE ####
948 % ^^A ##########################################################################
949 % ^^A ##########################################################################
950
951 %%
952 %% Commands for marking the cells
953 %%
954
955 %% keep track of used colors
956 \newcount\@karnaughmap@var@colorindex@\relax
957 \newcount\@karnaughmap@var@colorindexnext@\relax
958 \@karnaughmap@var@colorindex@=0\relax
959 \@karnaughmap@var@colorindexnext@=1\relax
960
961 % ^^A ##########################################################################
962 % ^^A ##########################################################################
963 % ^^A #### /CODE ####
964 % ^^A ##########################################################################
965 % ^^A ##########################################################################
966 % \end{macrocode}
967 % \fi
968 %
969 % \newpage
970 % \subsection{Implicants}
971 % \begin{macro}{\implicant}
972 % The |\implicant| command draws quadratic implicants on one or multiple submaps. If the implicant shall be drawn on multiple submaps, \marg{northwest cell} and \marg{southeast cell} must be specified as if the implicant was to be drawn on the 0:th submap. When turned on, colorization is done automatically, following a global sequence of available colors.
973 %
974 % \textbf{Usage:}
975 %
976 % \begin{tabularx}{\textwidth}{l X}
977 % \small{|\implicant|} & \\
978 % \small{\marg{northwest cell}} & \small{The most northwest cell in the implicant} \\
979 % \small{\marg{southeast cell}} & \small{The most southeast cell in the implicant} \\
980 % \small{\oarg{submaps}} & \small{Comma separated list of submaps the implicant should be drawn on. Default: ''0''} \\
981 % \end{tabularx}
982 %
983 % \textbf{Example:}
984 %
985 % \begin{multicols}{2}
986 % [Implicant around the four most inner cells.]
987 % \begin{verbatim}
988 %\begin{karnaugh-map}
989 % \implicant{5}{15}
990 %\end{karnaugh-map}
991 % \end{verbatim}
992 % \columnbreak
993 % \resizebox{\columnwidth}{!}{%
994 % \begin{karnaugh-map}
995 % \implicant{5}{15}
996 % \end{karnaugh-map}%
997 % }
998 % \end{multicols}
999 % \begin{multicols}{2}
1000 % [Single cell implicant, 0:th cell, on all four submaps.]
1001 % \begin{verbatim}
1002 %\begin{karnaugh-map}[4][4][4]
1003 % \implicant{0}{0}[0,1,2,3]
1004 %\end{karnaugh-map}
1005 % \end{verbatim}
1006 % \columnbreak
1007 % \resizebox{\columnwidth}{!}{%
1008 % \begin{karnaugh-map}[4][4][4]
1009 % \implicant{0}{0}[0,1,2,3]
1010 % \end{karnaugh-map}%
1011 % }
1012 % \end{multicols}
1013 % \iffalse code
1014 % \begin{macrocode}
1015 % ^^A ##########################################################################
1016 % ^^A ##########################################################################
1017 % ^^A #### CODE ####
1018 % ^^A ##########################################################################
1019 % ^^A ##########################################################################
1020 \DeclareDocumentCommand{\implicant}{m m O{0}} {%
1021 % bail if outside environment karnaugh-map
1022 \@karnaughmap@func@bailoutsideenvironment@{}
1023 %
1024 % fetch new color
1025 \@karnaughmap@func@updatecolor@{}
1026 %
1027 \begingroup
1028 % loop through specified sub maps
1029 \foreach \map in {#3} {%
1030 % make sure we don't try to draw on non existing sub maps
1031 \ifnum\map<\@karnaughmap@var@mapsizez@
1032 % calculate cell number for the specified sub maps {[START]
1033 \newcount\@karnaughmap@local@northwest@\relax
1034 \newcount\@karnaughmap@local@southeast@\relax
1035 \@karnaughmap@local@northwest@=\map\relax
1036 \@karnaughmap@local@southeast@=\map\relax
1037 \multiply\@karnaughmap@local@northwest@ by 16\relax
1038 \multiply\@karnaughmap@local@southeast@ by 16\relax
1039 \advance\@karnaughmap@local@northwest@ by #1\relax
1040 \advance\@karnaughmap@local@southeast@ by #2\relax
1041 % [END]}
1042 % only fill marking when \@karnaughmap@var@bw@ = '0'
1043 \ifnum0=\@karnaughmap@var@bw@
1044 \fill[
1045 rounded corners=3pt,
1046 fill=\@karnaughmap@var@color@,
1047 fill opacity=0.25,
1048 ] {
1049 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@northwest@}.center)+(-0.3,0.3)$)
1050 rectangle
1051 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@southeast@}.center)+(0.3,-0.3)$)
1052 };
1053 \fi
1054 \draw[
1055 rounded corners=3pt,
1056 draw opacity=1.0,
1057 ] {
1058 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@northwest@}.center)+(-0.3,0.3)$)
1059 rectangle
1060 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@southeast@}.center)+(0.3,-0.3)$)
1061 };
1062 \else
1063 \PackageWarning{karnaugh-map}{%
1064 You can only draw on existing sub maps.
1065 Ignoring instruction to draw on non existing sub map number \map%
1066 }
1067 \fi
1068 }
1069 \endgroup
1070 }
1071 % ^^A ##########################################################################
1072 % ^^A ##########################################################################
1073 % ^^A #### /CODE ####
1074 % ^^A ##########################################################################
1075 % ^^A ##########################################################################
1076 % \end{macrocode}
1077 % \fi
1078 % \end{macro}
1079 %
1080 % \newpage
1081 % \begin{macro}{\implicantedge}
1082 % The |\implicantedge| command draws quadratic implicants with the middle of the implicant facing the edge of a submap either horizontally or vertically. The function is able to draw the same implicant on one or multiple submaps. However if the implicant shall be drawn on multiple submaps, \marg{northwest part - northwest cell}, \marg{northwest part - southeast cell}, \marg{southeast part - northwest cell}, \marg{southeast part - southeast cell} must be specified as if the implicant was to be drawn on the 0:th submap. When turned on, colorization is done automatically, following a global sequence of available colors.
1083 %
1084 % \textbf{Usage:}
1085 %
1086 % \begin{tabularx}{\textwidth}{l X}
1087 % \small{|\implicantedge|} & \\
1088 % \small{\marg{northwest part - northwest cell}} & \small{The most northwest cell in the northwest part of the implicant} \\
1089 % \small{\marg{northwest part - southeast cell}} & \small{The most southeast cell in the northwest part of the implicant} \\
1090 % \small{\marg{southeast part - northwest cell}} & \small{The most northwest cell in the southeast part of the implicant} \\
1091 % \small{\marg{southeast part - southeast cell}} & \small{The most southeast cell in the southeast part of the implicant} \\
1092 % \small{\oarg{submaps}} & \small{Comma separated list of submaps the implicant should be drawn on. Default: ''0''} \\
1093 % \end{tabularx}
1094 %
1095 % \textbf{Example:}
1096 %
1097 % \begin{multicols}{2}
1098 % [Horizontal implicant over the submap edge containing the cells 4, 6, 12, and 14.]
1099 % \begin{verbatim}
1100 %\begin{karnaugh-map}
1101 % \implicantedge{4}{12}{6}{14}
1102 %\end{karnaugh-map}
1103 % \end{verbatim}
1104 % \columnbreak
1105 % \resizebox{\columnwidth}{!}{%
1106 % \begin{karnaugh-map}
1107 % \implicantedge{4}{12}{6}{14}
1108 % \end{karnaugh-map}%
1109 % }
1110 % \end{multicols}
1111 % \iffalse code
1112 % \begin{macrocode}
1113 % ^^A ##########################################################################
1114 % ^^A ##########################################################################
1115 % ^^A #### CODE ####
1116 % ^^A ##########################################################################
1117 % ^^A ##########################################################################
1118 \DeclareDocumentCommand{\implicantedge}{m m m m O{0}} {%
1119 % bail if outside environment karnaugh-map
1120 \@karnaughmap@func@bailoutsideenvironment@{}
1121 %
1122 % fetch new color
1123 \@karnaughmap@func@updatecolor@{}
1124 %
1125 \begingroup
1126 % helper variables {[START]
1127 \newcommand{\@karnaughmap@local@orientation@}{0} % '0' is a vertical and '1' is a horizontal implicant
1128 \newcommand{\@karnaughmap@local@coordinateone@}{0}
1129 \newcommand{\@karnaughmap@local@coordinatetwo@}{0}
1130 \newcommand{\@karnaughmap@local@mirror@}{1} % '1' or '-1' to mirror
1131 \newcommand{\@karnaughmap@local@bordercontent@}{}
1132 \newcommand{\@karnaughmap@local@fillcontent@}{}
1133 % [END]}
1134 % determinate if this is an horizontal or vertical implicant {[START]
1135 \newcount\@karnaughmap@local@testcaseone@\relax
1136 \newcount\@karnaughmap@local@testcasetwo@\relax
1137 \@karnaughmap@local@testcaseone@=#1\relax
1138 \@karnaughmap@local@testcasetwo@=#1\relax
1139 \advance\@karnaughmap@local@testcaseone@ by -#2\relax
1140 \advance\@karnaughmap@local@testcasetwo@ by -#3\relax
1141 \ifnum\@karnaughmap@local@testcaseone@<0 \multiply\@karnaughmap@local@testcaseone@ by -1\relax\fi
1142 \ifnum\@karnaughmap@local@testcasetwo@<0 \multiply\@karnaughmap@local@testcasetwo@ by -1\relax\fi
1143 % test case one
1144 \ifnum\@karnaughmap@local@testcaseone@<\@karnaughmap@var@mapsizex@
1145 % this is a vertical implicant
1146 \renewcommand{\@karnaughmap@local@orientation@}{0}
1147 \else
1148 % this is a horizontal implicant
1149 \renewcommand{\@karnaughmap@local@orientation@}{1}
1150 \fi
1151 % test case two
1152 \ifnum\@karnaughmap@local@testcasetwo@<\@karnaughmap@var@mapsizex@
1153 % this is a vertical implicant
1154 \renewcommand{\@karnaughmap@local@orientation@}{1}
1155 \fi
1156 % [END]}
1157 % loop through specified sub maps
1158 \foreach \map in {#5} {%
1159 % make sure we don't try to draw on non existing sub maps
1160 \ifnum\map<\@karnaughmap@var@mapsizez@
1161 % loop through both parts of the marking(ie. left and right part)
1162 \foreach \i in {0,1} {%
1163 % set parameters depending on the part of the marking(ie. left and right part) {[START]
1164 \ifnum\i=0
1165 \renewcommand{\@karnaughmap@local@coordinateone@}{#1}
1166 \renewcommand{\@karnaughmap@local@coordinatetwo@}{#2}
1167 \renewcommand{\@karnaughmap@local@mirror@}{1}
1168 \else
1169 \renewcommand{\@karnaughmap@local@coordinateone@}{#3}
1170 \renewcommand{\@karnaughmap@local@coordinatetwo@}{#4}
1171 \renewcommand{\@karnaughmap@local@mirror@}{-1}
1172 \fi
1173 % [END]}
1174 % calculate cell numbers for the specified sub map {[START]
1175 \newcount\@karnaughmap@local@coordinateonecounter@\relax
1176 \newcount\@karnaughmap@local@coordinatetwocounter@\relax
1177 \@karnaughmap@local@coordinateonecounter@=\map\relax
1178 \@karnaughmap@local@coordinatetwocounter@=\map\relax
1179 \multiply\@karnaughmap@local@coordinateonecounter@ by 16\relax
1180 \multiply\@karnaughmap@local@coordinatetwocounter@ by 16\relax
1181 \advance\@karnaughmap@local@coordinateonecounter@ by \@karnaughmap@local@coordinateone@\relax
1182 \advance\@karnaughmap@local@coordinatetwocounter@ by \@karnaughmap@local@coordinatetwo@\relax
1183 \renewcommand{\@karnaughmap@local@coordinateone@}{\@karnaughmap@local@coordinateonecounter@}
1184 \renewcommand{\@karnaughmap@local@coordinatetwo@}{\@karnaughmap@local@coordinatetwocounter@}
1185 % [END]}
1186 % select drawing content depending on orientation {[START]
1187 \ifnum\@karnaughmap@local@orientation@=0
1188 % this is a vertical implicant
1189 \renewcommand{\@karnaughmap@local@fillcontent@}{%
1190 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.3,.6*\@karnaughmap@local@mirror@)$)
1191 --
1192 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3,.6*\@karnaughmap@local@mirror@)$)
1193 { [rounded corners=3pt] --
1194 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3,-.3*\@karnaughmap@local@mirror@)$) }
1195 { [rounded corners=3pt] --
1196 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.3,-.3*\@karnaughmap@local@mirror@)$) }
1197 -- cycle
1198 }
1199 \renewcommand{\@karnaughmap@local@bordercontent@}{%
1200 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3,.6*\@karnaughmap@local@mirror@)$)
1201 { [rounded corners=3pt] --
1202 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3,-.3*\@karnaughmap@local@mirror@)$) }
1203 { [rounded corners=3pt] --
1204 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.3,-.3*\@karnaughmap@local@mirror@)$) }
1205 --
1206 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.3,.6*\@karnaughmap@local@mirror@)$)
1207 }
1208 \else
1209 % this is a horizontal implicant
1210 \renewcommand{\@karnaughmap@local@fillcontent@}{%
1211 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(-.6*\@karnaughmap@local@mirror@,-.3)$)
1212 --
1213 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.6*\@karnaughmap@local@mirror@,.3)$)
1214 { [rounded corners=3pt] --
1215 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(.3*\@karnaughmap@local@mirror@,.3)$) }
1216 { [rounded corners=3pt] --
1217 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3*\@karnaughmap@local@mirror@,-.3)$) }
1218 -- cycle
1219 }
1220 \renewcommand{\@karnaughmap@local@bordercontent@}{%
1221 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(-.6*\@karnaughmap@local@mirror@,.3)$)
1222 { [rounded corners=3pt] --
1223 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinateone@}.center)+(.3*\@karnaughmap@local@mirror@,.3)$) }
1224 { [rounded corners=3pt] --
1225 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(.3*\@karnaughmap@local@mirror@,-.3)$) }
1226 --
1227 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinatetwo@}.center)+(-.6*\@karnaughmap@local@mirror@,-.3)$)
1228 }
1229 \fi
1230 % [END]}
1231 % draw
1232 % only fill marking when \@karnaughmap@var@bw@ = '0'
1233 \ifnum0=\@karnaughmap@var@bw@
1234 \fill[
1235 sharp corners,
1236 fill=\@karnaughmap@var@color@,
1237 fill opacity=0.25,
1238 ] {
1239 \@karnaughmap@local@fillcontent@%
1240 };
1241 \fi
1242 \draw[
1243 sharp corners,
1244 draw opacity=1.0,
1245 ] {
1246 \@karnaughmap@local@bordercontent@%
1247 };
1248 }
1249 \else
1250 \PackageWarning{karnaugh-map}{%
1251 You can only draw on existing sub maps.
1252 Ignoring instruction to draw on non existing sub map number \map%
1253 }
1254 \fi
1255 }
1256 \endgroup
1257 }
1258 % ^^A ##########################################################################
1259 % ^^A ##########################################################################
1260 % ^^A #### /CODE ####
1261 % ^^A ##########################################################################
1262 % ^^A ##########################################################################
1263 % \end{macrocode}
1264 % \fi
1265 % \end{macro}
1266 %
1267 % \newpage
1268 % \begin{macro}{\implicantcorner}
1269 % The |\implicantcorner| command draws an implicant around only the four corner pieces on one or multiple four variable karnaugh submaps. When turned on, colorization is done automatically, following a global sequence of available colors.
1270 %
1271 % \textbf{Usage:}
1272 %
1273 % \begin{tabularx}{\textwidth}{l X}
1274 % \small{|\implicantcorner|} & \\
1275 % \small{\oarg{submaps}} & \small{Comma separated list of submaps the implicant should be drawn on. Default: ''0''} \\
1276 % \end{tabularx}
1277 %
1278 % \textbf{Example:}
1279 %
1280 % \begin{multicols}{2}
1281 % [Draw an implicant around all corners on 0th and 2nd submap of a six variable karnaugh map.]
1282 % \begin{verbatim}
1283 %\begin{karnaugh-map}[4][4][4]
1284 % \implicantcorner[0,2]
1285 %\end{karnaugh-map}
1286 % \end{verbatim}
1287 % \columnbreak
1288 % \resizebox{\columnwidth}{!}{%
1289 % \begin{karnaugh-map}[4][4][4]
1290 % \implicantcorner[0,2]
1291 % \end{karnaugh-map}%
1292 % }
1293 % \end{multicols}
1294 % \iffalse code
1295 % \begin{macrocode}
1296 % ^^A ##########################################################################
1297 % ^^A ##########################################################################
1298 % ^^A #### CODE ####
1299 % ^^A ##########################################################################
1300 % ^^A ##########################################################################
1301 \DeclareDocumentCommand{\implicantcorner}{O{0}} {%
1302 % bail if outside environment karnaugh-map
1303 \@karnaughmap@func@bailoutsideenvironment@{}
1304 %
1305 % make sure "\implicantcorner" only are used on 4x4 maps
1306 \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@=44
1307 % fetch new color
1308 \@karnaughmap@func@updatecolor@{}
1309 % loop through specified sub maps
1310 \foreach \map in {#1} {%
1311 % make sure we don't try to draw on non existing sub maps
1312 \ifnum\map<\@karnaughmap@var@mapsizez@
1313 % loop through the four corners
1314 \foreach \corner in {0,2,8,10} {%
1315 % calculate corner's properties {[START]
1316 \newcount\@karnaughmap@local@coordinate@\relax
1317 \@karnaughmap@local@coordinate@=\map\relax
1318 \multiply\@karnaughmap@local@coordinate@ by 16\relax
1319 \advance\@karnaughmap@local@coordinate@ by \corner\relax
1320 \newcommand{\@karnaughmap@local@mirrorx@}{0} % '1' or '-1' to mirror
1321 \newcommand{\@karnaughmap@local@mirrory@}{0} % '1' or '-1' to mirror
1322 \ifnum\corner=0 \renewcommand{\@karnaughmap@local@mirrorx@}{1}\renewcommand{\@karnaughmap@local@mirrory@}{1}\fi
1323 \ifnum\corner=2 \renewcommand{\@karnaughmap@local@mirrorx@}{-1}\renewcommand{\@karnaughmap@local@mirrory@}{1}\fi
1324 \ifnum\corner=8 \renewcommand{\@karnaughmap@local@mirrorx@}{1}\renewcommand{\@karnaughmap@local@mirrory@}{-1}\fi
1325 \ifnum\corner=10 \renewcommand{\@karnaughmap@local@mirrorx@}{-1}\renewcommand{\@karnaughmap@local@mirrory@}{-1}\fi
1326 % [END]}
1327 % draw
1328 % only fill marking when \@karnaughmap@var@bw@ = '0'
1329 \ifnum0=\@karnaughmap@var@bw@
1330 \fill[
1331 sharp corners,
1332 fill=\@karnaughmap@var@color@,
1333 fill opacity=0.25,
1334 ]
1335 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(-.6*\@karnaughmap@local@mirrorx@,.6*\@karnaughmap@local@mirrory@)$)
1336 --
1337 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(.3*\@karnaughmap@local@mirrorx@,.6*\@karnaughmap@local@mirrory@)$)
1338 { [rounded corners=3pt] --
1339 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(.3*\@karnaughmap@local@mirrorx@,-.3*\@karnaughmap@local@mirrory@)$) }
1340 --
1341 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(-.6*\@karnaughmap@local@mirrorx@,-.3*\@karnaughmap@local@mirrory@)$)
1342 -- cycle;
1343 \fi
1344 \draw[
1345 sharp corners,
1346 draw opacity=1.0,
1347 ]
1348 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(.3*\@karnaughmap@local@mirrorx@,.6*\@karnaughmap@local@mirrory@)$)
1349 { [rounded corners=3pt] --
1350 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(.3*\@karnaughmap@local@mirrorx@,-.3*\@karnaughmap@local@mirrory@)$) }
1351 --
1352 ($(\@karnaughmap@func@decimaltobin@{\@karnaughmap@local@coordinate@}.center)+(-.6*\@karnaughmap@local@mirrorx@,-.3*\@karnaughmap@local@mirrory@)$);
1353 }
1354 \else
1355 \PackageWarning{karnaugh-map}{%
1356 You can only draw on existing sub maps.
1357 Ignoring instruction to draw on non existing sub map number \map%
1358 }
1359 \fi
1360 }
1361 \else
1362 % print error if "\implicantcorner" are used on non 4x4 map
1363 \PackageError{karnaugh-map}{%
1364 \protect\implicantcorner\space can only be used on 4x4 maps%
1365 }{%
1366 You are trying to use \protect\implicantcorner\space on non 4x4 map.%
1367 }
1368 \fi
1369 }
1370 % ^^A ##########################################################################
1371 % ^^A ##########################################################################
1372 % ^^A #### /CODE ####
1373 % ^^A ##########################################################################
1374 % ^^A ##########################################################################
1375 % \end{macrocode}
1376 % \fi
1377 % \end{macro}
1378 %
1379 % \newpage
1380 % \subsection{Options}\label{sec:usage:options}
1381 % 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.
1382 % \begin{verbatim}
1383 %\usepackage[options]{karnaugh-map}
1384 %\end{verbatim}
1385 %
1386 % The local options, which have precedence over the global options, are defined when a |karnaugh-map| environment is started.
1387 %
1388 % \begin{verbatim}
1389 %\begin{karnaugh-map}(options)
1390 %\end{karnaugh-map}
1391 %\end{verbatim}
1392 %
1393 % \textbf{Available options are:}
1394 %
1395 % \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\}}.
1396 % \changes{v2.0}{2021/12/15}{Support custom implicant colors}
1397 %
1398 % \begin{figure}[H]
1399 % \centering
1400 % \resizebox{.25\textwidth}{!}{%
1401 % \begin{karnaugh-map}(implicantcolors={orange,violet})[2][2][1]
1402 % \minterms{1,2}
1403 % \autoterms[0]
1404 % \implicant{1}{1}
1405 % \implicant{2}{2}
1406 % \end{karnaugh-map}%
1407 % }
1408 % \end{figure}
1409 %
1410 % \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}.
1411 % \changes{v2.0}{2018/11/20}{Support alternate input label position}
1412 %
1413 % \begin{figure}[H]
1414 % \centering
1415 % \resizebox{.75\textwidth}{!}{%
1416 % \begin{karnaugh-map}
1417 % \end{karnaugh-map}%
1418 % \begin{karnaugh-map}(label=corner)
1419 % \end{karnaugh-map}%
1420 % }
1421 % \end{figure}
1422 %
1423 % \newpage
1424 % \section{Examples}
1425 % \begin{multicols}{2}
1426 % [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)$}.]
1427 % \begin{verbatim}
1428 %\begin{karnaugh-map}[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
1429 % \minterms{0,1,2,3,8,13,17,20,22,28,
1430 % 33,32,30,19,40,35,49,42,34,10,60,
1431 % 54,62,51,52}
1432 % \indeterminants{15,45,47}
1433 % \autoterms[0]
1434 % \implicantcorner[0,2]
1435 % \implicant{1}{3}[0,1,2,3]
1436 % \implicantedge{4}{12}{6}{14}[1,3]
1437 % \implicant{13}{15}[0,2]
1438 %\end{karnaugh-map}
1439 % \end{verbatim}
1440 % \columnbreak
1441 % \vspace*{0.25em}
1442 % \resizebox{\columnwidth}{!}{%
1443 % \begin{karnaugh-map}[4][4][4][$a$][$b$][$c$][$d$][$e$][$f$]
1444 % \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}
1445 % \indeterminants{15,45,47}
1446 % \autoterms[0]
1447 % \implicantcorner[0,2]
1448 % \implicant{1}{3}[0,1,2,3]
1449 % \implicantedge{4}{12}{6}{14}[1,3]
1450 % \implicant{13}{15}[0,2]
1451 % \end{karnaugh-map}%
1452 % }
1453 % \end{multicols}
1454 %
1455 % \begin{multicols}{2}
1456 % [Draw a karnaugh map for \small{$f(X_0,X_1) = \Pi(0,2,3)$} in black and white.]
1457 % \begin{verbatim}
1458 %\begin{karnaugh-map}*[2][2][1]
1459 % \maxterms{0,2,3}
1460 % \autoterms[1]
1461 % \implicant{1}{1}
1462 %\end{karnaugh-map}
1463 % \end{verbatim}
1464 % \columnbreak
1465 % \resizebox{\columnwidth}{!}{%
1466 % \begin{karnaugh-map}*[2][2][1]
1467 % \maxterms{0,2,3}
1468 % \autoterms[1]
1469 % \implicant{1}{1}
1470 % \end{karnaugh-map}%
1471 % }
1472 % \end{multicols}
1473 %
1474 % \newpage
1475 % \begin{multicols}{2}
1476 % [Draw a variable entered map.]
1477 % \begin{verbatim}
1478 %\begin{karnaugh-map}[4][2][1][$a$][$b$][$c$]
1479 % \maxterms{0,2,4,5,6}
1480 % \minterms{3}
1481 % \terms{1}{$d$}
1482 % \terms{7}{$d'$}
1483 % \implicant{1}{3}
1484 % \implicant{3}{7}
1485 %\end{karnaugh-map}
1486 % \end{verbatim}
1487 % \columnbreak
1488 % \resizebox{\columnwidth}{!}{%
1489 % \begin{karnaugh-map}[4][2][1][$a$][$b$][$c$]
1490 % \maxterms{0,2,4,5,6}
1491 % \minterms{3}
1492 % \terms{1}{$d$}
1493 % \terms{7}{$d'$}
1494 % \implicant{1}{3}
1495 % \implicant{3}{7}
1496 % \end{karnaugh-map}%
1497 % }
1498 % \end{multicols}
1499 %
1500 % \section{Dependencies}
1501 % \begin{itemize}
1502 % \item keyval
1503 % \item kvoptions
1504 % \item tikz
1505 % \item xparse
1506 % \item xstring
1507 % \end{itemize}
1508 %
1509 % \newpage
1510 % \section{Miscellaneous}
1511 % \subsection*{Resizing}
1512 % 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.
1513 % \begin{verbatim}
1514 %\resizebox{\columnwidth}{!}{%
1515 % \begin{karnaugh-map}
1516 % \end{karnaugh-map}%
1517 %}
1518 % \end{verbatim}
1519 %
1520 % \subsection*{Comma separated lists}
1521 % 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.
1522 %
1523 % 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.
1524 %
1525 \endinput