Module:2-ary truth table
Appearance
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module depends on the following other modules: |
| This module uses TemplateStyles: |
This module implements {{2-ary truth table}}
Usage
{{#invoke:2-ary truth table|main}}
local p = {}
local A_col = {false, false, true, true}
local B_col = {false, true, false, true}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
-- start table
root = mw.html.create('table')
:addClass('wikitable')
:addClass('sortable')
:addClass('two-ary-tt')
-- add headings
local A = frame:extensionTag("math",args['A'] or 'A',{})
local B = frame:extensionTag("math",args['B'] or 'B',{})
local row = root:tag('tr')
row:tag('th'):wikitext(A)
row:tag('th'):wikitext(B)
local thick_border = {}
local col = 1
thick_border[col] = true
while args[6*col - 1] do
thick_border[col + 1] = string.lower(args[6*col] or '') == 'thick'
row:tag('th')
:addClass('unsortable')
:addClass(thick_border[col] and 'border' or nil)
:wikitext(args[6*col - 1])
col = col + 1
end
local total_cols = col - 1
for i = 1,4 do
row = root:tag('tr')
-- A col
row:tag('td')
:addClass('bold')
:addClass(A_col[i] and 't' or 'f')
:wikitext(A_col[i] and 'T' or 'F')
-- B col
row:tag('td')
:addClass('bold')
:addClass(B_col[i] and 't' or 'f')
:wikitext(B_col[i] and 'T' or 'F')
-- Remaining cols
for j = 1,total_cols do
local val = (tonumber(args[6*j - 6 + i]) or 0) == 1
row:tag('td')
:addClass(val and 't' or 'f')
:addClass(thick_border[j] and 'border' or nil)
:wikitext(val and 'T' or 'F')
end
end
local templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = 'Template:2-ary truth table/style.css' }
}
return templatestyles .. tostring(root)
end
return p