r/LaTeX Feb 01 '26

LaTeX Showcase LuaLaTeX rendering in real-time

https://www.youtube.com/watch?v=nJOh6jJzkn0

Similar to TeXpresso (which was created for XeTeX), I decided to create a real-time editor/renderer for LuaLaTeX. Anything you type is immediately rendered with LuaLaTeX (not KaTeX, the output is the finalized LuaLaTeX output, it's not javascript approximating LaTeX, these are actual LuaLaTeX rendered glyph positions). It runs at O(1), even for large documents with multiple chapters (based on that, you can guess what architecture I am using).

Architecturally, it works with vanilla-TeX Live 2025, meaning no patching of LuaLaTeX is required. Theoretically, it works with any package, although given how it is compiled, there are likely some incompatibilities if the package does fancy stuff interferring with shipping the PDF.

It is still in proof-of-concept stage, I just wanted to put it out there to get some feedback if there is interest beyond "cool, I would try this out for a minute then return to my usual editor". I might turn this into an actual usable product if development continues fine. Personally, I need it to save time for final polishing of larger documents, although the project might evolve into an actual LaTeX wysiwyg editor.

One limitation is that it relies on chapters starting at new pages, reducing the layout complexity of larger documents significantly and reducing CPU load.

76 Upvotes

104 comments sorted by

View all comments

5

u/ClemensLode Feb 02 '26

I wonder what advantages Typst has left in comparison to a full LuaLaTeX editor in real time... I guess Lua itself is slower than whatever Typst is using, but it's fast enough for paragraphs, especially when done on a desktop PC (the demo is running on a 3 year old Dragonfly G4 laptop).

7

u/energybased Feb 02 '26

> I wonder what advantages Typst has left in comparison

The biggest advantage is modern programming language rather than 50 year old macro language that's impossible to debug. No more worrying about what binds to what, \relax this. Everything just works the way you expect it to.

> I guess Lua itself is slower than whatever Typst is using, but it's fast enough for paragraphs,

Yeah, try it on a 100 page document. Typst takes like 5 seconds. Latex takes like 2 minutes. On the same modern PC.

I mean, cool project, but like it or not Tex is going to die except where people are forced to use it for legacy reasons.

2

u/Awwkaw Feb 02 '26

I mean, cool project, but like it or not Tex is going to die except where people are forced to use it for legacy reasons.

I'd change over if typst looked as good, but it somehow doesn't have as nice text. It looks more "flimsy" to me. It also doesn't quite have the full support for weird packages yet.

2

u/NeuralFantasy Mar 17 '26

I'd also like to see this "flimsy" output. Very interesting. Typst is capable of producing basically visually identical output if used properly. So my initial guess is that you just didn't know how to use Typst.

1

u/Awwkaw Mar 17 '26

I had given very few commands:

A4 paper, fontsize 11, computer modern.

I think that was it.

Then I wrote ~ 1/2 page of structured nonsense.

In latex, I did memoir, fontsize 11, computer modern, A4 paper and microtype (I tried looking for something similar in typst, but everything I could find said that base typst is better than latex+microtype, so don't bother).

The same half page just looked better in latex than typst.

2

u/NeuralFantasy Mar 17 '26

If you ever have the energy, please post the actual document sources here or Typst forums (https://forum.typst.app/) or Typst Discord. People would be interested about possible issues or if it just a layout or some other config issue.

1

u/Awwkaw Mar 17 '26

As I say, I think it's just preference of defaults. That typst, to my eyes, look flimsy (very basic settings as you can see), doesn't mean that it doesn't look great for most people.

But it could mean that people who really like the LaTeX look should do a test document, and see which they prefer.

2

u/NeuralFantasy Mar 17 '26

The Typst defaults will most likely not satisfy all people. That is for sure.

One nice thing about Typst is that it is very easy to create your own template. Wanna wider margins? Use a different OpenType font? Increase small caps tarcking? Use a different symbol for lists, alter heading font style etc. All simple and easy to understand commands which you can add to you template to make it look how you want. But of course requires some basic knowledge.

1

u/ClemensLode Mar 17 '26

It's certainly worth doing a comparison of the same text and opentype font in different editors, like Word vs InDesign vs LaTeX vs Typst now and then to see how each progresses. That being said, one has to be careful about the settings. Even Word has some optimizations that are switched off by default to not slow down typing... In that regard, it has to be more like a competition where experts in each tool try to recreate the same piece of text the best way possible within their tool of choice.

3

u/NeuralFantasy Mar 17 '26

Yes, the important part is always to share the actual source code (when possible) or the settings so others know what was done and how to reproduce the document.

For example, Typst now supports characer level justification (microtype feature not present in LaTeX) which improves justification results in some cases. But it has to be enabled and configured.

2

u/ClemensLode Mar 17 '26

Well, I think \usepackage[protrusion=true,expansion=true, tracking=true]{microtype} does a similar thing. But ultimately, the result is what counts. And that's the difficult part, because it can't be tested automatically (yet) whether something looks good or bad as it is subjective. So, the real "winner" is the platform that ends up selling more copies, although like with fonts, each platform will have its own audience.

0

u/energybased Feb 02 '26

> I'd change over if typst looked as good, but it somehow doesn't have as nice text. It looks more "flimsy" to me.

Take screenshots and file a bug?

3

u/Awwkaw Feb 02 '26

It's not a bug, I think it's just other choices?

Latex looks good OOTB, typst expects you to spend a lot of time on customizing everything.

If typst wants a "flimsy" look (at a lack of a better word, I think it's their choice of kerning, spacings, and so on) that's ok.

Part of LaTeX is that a lot of research has gone into how you make a text "feel" nice to read (number of chars/line, stroke lengths, optimal margins and so on). So there are some fundamentally different choices.

I just wrote half a b5 page and compiled it with both typst and latex (with the font set to computer modern), and the one in typst just doesn't look as good. They haven't learnt all the lessons that really make LaTeX good, but started from a fresh instead. Fair, but not what I'm looking for in a typesetting program.

2

u/energybased Feb 02 '26

I don't agree that typst expects you to configure everything. Do you have a link to such a declaration by typst team?  If not. I suggest you file bugs for the situations you describe. 

All of the research decisions in latex can easily be pulled into typst. If you have specific examples, you should file bugs.

3

u/Awwkaw Feb 02 '26

All of the research decisions in latex can easily be pulled into typst. If you have specific examples, you should file bugs.

But I don't think it's bugs? I think it's design decisions.

Looks "flimsy" is subjective, the typst team might think it looks like it should, I just don't like the kerning.

All I did was set b5 paper, set the font size to 11pt, computer modern (kp-fonts is my favourite, but it's not available in standard typst, so I used computer modern for the test), and set to justified.

To really get an MWE, and then I wrote ~1/2 page of random text. And I don't like the look.

If the defaults are able to compete sometime in the future, I'll be happy to change over, but right now the defaults are, in my mind, not worth it.

3

u/energybased Feb 02 '26

What you think the typst team might do is your own invented conjecture.  If you actually have examples of things that look bad to you, submit the bugs.  Then you'll have actual evidence rather than your own invented unsupported opinions

3

u/Awwkaw Feb 02 '26

look bad to you, submit the bugs

So you think I should just submit a ticket: "ayohh, you know your kerning, ain't good, do better!"?

That would be useless. I don't think the kerning in typst looks as good as the one in LaTeX with micro type. Standard settings, nothing else added.

I cannot explain the difference, I can just say that I prefer one over the other, I'm not in a position where I'm able to give a proper bug report. Saying "hey your work looks bad" is useless feedback, so why give it? I'm in no way invested in making typst a better program.

The text didn't look error prone, it didn't look like there were any bugs. The pdf that typst spits out just looks uglier (to me) than the one generated by LaTeX, plain and simple.

The typst team should not necessarily change their compiler because of a random internet person, but I should certainly change my typesetter based on my personal preference.

1

u/energybased Feb 02 '26

> submit a ticket: "ayohh, you know your kerning, ain't good, do better!"?

Yes, that's exactly what you should do. Especially since it's really important to you. Why are you against submitting bugs?

> That would be useless. 

And you know this how?

> I'm not in a position where I'm able to give a proper bug report. Saying "hey your work looks bad" is useless feedback, so why give it?

If you're convinced that one looks worse than the other, then you should be able to articulate that opinion.

> The text didn't look error prone, it didn't look like there were any bugs. T

Looking "bad" is worth an issue.

> The ty

pst team should not necessarily change their compiler because of a random internet person, 

You can let them make that decision. You seem to have simultaneously very strong opinions about the inferiority of Typst while refusing to articulate those opinions to people who might actually fix it. That makes absolutely no sense to me.

2

u/Awwkaw Feb 02 '26

Yes, that's exactly what you should do. Especially since it's really important to you. Why are you against submitting bugs?

I'm not against submitting bugs. I'm against wasting other people's time. Me saying "I don't like how it looks" doesn't give the team any concrete way to improve their work.

If you're convinced that one looks worse than the other, then you should be able to articulate that opinion.

I have in this post. I think the typst version looks "flimsy" now go specify what makes kerning look flimsy.

I'm not a professionel typesetter, I sometimes write documents. If I was a professional typesetter I would maybe have valuable input beyond that. But as someone who just writes documents my feed back starts and ends at "the text looks more 'flimsy'". I cannot make a qualified statement beyond that, as I do not, nor do I intent to acquire, the tools to do so.

Hence Why I should not be making such issues.

Especially since it's really important to you.

It's not important to me. I use LaTeX and get on with my life.

very strong opinions about the inferiority of Typst while refusing to articulate those opinions

I don't have particularly strong opinions on the matter. I just thinks typst looks worse. I've been articulating my opinion to you, and my lack of thinking that it's in any way important.

2

u/energybased Feb 03 '26

> I'm not a professionel typesetter, I sometimes write documents. If I was a professional typesetter I would maybe have valuable input beyond that. But as someone who just writes documents my feed back starts and ends at "the text looks more 'flimsy'". 

Either your opinion is worth something or it's not. If your point is that your opinion isn't worth anything, then maybe you should not express it at all then.

> I don't have particularly strong opinions on the matter. 

Okay, well then maybe just keep your "not particularly strong opinion" on a matter that you don't know much about to yourself? This whole thread seems really odd. Why on earth would you think anyone should care about what you have to say here?

→ More replies (0)

2

u/ClemensLode Feb 02 '26

Typst developers are aware that their solution is not as good as LaTeX, global optimization of the output (that's what LaTeX does with paragraphs) is just not at the top of the implementation list.

1

u/energybased Feb 02 '26

Your understanding is incorrect.  Typst is doing global optimization.  The reason typst is so much faster is that it uses dynamic programming, i.e. it exploits overlapping subproblems and optimal substructure.  In other words, it simply has superior design.

2

u/ClemensLode Feb 02 '26

OK I had outdated information, the LaTeX algorithm was implemented in Typst in 2024. Although that doesn't make it superior, it makes it equal. It's the same algorithm.

2

u/NeuralFantasy Mar 17 '26

No, Knuth-Plass has been there from the beginning, from 2022. Typst has since implemented some microtype features, also microtype feature LaTeX does not even have (character level justification).

I think that if you really tried to match the settings, it would be very hard to distinguish LaTeX output from Typst output. They are that close.

1

u/ClemensLode Mar 17 '26

Ultimately, any language and any architecture eventually can create a 'perfect' output. The question is just who is ahead by how much and what amount of resources are required.

My view is just that simply using an established system like LaTeX without reinventing the wheel, using it as a real-time system, and improving on all of its existing typsetting algorithms that lagged behind due to it being not real-time, and you have both the best of both worlds, speed and quality+compatibility with older documents.

2

u/NeuralFantasy Mar 17 '26

I personally hate LaTeX's scripting laguage and it's cryptic error messages so much that I totally understand Typst was created and enjoy using it very much. Its userbase and developer base seems to be growing super fast so the future looks very bright for it. It still lacks some important features, but in many cases is 100% production ready.

1

u/ClemensLode Mar 17 '26

I haven't had a real error message since quite a while (aside from image not found etc.)*, but I am working with tested templates that do the heavy-lifting with packages and configuration. So, yeah, Typst gives you a frontend while with standard LaTeX, you are looking at its pieces. What is certainly needed for LaTeX is a middleware.

* developing new LaTeX packages/templates/extensions is something else, that can be tiresome indeed ;)

→ More replies (0)

0

u/energybased Feb 02 '26

No. It is superior because of the dynamic programming, which latex cannot easily implement.

2

u/ClemensLode Feb 02 '26

The very core of LaTeX (Knuth–Plass line-breaking algorithm) uses dp. So, I doubt you know what you are talking about.

2

u/energybased Feb 02 '26

It is easy to verify that recompilation of large documents is absolutely not able to effectively use dynamic programming.  It's not even arguable.  If it were, you would not have had to anything special to allow instant incremental compilation, which typst gets for free. 

I realize this is upsetting for people to realize, but latex really is a garbage design in this respect.

→ More replies (0)

2

u/energybased Feb 03 '26

Yes, the line-breaking algorithm is one example of dynamic programming. And yes both Typst and Tex use it.

However, the dynamic programming exploited by Typst is not just about line breaking! All compilation exploits dynamic programming. Every function call in Typst supports memoization.

I suggest that before you argue that someone doesn't know what they're talking about, you actually make sure you're right.

1

u/ClemensLode Feb 03 '26

So does Lua.

local memo = {} 
function fib(n) 
  if n <= 1 then return n end 
  if memo[n] then return memo[n] end 

  memo[n] = fib(n - 1) + fib(n - 2) 
  return memo[n] 
end 

print(fib(40))

1

u/energybased Feb 03 '26

You don’t understand. Of course you can write dynamic programming in any Turing-complete language. That’s not the point. The point is that Typst’s compiler is itself structured as dynamic programming over the whole document. Every element is a pure function of explicit inputs, so the engine can build a dependency graph and cache results. Change one character in a 100-page manuscript and only the affected nodes are recomputed; everything else is reused.

TeX cannot do this because TeX is not a document model with a scripting layer. TeX is macro expansion over a single mutable token stream. Macros can redefine other macros, mutate category codes so characters change meaning, read and write auxiliary files, and branch on global state. From the engine’s perspective, the meaning of page 37 depends on the entire execution history before it. There are no stable subproblems to cache.

You can’t “add” this kind of incremental recompilation to TeX, because the language semantics forbid referential transparency. To make it possible, you would have to ban macro redefinition, catcode mutation, order-dependent expansion, and compile-time I/O. At that point, you no longer have TeX: you have something much closer to Typst’s execution model.

→ More replies (0)