Changes

Jump to navigation Jump to search
8,731 bytes added ,  22:43, 5 July 2021
Created a page for my module!
This is a ConTeXt user module that draws Karnaugh maps containing data (ones, ceros, or anything) and their groupings, with easy to use syntax. It supports larger than four variable maps; and formulas, or any text, can be added.

The PDF documentation (with the actual maps) is [https://github.com/VicSanRoPe/context-karnaugh/blob/master/doc/context/third/karnaugh/karnaugh-docs.pdf here]

= Options =

To draw a Karnaugh map, the <code>karnaugh</code> environment is used, the options specified here override the global options.

<pre>\startkarnaugh [..,..=..,..] ... \stopkarnaugh</pre>
The options are set globally with the <code>setupkarnaugh</code> command.

<pre>\setupkarnaugh [..,..=..,..]
ylabels = LIST
xlabels = LIST
ny = NUMBER
nx = NUMBER
name = TEXT
labelstyle = edge corner
groupstype = pass stop
indices = yes no on off
spacing = small big normal NUMBER
indicesstart = NUMBER</pre>
* The options <code>ylabels</code> and <code>xlabels</code> are the input variables used for the map, they are written as a list, and math mode is usually used for each individual element. <code>xlabels</code> refers to the variables at the top of the map, and the last element is the least significant variable (for indices and minterms). <code>ylabels</code> are at the left, its first element is the most significant variable. If these labels are not specified, then the labels will be I<sub>0</sub> , I<sub>1</sub> , I<sub>2</sub>, and so on.
* The options <code>ny</code> and <code>nx</code> are the map’s size in number of cells, they are calculated automatically when labels are specified, and if no size or labels are specified but there is data, the size of the map is guessed with the newline characters.
* The <code>name</code> option is some text that is added on top or on the top-left corner of the map, the name of the function could be placed there.
* The <code>labelstyle</code> option specifies whether the input variables are placed in a corner of the map (value: corner) or at the edges (value: edge). By default, the corner style is used for small maps and the edge style is used for 5 variable maps or larger.
* The <code>groupstyle</code> option changes how the group’s lines are drawn, if its value is <code>pass</code> (the default), the lines continue for a bit outside of the map. If it is <code>stop</code>, they will not, which might be preferred when making a combination of maps using the overlay method, to mark that some adjacent groups are not connected, but the effect is minimal.
* If the <code>indices</code> option is set to yes or on, it will draw a small number on every cell with the value of the input variables in decimal. If groups are also being drawn, the map’s spacing will be enlarged to accommodate both things and the data.
* The <code>spacing</code> option simply increases or decreases the whitespace around every cell’s data. Please note that the document’s font size affects the map’s size, such that is looks the same, just smaller or bigger, always with the same font as the main text. To make the maps have a constant size, surround them with <code>\scale</code> spacing can be a number too, adjust both of these to get the proportions you want.

= Data input =

== As a list ==

<pre>\karnaughtabledata {...,...}</pre>
This command fills the map with the elements specified in the comma separated list in the same order as the truth table. Space before and after a comma is ignored. If all elements are just one simple character (very common), then the elements may be written one after the other, with no commas or spaces. The map’s size is calculated automatically if no size or labels are given. The elements aren’t limited to ceros and ones, they just have to be short.

<pre>\karnaughminterms {...,...}
\karnaughmaxterms {...,...}</pre>
These commands place ones or ceros (respectively) on the specified locations (written as a list of the decimal values of the input variables) and then fill the rest of the map with the opposite symbol.

<texcode>
\startkarnaugh[ylabels={A}, xlabels={B}]
\karnaughminterms{0, 3}
\stopkarnaugh
</texcode>

== As a map ==

<pre>\startkarnaughdata ... \stopkarnaughdata</pre>
Inside of this environment the data is placed as a comma separated list, preferably with newlines at every row, in the same positions as they will appear on the map. A trailing comma is ignored, and cells may be left empty.

<texcode>
\startkarnaugh[ylabels={d, c}, xlabels={b, a}]
\startkarnaughdata
1, 0, 1, 0,
0, 1, 1, 0,
1, 0, 1, 0,
0, 1, 1, 0,
\stopkarnaughdata
\stopkarnaugh
</texcode>

= Groups and other data =

This data is input with the map syntax because presumably the map is already drawn with the ones and ceros, and drawing the groups “in-place” is much easier than calculating the coordinates of the desired groups.

<pre>\startkarnaughgroups ... \stopkarnaughgroups</pre>
Inside of this environment various types of data are placed as a comma separated list with as many elements as there are cells in the map. Any cell may contain various instances of any of the information types mentioned here.

== Groups ==

Groups are input by inserting a letter (one per group) on every cell the group covers. The way they are drawn is handled automatically. The uppercase letters have colors assigned to them. The following example has three groups: at the corners, the edges, and in the middle.

<texcode>
\startkarnaugh[ny=4, nx=4]
\startkarnaughgroups
BA, , , BA,
B, C, C, B,
, C, C, ,
A, , , A,
\stopkarnaughgroups
\stopkarnaugh
</texcode>

== Notes ==

After drawing a Karnaugh map, it is useful to know which term of the produced formula represents each group. These can be drawn as text with arrows coming from the desired group.

<pre>\karnaughnote {...}{...}{...}
CHARACTER
CONTENT
tr Tr tl Tl br Br bl Bl lb lt rb rt r b</pre>
The base of the arrow is specified in the <code>karnaughgroups</code> environment as an asterisk after the group it represents, and the remaining data is specified using the <code>karnaughnote</code> command. The first argument is the character assigned to the group, the second is the text to be added to the map, and the third is one of the specified directions the arrow may point to.

The first letter of the direction is where it will mainly point towards, with <code>t</code> meaning top, <code>b</code> meaning bottom, <code>l</code> meaning left, and <code>r</code> meaning right; if it is uppercase it will be further separated from the map (for two rows of text, for example). The second letter (if present) will be a slight offset to the desired side, mainly to make the arrow not overlap with the grey code to the top and left. The arrows look better when they come out of a group’s corner.

<texcode>
\startkarnaugh[ny=4, nx=4]
\startkarnaughgroups
B*A, , , BA,
B, C, C, B,
, C, C*, ,
A*, , , A,
\stopkarnaughgroups
\karnaughnote{A}{A's note}{b}
\karnaughnote{B}{B's note}{Tr}
\karnaughnote{C}{C's note}{rb}
\stopkarnaugh
</texcode>

== Connecting lines ==

This feature is only used when drawing Karnaugh maps with more than 4 variables, then a mirror line is drawn in the middle, and groups which exist in both halves should be connected to each other.

To draw connections, a single plus <code>+</code> is placed in the <code>karnaughgroups</code> environment after the letter of the group to be connected, and at least one minus <code>-</code> has to be placed after the letter of a different region of the group.

The following example shows:
* The group <code>A</code> which is mirrored on both axis and has 3 lines connecting one part of the group to the rest. An arrow could be added to the bottom-right part, the cell would be <code>A+*</code> or <code>A*+</code>.
* The group <code>C</code> which is mirrored on one axis and thus has one connection line (the <code>+</code> and <code>-</code> can be switched around in this case)
* The group <code>B</code> with a completely unnecessary connection.

<texcode>
\startkarnaugh[ny=8, nx=8]
\startkarnaughgroups
, , , , , , , ,
, A, A-C, C, , A-, A, ,
, , C+, C, , , , ,
B+, , , , , , , B-,
B, , , , , , , B,
, , C-, C, , , , ,
, A, A-C, C, , A+, A, ,
, , , , , , , ,
\stopkarnaughgroups
\stopkarnaugh
</texcode>
5

edits

Navigation menu