Can somone point a mistake in my reasoning?

  1. It is possible to build an operating system.

  2. A Turing complete programming language can by used to program an operating system.

  3. LaTeX is a Turing complete, so you can build an operating system with LaTeX.

  4. You need a LaTeX to compile a tex-document, and that runs in some operating system.

  5. Therefore, by 1, 2 and 3 you can build an operating system with LaTeX but by 4., you can't install it to any machine.

Is there a contradiction or has my reasoning an error?

  • $\begingroup$ The mistake is in premise 2. A language being Turing-complete has nothing to do with its capacity to program an operating system. In fact, C, used to program most operating systems, is not even technically Turing-complete. $\endgroup$ Jan 4, 2022 at 21:08

2 Answers 2


Somewhere between step 3 and 4 you make an unwarranted leap. TeX is Turing-complete, so you can write a computer in TeX that does anything. However, that computer is not the one you're compiling your LaTeX document on. So you can not write an operating system for your PC in TeX/LaTeX.

That said, most modern LaTeX versions have an OS escape: if you \write18{command}, that command gets executed. That way you can still do file and whatever operations on your machine from LaTeX.

  • $\begingroup$ A way to improve your answer would be to note that LaTeX will generate a TeX document but also one could use plugins and have LaTeX have a side effect of generating assembly or something. In other words if a plugin can have a side effect of creating an error message or log apart from the TeX document then leverage that into outputting the operating system as a side effect. $\endgroup$
    – Guy Coder
    Jan 6, 2022 at 8:21

Actually you can do it and this sort of thing is often done. In particular, C compilers are often written in C itself. Even weirder, the first compiler for C on a new architecture might be written in C through an iterative process called bootstrapping. So, since LaTex is actually a compiler, you can do the same thing.

You work on such things in a series of stages, with only the very first stage needing to be done in another language (or no language other than absolute machine language).

First write a simple thing that will only compile somewhat more complex things, not the full language. Write a somewhat more complex thing that only uses features supported by the simple thing. Then, compile the new thing with the simple thing. Replace the simple thing with the new thing as your basic compiler. Then repeat. Write the V2 new thing using only features of the V1 simple thing and compile it with V1. Replace V1 with V2 and repeat as necessary until Vn is what you want.

In practice two or three iterations might be needed, but usually not more.

In fact, the latest versions of most languages are written this way by writing a compiler for them in the language of the previous version of the language.

There is usually a final stage in such bootstrapping in which a compiler for level n is written in the level n language itself, which only previously had a compiler written in level n-1 language. The compiler then compiles itself, and replaces the earlier version. Once this newest thing is compiled the result replaces the version that compiled it.

I don't know when this was first used, but I'll guess it was during the development of C.

For your application it is much simpler if you already have a LaTex system, write your OS to be compatible with that. Then compile it. Then replace your original OS with this new version. Presumably this new version has its own LaTex compiler.

Alternatively, if you have a Turing Complete language (maybe C) on the new machine that doesn't have a LaTex system, write a compiler for LaTex in C on that new machine and compile it there. You now have a running LaTex compiler on that machine. So, write your LaTex compiler in LaTex and compile it with that first (C) version and then replace the first version with the new one. Now you have a Turning Complete language that you can use to write other programs.

You can perform any computational process on any Turing Machine, but it doesn't need to be easy.

And, you should probably read the following pdf if you have any interest in compilers: https://cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf


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