Programming and typesetting
Peter Cameron's Blog 2023-12-19
Is computer typesetting a kind of programming?
One of the pioneers, Donald Knuth, clearly thought so. In The TeXBook, he gives TeX code for computing and typesetting the first thirty primes; apart from anything else, this demonstrates that TeX has the capacity to act as an all-purpose program.
But there is a rather significant difference.
A programmer requires the program to deliver the right answer: exactly, for a discrete mathematician, and to with a specified approximation, for a continuous mathematician. Computer typesetting doesn’t deliver an answer as such. Knuth realises this when The TeXBook ends with the admonition “GO FORTH and create masterpieces of the publishing art“. Despite Keats, truth and beauty are not quite the same.
It is still true, though, that computer typesetting can pose problems similar to those faced by programmers. This summer, I was editing a book with four substantial chapters written by different teams of authors. When I put the chapters together and compiled the book, I discovered that the diagrams in one chapter were wrong. After a lot of searching, I discovered that this was caused by a conflict between two packages used by different authors. The standard remedy is to load the packages in the other order. But this brought LaTeX to a screaming halt without typesetting anything.
The two conflicting packages were curves and tikz. The authors who had loaded the second of these made extensive use of it, but for the first package only two commands had actually been used. The solution wasn’t going to be to delve inside the packages and make changes, since the LaTeX file had to go off to the publisher.
I used plain TeX for several years before being (more or less forcibly) converted to LaTeX. (If you have looked at my Combinatorics book for CUP, you will have noticed that it doesn’t look like most textbooks produced with LaTeX – that is the reason.) So I delved into my knowledge of TeX. I loaded curves, renamed the two required commands with the TeX \let command, and then loaded tikz, then held my breath and compiled the book: it worked!
So no pretence that this was the “correct” programming to use here, but it happened to work to produce the book: perhaps not a masterpiece of the publishing art, but at least a beautiful book. (It should appear next year.)
I now have to face a somewhat similar problem. A coauthor just sent me a copy of the paper, so that it is now my responsibility to make some edits. I was quite horrified, when I looked through it, to find the string lcmp. (I am showing you just an approximation in HTML.) I checked the input: lcm was correctly defined as a math operator, so the output should have looked something like lcm p. (A math operator is designed to leave a certain amount of space between itself and its operand; this looks better and is easier to read and understand. All this is based on a combination of centuries of typesetters’ experience and research in neuropsychology.)
I now have to track down the problem.
I also noticed that the preamble to the paper loads several dozen packages, many of which I have never heard of. I suspect that one of these is causing the trouble, and my next task will be to find which one. At the same time, I also suspect that most of these packages are not necessary. I know that some authors start with a LaTeX template which loads every package they have ever heard of, just in case it is needed. So I might do some judicious filtering …