0

I heard that TeX is a Turing complete language. Does it mean that one can use TeX for example to write operating systems or games like Tetris or Hangman? I don't mean that one writes a source code of Tetris but I mean, can one play Tetris somehow by writing a document and compiling it?

5
  • 1
    i don't see how one can play tetris without writing a program. From my understanding, latex is a set of macros and not a programming language per se. However, there are packages (pytex, pertex) that can call external programs written in e.g. python. Also, lualatex embeds lua code into a document. Thus, it might be possible by writting tetris in lua
    – Yorgos
    Jul 3 '20 at 9:39
  • 3
    Like reversi, for example? Jul 3 '20 at 10:02
  • 1
    See some of the answers here: What is the most bizarre thing you have seen done with TeX
    – Alan Munn
    Jul 3 '20 at 11:24
  • While theoretically possible, the programs would be incredibly slow, unless all they did was put boxes inside other boxes. Jul 3 '20 at 14:29
  • 2
    Could you implement on a traditional 8-bit TeX-engine a unicode-TeX-engine like LuaTeX or XeTeX? ;-) - This might be an interesting way of updating things on old platforms. ;-) Jul 3 '20 at 19:01
5

“Turing-complete” means that, in theory, a TeX engine with enough memory could run a simulation of any of those things. It wouldn’t be practical.

The game of Tetris would not actually be playable, because TeX is not designed to read a controller and update pictures in real time, but it might come closest. However, you might write code (let’s say, in TikZ) that produce an animation of a Tetris game based on a given input file. It’s also possible to imagine making a simulation of the memory of some 8-bit computer, like an Apple II, including the CPU and the memory, as a state machine. You could then run a simulated operating system in the document and draw what would appear on the screen when the simulated program finished.

LuaTeX provides hooks to insert arbitrary Lua modules, but that’s somewhat different from doing it in TeX.

2
  • 2
    Another way to handle “input”/“output” is to use the error message/response loop that occurs during a TeX run. I.e. you run pdflatex on the input file from the command line; pdflatex issues an “error message” describing the game state; your response describes the next move. Something like tic-tac-toe should be feasible this way in practice. Jul 3 '20 at 10:08
  • 1
    @PeterLeFanuLumsdaine Some of the early proofs-of-concept of C++ template metaprogramming printed the results of the program in an error message!
    – Davislor
    Jul 3 '20 at 10:10
4

I used LaTeX to create and solve sudoku puzzles (> texdoc sudokubundle) although I don't recommend using (La)TeX for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.