diff options
author | Karl Berry <karl@freefriends.org> | 2021-10-09 20:49:12 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-10-09 20:49:12 +0000 |
commit | 87750c9264a7d4145078ecfbdc1b8bd8397827c1 (patch) | |
tree | 5da25db12f9c0dd557e1d1b0a5402d7a157a6abe | |
parent | d53ffabdc97c772548fffbde181b9c3843740004 (diff) |
truthtable (9oct21)
git-svn-id: svn://tug.org/texlive/trunk@60717 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/lualatex/truthtable/README.md | 10 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/truthtable/res/exampletable.tex | 6 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/truthtable/res/exampletableoutput.tex | 10 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/truthtable/truthtable.pdf | bin | 106754 -> 145325 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/truthtable/truthtable.tex | 220 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/truthtable/truthtable.sty | 28 |
6 files changed, 176 insertions, 98 deletions
diff --git a/Master/texmf-dist/doc/lualatex/truthtable/README.md b/Master/texmf-dist/doc/lualatex/truthtable/README.md index 18baedb8580..c41dd42fa32 100644 --- a/Master/texmf-dist/doc/lualatex/truthtable/README.md +++ b/Master/texmf-dist/doc/lualatex/truthtable/README.md @@ -2,7 +2,7 @@ *Copyright (C) Dominic Flück (K-Trout) 2021* <k-trout.ctan[at]protonmail[dot]ch> -truthtable 2021/10/01 v0.0.1 +truthtable 2021/10/08 v0.0.2 --- @@ -16,6 +16,14 @@ Details: [www.latex-project.org/lppl.txt](https://www.latex-project.org/lppl.txt A small LaTeX package for generating truth tables automatically. +## CTAN + +The package is available on CTAN: [ctan.org/pkg/truthtable](https://ctan.org/pkg/truthtable). + +## Github + +The package repository is on Github: [github.com/K-Trout/truthtable](https://github.com/K-Trout/truthtable). For bug reports and feature requests create an issue: [github.com/K-Trout/truthtable/issues](https://github.com/K-Trout/truthtable/issues) + ## Provided files - README.md (This file) diff --git a/Master/texmf-dist/doc/lualatex/truthtable/res/exampletable.tex b/Master/texmf-dist/doc/lualatex/truthtable/res/exampletable.tex index aabfc488c38..5de401796f5 100644 --- a/Master/texmf-dist/doc/lualatex/truthtable/res/exampletable.tex +++ b/Master/texmf-dist/doc/lualatex/truthtable/res/exampletable.tex @@ -1,9 +1,11 @@ \begin{table}[h] \centering - \begin{tabular}{c|c||c|c|c|c|c} + \begin{tabular}{c|c||c|c|c|c|c|c|c} % Content of table is generated using this single command. - \truthtable{A,B}{$A$,$B$}{!A, A & B, A | B, >>(A; B), __(A; B)}{$\lnot A$, $A \land B$, $A \lor B$, $A \rightarrow B$, $A \leftrightarrow B$}{$T$}{$F$} + \truthtable{A,B}{$A$,$B$} + {!A, A & B, A | B, ^(A; B), !&(A; B), >>(A; B), <>(A; B)}{$\lnot A$, $A \land B$, $A \lor B$,$A \veebar B$,$A | B$, $A \rightarrow B$, $A \leftrightarrow B$} + {$T$}{$F$} \end{tabular} \end{table}
\ No newline at end of file diff --git a/Master/texmf-dist/doc/lualatex/truthtable/res/exampletableoutput.tex b/Master/texmf-dist/doc/lualatex/truthtable/res/exampletableoutput.tex index 507049ca142..ab93cdeeb89 100644 --- a/Master/texmf-dist/doc/lualatex/truthtable/res/exampletableoutput.tex +++ b/Master/texmf-dist/doc/lualatex/truthtable/res/exampletableoutput.tex @@ -1,5 +1,5 @@ -$A$ & $B$ & $\lnot A$ & $A \land B$ & $A \lor B$ & $A \rightarrow B$ & $A \leftrightarrow B$ \\ \hline -$T$ & $T$ & $F$ & $T$ & $T$ & $T$ & $T$ \\ -$T$ & $F$ & $F$ & $F$ & $T$ & $F$ & $F$ \\ -$F$ & $T$ & $T$ & $F$ & $T$ & $T$ & $F$ \\ -$F$ & $F$ & $T$ & $F$ & $F$ & $T$ & $T$ \\
\ No newline at end of file +$A$ & $B$ & $\lnot A$ & $A \land B$ & $A \lor B$ & $A \veebar B$ & $A | B$ & $A \rightarrow B$ & $A \leftrightarrow B$ \\ \hline +$T$ & $T$ & $F$ & $T$ & $T$ & $F$ & $F$ & $T$ & $T$ \\ +$T$ & $F$ & $F$ & $F$ & $T$ & $T$ & $T$ & $F$ & $F$ \\ +$F$ & $T$ & $T$ & $F$ & $T$ & $T$ & $T$ & $T$ & $F$ \\ +$F$ & $F$ & $T$ & $F$ & $F$ & $F$ & $T$ & $T$ & $T$ \\
\ No newline at end of file diff --git a/Master/texmf-dist/doc/lualatex/truthtable/truthtable.pdf b/Master/texmf-dist/doc/lualatex/truthtable/truthtable.pdf Binary files differindex bd2c8df7d4e..2667782a89f 100644 --- a/Master/texmf-dist/doc/lualatex/truthtable/truthtable.pdf +++ b/Master/texmf-dist/doc/lualatex/truthtable/truthtable.pdf diff --git a/Master/texmf-dist/doc/lualatex/truthtable/truthtable.tex b/Master/texmf-dist/doc/lualatex/truthtable/truthtable.tex index a6d62fc606b..d95d7d2c6d5 100644 --- a/Master/texmf-dist/doc/lualatex/truthtable/truthtable.tex +++ b/Master/texmf-dist/doc/lualatex/truthtable/truthtable.tex @@ -32,7 +32,7 @@ showstringspaces=false, } \lstloadlanguages{ % Check documentation for further languages ... - [LaTeX]TeX + [LaTeX]TeX } \DeclareCaptionFont{blue}{\color{blue}} @@ -48,8 +48,8 @@ bookmarksnumbered=true, pdftitle={truthtable}, pdfauthor={Dominic Flück <K-Trout>}, - pdfsubject={truth LaTeX package}, - pdfkeywords={truthtable,LuaLaTeX, package, documentation, LaTeX}, + pdfsubject={truthtable package documentation v0.0.2}, + pdfkeywords={truthtable, LuaLaTeX, package, documentation, LaTeX}, pdfdisplaydoctitle=true, pdflang={en-GB}, pdfcreator={LuaHBTeX}, @@ -57,136 +57,186 @@ \usepackage{truthtable} +\usepackage{amssymb} \usepackage{bxtexlogo} \usepackage[ukenglish]{babel} +\usepackage{microtype} \title{\texttt{truthtable}\textbf{: \LaTeX\ Package\\for automatically generated Truth Tables}} \author{Dominic Flück <K-Trout>} -\date{0.0.1 2021/10/01} +\date{0.0.2 2021/10/08} \begin{document} - \maketitle +\maketitle - \begin{abstract} - \noindent \texttt{truthtable} is a \LaTeX\ package for creating automatically generating truth tables given a table header. It supports a number of logical operations which can be combined as needed. It's built upon the package \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} and therefor has to be used with the \LuaLaTeX\ compiler. - \end{abstract} +\begin{abstract} + \noindent \texttt{truthtable} is a \LaTeX\ package for creating automatically generating truth tables given a table header. It supports a number of logical operations which can be combined as needed. It's built upon the package \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} and therefore has to be used with the \LuaLaTeX\ compiler. +\end{abstract} - \tableofcontents +\tableofcontents - \section{Introduction} - Tables in \LaTeX\ have the reputation of being a bit tedious. When creating a table with many cells, such as a truth table, they are not only tedious to build, but also not very readable. +\section{Introduction} +Tables in \LaTeX\ have the reputation of being a bit tedious. When creating a table with many cells, such as a truth table, they are not only tedious to build, but also not very readable. - To help this situation when creating a truth table for a document, this package provides a macro, which allows simply for the variables and the columns of a truth table to be defined. The package then takes care of the rest. +To help this situation when creating a truth table for a document, this package provides a macro, which allows simply for the variables and the columns of a truth table to be defined. The package then takes care of the rest. - \section{Dependencies} +\section{Dependencies} - \texttt{truthtable} uses the package \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} to run, as the heavy lifting of the processing is done in \emph{Lua}. The package checks if \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} is already loaded, and if not, does so. \LuaLaTeX is required to compile the resulting documents. +\texttt{truthtable} uses the package \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} to run, as the heavy lifting of the processing is done in \emph{Lua}. The package checks if \href{https://ctan.org/pkg/luacode}{\texttt{luacode}} is already loaded, and if not, does so. \LuaLaTeX\ is required to compile the resulting documents. - \section{Usage} +\section{Usage} - The \texttt{truthtable} package provides as of this version a single command:\\ \texttt{\textbackslash truthtable\{\emph{comma separated variables}\}\{\emph{comma separated display variables}\}\\\{\emph{comma separated statements}\}\{\emph{comma separated display statements}\}\\\{\emph{display true value}\}\{\emph{display false value}\}} +The \texttt{truthtable} package provides as of this version a single command:\bigskip\\ +\noindent\texttt{\textbackslash truthtable\{\emph{comma separated variables}\}\{\emph{comma separated display variables}\}\\\{\emph{comma separated statements}\}\{\emph{comma separated display statements}\}\\\{\emph{display true value}\}\{\emph{display false value}\}} +\bigskip\\ +The command positions in the normal table boilerplate. This leads to the redundant practice of defining the column count twice, once for the table environment as the column layout and once in the command by defining the variables and statements.\footnote{See \autoref{lst:exampletable} for example} - This command is placed in the normal table boilerplate. This leads to the redundant practice of defining the column count twice, once for the table environment as the column layout and once in the command by defining the variables and statements.\footnote{See \autoref{lst:exampletable} for example} +This is intentional to allow for more flexibility in customising the column layout as well as pre- and appending of further rows to the table. - This is intentional to allow for more flexibility in customising the column layout as well as pre- and appending of further rows to the table. +\subsection{Comma separated variables} - \subsection{Comma separated variables} +The basic variables, for which every combination of \emph{true} and \emph{false} a row of table will be generated. The variables should be relatively simple, as they are not used for the formatting the table but simply to calculate the answers. The variables should be separated using commas. Don't use variables, which contain another variable, i.e., don't do this: \texttt{\{n,An\}}. - The basic variables, for which every combination of \emph{true} and \emph{false} a row of table will be generated. The variables should be relatively simple, as they are not used for the formatting the table but simply to calculate the answers. The variables should be separated using commas. Don't use variables, which contain another variable, i.e., don't do this: \emph{\{n,An\}}. +\subsection{Comma separated display variables} - \subsection{Comma separated display variables} +These are the display values corresponding to the \emph{Comma separated variables}. Fancy variable formatting can be applied. At least normal text and ``math'' mode seem to work.\footnote{More testing needs to be done} +The same number of display variables as variables is required. The comma cannot be used as a display character, as it is used as delimiter. - These are the display values corresponding to the \emph{Comma separated variables}. Fancy variable formatting can be applied. At least normal text and math mode seem to work.\footnote{More testing needs to be done} - The same number of display variables as variables is required. The comma cannot be used as a display character, as it is used as delimiter. +\subsection{Comma separated statements} - \subsection{Comma separated statements} +The statements using the \emph{Comma separated variables} which are used to evaluate the statements for any given combination of variables. Parentheses can be used in the normal fashion to indicate the order of combined statements. The notation for the different operations is as follows: - The statements using the \emph{Comma separated variables} which are used to evaluate the statements for any given combination of variables. Parentheses can be used in the normal fashion to indicate the order of combined statements. The notation for the different operations is as follows: +\subsubsection{\texttt{NOT} / Negation} - \subsubsection{\texttt{NOT} / Negation} +To negate a variable or statement, the exclamation point \texttt{!} is used. +\begin{itemize} + \item $\lnot A$: \texttt{!A} + \item $\lnot (\lnot A)$: \texttt{!(!A)} +\end{itemize} - To negate a variable or statement, the exclamation point \texttt{!} is used. - \begin{itemize} - \item $\lnot A$: \texttt{!A} - \item $\lnot (\lnot A)$: \texttt{!(!A)} - \end{itemize} +\subsubsection{\texttt{AND} / Conjunction} - \subsubsection{\texttt{AND} / Conjunction} +For the conjunction of two variables or statements the and symbol \texttt{\&} is used. \textbf{The \& must not be escaped for the comma separated statements!} +\begin{itemize} + \item $A \land B$: \texttt{A \& B} + \item $A \land (A \land B)$: \texttt{A \& (A \& B)} +\end{itemize} - For the conjunction of two variables or statements the and symbol \texttt{\&} is used. \textbf{The \& must not be escaped for the comma separated statements!} - \begin{itemize} - \item $A \land B$: \texttt{A \& B} - \item $A \land (A \land B)$: \texttt{A \& (A \& B)} - \end{itemize} +\subsubsection{\texttt{OR} / Disjunction} - \subsubsection{\texttt{OR} / Disjunction} +For the Disjunction of two variables or statements the vertical line character \texttt{|} is used. - For the Disjunction of two variables or statements the vertical line character \texttt{|} is used. +\begin{itemize} + \item $A \lor B$: \texttt{A | B} + \item $A \lor (A \lor B)$: \texttt{A | (A | B)} +\end{itemize} - \begin{itemize} - \item $A \lor B$: \texttt{A | B} - \item $A \lor (A \lor B)$: \texttt{A | (A | B)} - \end{itemize} - - \subsubsection{$\rightarrow$ / Implication} +\subsubsection{\texttt{XOR} / Exclusive disjunction} - The implication can also be expressed. \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{;} ! This is because the statements are separated using the comma.} +The exclusive disjunction (\texttt{XOR}) is written in parentheses preceded by the hat operator. \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{,} ! This is because the statements are separated using the comma.} - \begin{itemize} - \item $A \rightarrow B$: \texttt{>>(A; B)} - \item $A \rightarrow (A \lor B)$: \texttt{>>(A; (A | B))} - \item $A \land (A \rightarrow B)$: \texttt{A \& >>(A; B)} - \end{itemize} +\begin{itemize} + \item $A \veebar B$: \texttt{\^\ (A; B)} + \item $A \veebar (A \lor B)$: \texttt{\^\ (A; (A | B))} +\end{itemize} - \subsubsection{$\leftrightarrow$ / Equality} +\subsubsection{\texttt{NAND} / Negated conjunction} - The equality can also be expressed. \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{;} ! This is because the statements are separated using the comma.} \textbf{The \texttt{\_\_} must not be escaped for the comma separated statements!} +The \texttt{NAND} operation is written in parentheses preceded by the the \texttt{NOT} and the \texttt{AND} operator (\texttt{!\&}). \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{,} ! This is because the statements are separated using the comma.} - \begin{itemize} - \item $A \leftrightarrow B$: \texttt{\_\_(A; B)} - \item $A \leftrightarrow (A \lor B)$: \texttt{\_\_(A; (A | B))} - \item $A \land (A \leftrightarrow B)$: \texttt{A \& \_\_(A; B)} - \end{itemize} +\begin{itemize} + \item $A | B$: \texttt{!\&(A; B)} + \item $A | (A \lor B)$: \texttt{!\&(A; (A | B))} +\end{itemize} - \subsection{Comma separated display statements} +\subsubsection{$\rightarrow$ / Implication} - Display statements are defined the same way as the \emph{comma separated display variables}. The comma cannot be used as a display character, as it is used as delimiter. +The implication can also be expressed. \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{,} ! This is because the statements are separated using the comma.} - \subsection{Display true value} +\begin{itemize} + \item $A \rightarrow B$: \texttt{>>(A; B)} + \item $A \rightarrow (A \lor B)$: \texttt{>>(A; (A | B))} + \item $A \land (A \rightarrow B)$: \texttt{A \& >>(A; B)} +\end{itemize} - The displaying string which will be used in the table body for \emph{true}.Normal text and math mode can be used. +\subsubsection{$\leftrightarrow$ / Equality} - \subsection{Display false value} +The equality can also be expressed. Since version 0.0.2 this command can also be expressed as \texttt{<>(A;~B)}. The previous definition\footnote{The equality operation was defined this way in v0.0.1} of \texttt{\_\_(A;~B)} also works. \textbf{Note that the delimiter used is the semicolon \texttt{;} and not the comma \texttt{,} ! This is because the statements are separated using the comma.} \textbf{The \texttt{\_\_} must not be escaped for the comma separated statements!} - The displaying string which will be used in the table body for \emph{false}.Normal text and math mode can be used. +\begin{itemize} + \item $A \leftrightarrow B$: \texttt{\_\_(A; B)} = \texttt{<>(A; B)} + \item $A \leftrightarrow (A \lor B)$: \texttt{\_\_(A; (A | B))} = \texttt{<>(A; (A | B))} + \item $A \land (A \leftrightarrow B)$: \texttt{A \& \_\_(A; B)} = \texttt{A \& <>(A; B)} +\end{itemize} - \newpage +\subsection{Comma separated display statements} - \section{Example of use} +Display statements are defined the same way as the \emph{comma separated display variables}. The comma cannot be used as a display character, as it is used as delimiter. - The code snippet seen in \autoref{lst:exampletable} is the entirety of code required to produce the truth table seen in \autoref{tab:sampletable}.\footnote{The captioning setup was omitted in the listing.} +\subsection{Display true value} - The command generates the code seen in \autoref{lst:exampletableoutput}. +The displaying string which will be used in the table body for \emph{true}. Normal text and ``math'' mode can be used. - \lstinputlisting[language={[LaTeX]TeX}, label=lst:exampletable, caption=Code for an sample truth table]{res/exampletable.tex} +\subsection{Display false value} - \lstinputlisting[language={[LaTeX]TeX}, label=lst:exampletableoutput, caption=Code generated by \textbackslash truthtable]{res/exampletableoutput.tex} - - \begin{table}[h] - \centering - \begin{tabular}{c|c||c|c|c|c|c} - \truthtable{A,B}{$A$,$B$}{!A, A & B, A | B, >>(A; B), __(A; B)}{$\lnot A$, $A \land B$, $A \lor B$, $A \rightarrow B$, $A \leftrightarrow B$}{$T$}{$F$} - \end{tabular} - \caption{Sample truth table} - \label{tab:sampletable} - \end{table} +The displaying string which will be used in the table body for \emph{false}. Normal text and ``math'' mode can be used. - \section{Known issues and bugs} +\section{Example of use} - \begin{description} - \item[Stability] The Lua code of the macro is not yet error resistant. Either a table is produced or not, warnings and errors are not yet implemented. Future versions of the package will probably address this. - \item[Display formatting] Whilst normal text and math mode work for both headers and truth values, other text formatting such as \texttt{\textbackslash textbf} does not. It is not yet clear if this will be addressed in future versions. - \item[Operations] For the moment only four operations are defined. Further operations\footnote{\emph{NAND}, \emph{XOR}, \emph{etc.}} may be added in future versions. - \end{description} +The code snippet seen in \autoref{lst:exampletable} is the entirety of code required to produce the truth table seen in \autoref{tab:sampletable}.\footnote{The captioning setup was omitted in the listing.} + +The command generates the code seen in \autoref{lst:exampletableoutput}. + +\lstinputlisting[language={[LaTeX]TeX}, label=lst:exampletable, caption=Code for an sample truth table]{res/exampletable.tex} + +\lstinputlisting[language={[LaTeX]TeX}, label=lst:exampletableoutput, caption=Code generated by \textbackslash truthtable]{res/exampletableoutput.tex} + +\begin{table}[h] + \centering + \begin{tabular}{c|c||c|c|c|c|c|c|c} + \truthtable{A,B}{$A$,$B$} + {!A, A & B, A | B, ^(A; B), !&(A; B), >>(A; B), <>(A; B)}{$\lnot A$, $A \land B$, $A \lor B$,$A \veebar B$,$A | B$, $A \rightarrow B$, $A \leftrightarrow B$} + {$T$}{$F$} + \end{tabular} + \caption{Sample truth table} + \label{tab:sampletable} +\end{table} + +\newpage + +\section{Development} + +\subsection{Repository} + +This package is on \emph{CTAN} (\href{https://ctan.org/pkg/truthtable}{ctan.org/pkg/truthtable}). The repository of the package is \href{https://github.com/K-Trout/truthtable}{github.com/K-Trout/truthtable}. For bug reports and feature requests create an issue on github: \href{https://github.com/K-Trout/truthtable/issues}{github.com/K-Trout/truthtable/issues}. + +\subsection{Changes} + +\textbf{v0.0.2 (2021/10/08)} + +\begin{itemize} + \item Added support for \emph{XOR} and \emph{NAND}. + \item Added definition for equivalence operation to be written as \texttt{<>(A; B)}. \texttt{\_\_(A; B)} is still supported + \item Added some error messages when the number of arguments and display arguments don't correspond. +\end{itemize} +\textbf{v0.0.1 (2021/10/01)} + +\begin{itemize} + \item Initial release +\end{itemize} + +\subsection{Known issues and bugs} + +\begin{description} + \item[Stability] The Lua code of the macro is not very error resistant. The package only checks if the same amount of working and display variables, as well as working and display statements are provided. If a mismatch is detected, an error message is output and the package code halts. Further improvements may be undertaken in the future. + \item[Display formatting] Whilst normal text and ``math'' mode work for both headers and truth values, other text formatting such as \texttt{\textbackslash textbf} does not. It is not yet clear if this will be addressed in future versions. + \item[Operations] For the moment seven operations are defined. Further operations may be added in future versions. +\end{description} + +\newpage + +\section{Implementation} + +\lstinputlisting[language={[LaTeX]TeX}, label=lst:packagecode, caption=Source code of the truthtable package, numbers=left,xleftmargin=17pt,xrightmargin=-3.4pt,framexleftmargin=17pt, numbersep=5pt,frame=bt]{truthtable.sty} \end{document}
\ No newline at end of file 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 |