This repository contains Python scripts designed to automate the generation and compilation of LaTeX/TikZ source code for visually representing the tape of a Turing machine.
The resulting diagram follows the same style as that in Charles Petzold's book The Annotated Turing. It consists of a grid of squares containing characters from a given input string, with an ultra-thick border around a specified square to indicate the current position of the head, a customizable total number of squares and a few style options.
The program consists of three scripts:
generate_tikz_code.py
– Generates the LaTeX/TikZ source code and saves it to the filetikz_code.tex
.compile_latex.py
– Compiles the generated LaTeX file to a PDF and saves it inside anoutput
folder together with associated.aux
and.log
files.main.py
– Main script; calls the other two scripts to produce the LaTeX source code and PDF files.
- Python 3.x
- A LaTeX distribution with
pdflatex
(e.g., TeX Live, MiKTeX) - The TikZ package for LaTeX
Using any text editor, modify the values of the variables in main.py
to customize the tape's content according to the explanations there. Here's the code used to produce the first example in the preceding figure:
s = "r e c u r s i o n !" # The string to be printed on the tape
head = 15 # The position of the head (0-based)
length = 20 # The total number of squares
style = "c" # Additional style options
Then run the main script through the Python interpreter:
python3 main.py