October 16, 2021

The sile typesetting system

 

A less known possible replacement for LaTeX is Sile. For a one to one comparison the sourcecode can be fetched and then the lines of code are counted:
git clone --depth 1 https://github.com/sile-typesetter/sile.git
cloc sile
No matter what the original documentation of the project likes to explain the cloc tool is an objective measurement what the project is about. According to the statistics, Sile was programmed was mainly programmed in Lua with some parts in C++. The overall lines of code is 450k. Now we can compare this number with the well known luatex project. CLOC will show for luatex that it contains of 1 million llines of code. So we can say that Silo has the half size of luatex.
Unfurtunately, the amount of 450k lines of code is similar to the original luatex project not a small github code repository but a larger one. Maintaining all the code will need a lot of work. Only to get a better understanding what the size is. One line of code needs around 40 Byte. Suppose the code is converted 1:1 into a binary file than 1 million line of code is equal to 40 MB for the binary file. So we are speaking about a 20 MB executable file for the sile project and about a 40 MB file for the luatex project.
Now it is possible to analyze the reason why these layout engines are so big. What Sile, luatex and possible future latex replacements have in common is that they are implementing commands for typessetting. Even if the vocabulary of all the latex commands was never standardized, there is some sort of list available which latex commands are used frequently. In this list around 250 different commands are available which includes commands for typesetting tables, mathematics and showing images in the document.
An well programmed layout engine has to implement these 250 commands at minimum. In case of sile the syntax is a bit different but this is only a detail problem. The open question is how to program a layout engine which takes the 250 possible commands as input and produdes a pdf file as output?
This is realized with lots of lines of code:
Sile, 450k lines of code 250 latex commands -> 1800 lines of code for a single command
Luatex, 1000k lines of code for 250 latex commands -> 4000 lines of code for a single command
So the only difference is how much LoC are needed for a single command per average. From a technical side it is possible to implement only 10 commands, but such a layout engine is less powerful than the original tex software. That means, even if someone reinvents latex he has to implement all the 250 commands.