diff options
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty b/Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty index 94403911ad2..991074264a0 100644 --- a/Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty +++ b/Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty @@ -15,7 +15,7 @@ % % This work consists of the file truthtable.sty. \NeedsTeXFormat{LaTeX2e}[1994/06/01] -\ProvidesPackage{truthtable}[2021/10/01 0.0.1 Package for generating truth tables automatically using LuaTeX] +\ProvidesPackage{truthtable}[2021/10/08 0.0.2 Package for generating truth tables automatically using LuaTeX] \ProcessOptions\relax \@ifpackageloaded{luacode}{ @@ -34,6 +34,14 @@ function Equiv(a,b) return ((a and b) or ((not a) and (not b))); end +function Xor(a,b) + return ((a or b) and (not (a and b))); +end + +function Nand(a,b) + return (not (a and b)); +end + function ComputeRows(header) return 2^header end @@ -47,7 +55,8 @@ function Split(s, delimiter) end function EvaluateFormula(formula) - local parsedFormula = "function res() return( " .. string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, " ", ""),">>","Impl"),"__","Equiv"),"!","not "),"&" ," and "),"|"," or "),";",",") .. " ) end"; + + local parsedFormula = "function res() return( " .. string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, " ", ""),">>","Impl"),"__","Equiv"),"<>","Equiv"),"%^","Xor"),"!&","Nand"),"!","not "),"&" ," and "),"|"," or "),";",",") .. " ) end"; chunk = load(parsedFormula); chunk(); @@ -84,6 +93,9 @@ function printTruthValue(expr, dTrue, dFalse) end function parse(commaSepVariables, commaSepDisplayVariables, commaSepResultRows, commaSepResultDisplayRows, displayTrue, displayFalse) + + print("\n\ntruthtable v0.0.2\n") + local vrbls = Split(commaSepVariables, ","); local numberOfColumns = #(vrbls); local rows = ComputeRows(numberOfColumns); @@ -93,8 +105,14 @@ function parse(commaSepVariables, commaSepDisplayVariables, commaSepResultRows, local dHeader = string.gsub(commaSepDisplayVariables, ",", " & ") .. " & " .. string.gsub(commaSepResultDisplayRows, ",", " & ") .. " \\\\ \\hline"; - if (not (numberOfColumns == #(vrbls) and numberOfColumns == #(dVrbls))) then - return("error"); + if (#(dVrbls) ~= #(vrbls)) then + print("Error: The number of variables does not match the number of display variables."); + return + end + + if (#(dResRows) ~= #(resRows)) then + print("Error: The number of statements does not match the number of display statements."); + return end local tableContent = dHeader; @@ -135,7 +153,7 @@ function parse(commaSepVariables, commaSepDisplayVariables, commaSepResultRows, tableContent = tableContent .. "\n" .. row end - + tex.print(tableContent); end |