Is Troff Turing complete?

Yes, troff is Turing-complete. It supports arbitrary recursion and conditional branching, which is sufficient. It also has registers and various other ways to store data, which gives you another path in again.

Turing completeness doesn't imply that highly complex programs are practical - just that they're theoretically possible, somehow, at some level of remove - and nor does its absence imply that they aren't, so neither troff's being Turing-complete nor the absence of complex programs don't suggest anything much one way or the other about that.


Turing completeness is not, generally, a property that means anything useful for you the user. All it means is that you can simulate a Turing machine with it, not that you'd want to, and not that the output that you'd get from it is anything like what you'd expect to read. The input or output might just be a number, or even the number of times something appears, rather than something useful, and the sorts of machine you end up simulating and their programs are often barely comprehensible to start with.

Many languages and systems are incidentally Turing-complete but not reasonably applicable for any actual programming in that subset (for example, Conway's Game of Life or CSS), and some languages that are useful for real programming are not Turing-complete (for example, Agda). The defining characteristics really are that you can

  • keep going forever
  • remember as much data as you want
  • choose what, if anything, to do next

Often those properties - particularly non-termination - are actually undesirable, possibly including for troff. Outside of theoretical computer science and language design, Turing completeness is not a terribly interesting property virtually of the time, despite being catchy.


ESR's The Art of Unix Programming claims it is:

We'll examine troff in more detail in Chapter 18; for now, it's sufficient to note that it is a good example of an imperative minilanguage that borders on being a full-fledged interpreter (it has conditionals and recursion but not loops; it is accidentally Turing-complete).

("Accidentally" as opposed to m4, which is said to be "deliberately Turing-complete".)

Tags:

Roff