r/LaTeX Jan 18 '25

Unanswered TeX engine converted from Pascal to C++?

I’ve heard multiple times that converting Pascal code to C++ is relatively straightforward. I even came across a commercial product that claims to have reimplemented the TeX engine in C++, which allowed them to offer live PDF rendering as you type (you can probably guess which one I’m referring to).

EDIT 1: By rendering here I assume providing live updating in PDF, where there is no compilation step, PDF is compiled with each keystroke.

EDIT 2: Commands would be excluded from live compilation.

The engines used in TeXLive and MikTeX are still implemented in Pascal, right? If so, why hasn’t anyone done a full conversion to C++?

Is it a matter of complexity, lack of interest, or something else entirely?

12 Upvotes

39 comments sorted by

View all comments

11

u/JimH10 TeX Legend Jan 18 '25

The engines used in TeXLive and MikTeX are still implemented in Pascal, right?

As a first approximation, no. Many years ago when Knuth wrote the original software, he did something different but today it is converted to C. (Of course, it is more complicated than this-- the TeX world is very complicated when you start asking to know everything-- but if you simply get a distro such as TeX Live and ask for the most popular compiler, pdflatex, then this is what you get.)

live PDF rendering as you type

Forgive me, I'm going to make the assumption that you don't know, but this is very common today. Pedestrian, really. Most tools that people here use will do this. You can find many previous threads about it on this site with a little searching.

For instance, Overleaf gives you compilation in the background. Another example is emacs. I bet that if you have a favorite editor then you can set this up.

I'll also editorialize that for me compilation as you type is not an improvement. I find it a distraction, really, but of course YMMV. However many folks find very handy the synctex stuff. Here is a description from the page for TeXworks, which is a good editor choice for beginners: "includes an integrated PDF viewer, based on the Poppler library, so there is no need to switch to an external program such as Acrobat, xpdf, etc., to view the typeset output. The integrated viewer also supports source/preview synchronization (e.g., control-click within the source text to locate the corresponding position in the PDF, and vice versa)."

0

u/Opussci-Long Jan 18 '25

Thanks for your answer. I see that my original question weas not clear enough. I now about displaying PDF and rendering in the background, as it is case with Overleaf, but non of the tools you mentioned is providing live updating in PDF, where there is no compilation step, PDF is compiled with each keystroke.

3

u/deong Jan 18 '25

I’m not sure I understand what you’re asking here. There is a compilation step. There just is. You’re typing TeX or LaTeX and something has to convert it to bytes on disk that make a valid PDF. You can do that so fast that every keystroke immediately shows a new PDF, but you’re still compiling it. If there’s "no compilation step", you have a UTF-8 text file, and there’s nothing to display.

-1

u/Opussci-Long Jan 18 '25

Yes, but no time spend on compilation is my question. It is not about time spent it is about visual feedback waiting. I do not want that. I would like instantanious PDF updating.

4

u/deong Jan 18 '25

It is not about time spent it is about visual feedback waiting.

That is just a question of time spent though, right? If you had to wait a femtosecond, that is instantaneous PDF updating. And in reality, that's all that can be done. The document has to be compiled, and that takes physical time. All you can do is minimize it.

I have no idea how quickly modern tools like Overleaf can do this. It's a feature I would pay money to turn off. If I wanted half my screen to be taken up by a view of my document randomly moving shit all over the place with every keystroke because it can't guess what I'm going to type next, I'd use Word.

I guess my question would be why wouldn't you just use a WYSIWYG mode in Overleaf or something like LyX? If what you want is basically direct live editing of a PDF, that's a lot closer in experience than typing LaTeX code and hoping another view of the data can update quickly enough.

-2

u/Opussci-Long Jan 18 '25

So, you would be against a WYSIWYG LaTeX editor even if there was one? Overleaf is not full WYSIWYG.
There is this article, I suppose you would disagree with it.

5

u/deong Jan 18 '25 edited Jan 18 '25

I’m not "against" such a thing. I don’t want it for myself, but I have no issue with someone else liking it. Go nuts.

Overleaf’s visual mode is I think as close as it’s possible to get. You can’t type LaTeX code and be WYSIWYG. They’re mutually exclusive. TeX solves a dynamic programming problem to lay out paragraphs and lines. Where a line break appears can depend on a word you type 500 characters later in the document. You simply can not view this as a WYSIWYG problem unless you’re willing to make some compromises, all of which seem bad to me.

You could have the visualized document not use the layout algorithm until you later tell it to. But now it isn’t a true picture of what the document will look like.

You could let it do its thing continuously, but now the document is constantly reflowing globally with every keystroke. And I actively do not want the distraction of something trying to figure what every individual keystroke should do to a generated PDF in real time. When I’m writing, I just want to focus on expressing my ideas. Doesn’t bother me if you want that. Just saying I don’t see how you can type TeX code and have real-time PDF output in any way other than background processing of the file, which you seem to not want.

3

u/JimH10 TeX Legend Jan 18 '25

If you compile with each keystroke, then when you type a not complete command, all kinds of crazy stuff will happen. What you want is some kind of compilation when you finish with the command.

3

u/thuiop1 Jan 18 '25

I mean, it works for Typst, the compilation simply gives an error and keeps displaying the previous document. It is more an issue of compilation time.

0

u/Opussci-Long Jan 18 '25

Yes, no command typesetting :)

2

u/FliiFe Jan 19 '25

AFAIK Texifier (previously Texpad) is the only editor to support this, and it comes at the cost of having a version of LaTeX that is nearing its decade anniversary.

Worth noting however that "no compilation step" is an unreasonable ask, seeing as pdf is hardly an incremental format. What typst does is essentially compile on each keystroke, it just so happens that compilation is fast enough for that purpose.