Module:2-ary truth table
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the 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 row = root.tag('tr')
row:tag('th'):tag('math'):wikitext(args['A'] or 'A')
row:tag('th'):tag('math'):wikitext(args['B'] or 'B')
local thick_border = {}
local col = 1
thick_border[col] = false
while args[6*col - 1] do
thick_border[col + 1] = (args[6*col] or '').lower() == '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 - 5 + i]) or 0
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