While looking for code which can automatically generate truth table in LaTeX I stumbled on this Python generator. It appears that the code can be used from Cheetah's framework. Can anybody point me to a simple example of use. I started reading documentation for Cheetah ? Additionally can people provide me with other examples of using Cheetah (or some other frame work) to automatically generate LaTeX code.

Edit: I am not sure if Sphinx also could be used as a wrapper for above code.

For archiving purposes, for people less familiar with Cheetah framework, the above is just a regular Python script. The output of the script on the standard output (could be of course piped into a file) is the LaTeX code.

What is the advantage of using a template engine rather than writing it straight to a file? I can understand that the template can be useful for web pages, but can't really see the benefit here.
–
Yiannis LazaridesJan 22 '12 at 6:50

2

With this simple example there may not be much difference. But consider a document management system preparing dozens or hundreds of different templates. Using a template engine can help you by separating the template code from the rest.
–
Uwe ZiegenhagenJan 22 '12 at 8:03

@Uwe Ziegenhagen spot on! Great answer. It just hit me how to use Cheetah and that code generator. Thank you so much!
–
Predrag PunosevacJan 22 '12 at 15:50

@Uwe Ziegenhagen Can Sphinx be used as a wrapper to do the same? I have never played with it before but it might be a time.
–
Predrag PunosevacJan 22 '12 at 16:06

1

No idea, until yesterday I even didn't lnow Cheetah.
–
Uwe ZiegenhagenJan 23 '12 at 5:30

Not really an answer to this question as it doesn't involve Cheetah. However if anyone searches for truth table, potentially they would like a truth table macro so I'll post this for that reason. The macro \truthtable{<prims>}{<exprs>} (compile with LuaLaTeX) takes two arguments:

The first argument is a comma separated list of primitives (variables)

The second argument is a semi-colon separated list of logical statements involving the operations of:

Negation, entered as -

Conjunction, entered as *

Disjunction, entered as +

Implication, entered as (stuff)->(stuff)

For example, \truthtable{a,b,c,d}{-a;a*b*d;(a)->(b);a*(b+c);(a*(b+c))->(b)} produces the following:

I was just looking for a truth table so thank you very much for your not really answer ;-)
–
IgnasiFeb 26 '14 at 8:47

This looks awesome. The best I've found in the past was a script I ran outside TeX to generate a truth table which I then adapted for use in TeX. It would be fantastic to see this expanded into a package on CTAN. (Wish list: option to use T/F rather than 1/o; option to toggle first variable fastest, right variable slowest since there are, for some reason, textbooks which insist on doing this.) This is the first compelling reason I've seen to use something other than pdflatex. (For me - I have seen compelling reasons-if-they-applied-which-they-don't.)
–
cfrFeb 26 '14 at 20:22

Making truth tables is especially easy using pythontex. Pythontex integrates with sympy and allows you to insert sympy code into your document. A simple truth table can be created for example like this:

I agree with you %100. However PythonTeX was not available when my student wrote parser for propositional logic which outputs truth table in LaTeX code. Unfortunately I never finished cleaning his files and posting complete solution for my original problem.
–
Predrag PunosevacMay 27 '13 at 5:24

This is the first in series of several Python scripts which I will post over the next couple of days as we add license which completely solves original problem. The code is written by my student Stephen Pardue. The first one is the final wrapper bftruthtable.py (boolean functions truth table). However, I have to post couple objects on which wrapper depends before you can use it.

#!/usr/local/bin/python
# Copyright (c) 2011, Stephen Pardue <spardue@aug.edu>
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all
# copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
import argparse
from asciitruthtable import ascii_tables
from latextruthtable import latex_tables
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="generates truth tables for boolean functions",
epilog="By Stephen Pardue. Fear the pandas")
parser.add_argument(
"function", metavar="fn", type=str, nargs="+",
help="boolean function(s) to generate the table(s) for")
parser.add_argument(
"--ascii", dest="ascii", action="store_const",
const=True,
help="output the table(s) to stdout in ascii format"
)
parser.add_argument(
"--latex", dest="latex", action="store_const",
const=True,
help="output the table(s) to stdout in LaTex format")
args = parser.parse_args()
if args.ascii:
ascii_tables(args.function)
if args.latex:
latex_tables(args)