How does multi-pass stuff work in Typst and specifically for instant preview?
In particular, things like ToC generation, figure and formula numbering and back- and forward-referencing?
I was always intrigued by creating a TeX-like typesetting language that has similar properties, but I was always put off by having to reimplement the gist of the typesetting engine (entire box model and font support, especially math typesetting).
It'd also be nice to support more advanced data structures other than 255 registers to allow moving away from external file use in all the multi-pass processing features.
While I was heavily involved with typesetting in TeX, I mostly had my own PlainTeX macros for all of the above stuff (including syntax highlighted code listings with cross-page continuation logic), but that was 25 years ago when Unicode support was mostly very rudimentary: I don't have a need for a typesetting engine of the sort today, though I would love to switch my blog into a more semantic language with nice support for maths and programming that would allow instant print previews (and printouts) with TeX like formatting quality.
I would also love it if you open source your stuff, but I understand that you are likely trying to build a business around this too.
These are great points. I'll try to address all of them.
Multi-pass: We also do multiple passes, but thanks to comemo we can reuse most of the stuff from previous passes. The change tracking detects if a dependency on some other part of the document requires updating. This doesn't require file writing and reading; Typst has a built-in user-facing interface for these kinds of tasks.
Data structures: Typst has typical data types you'd expect from a modern programming language and also typical imperative control flow like if, for, and while. What's a bit non-standard is that Typst enforces that all user-defined functions are pure (else we'd break incremental).
Open Source: We do plan to open source the Typst compiler and CLI! Just not the collaborative web app.
1) Store all actions by a user as as an array of add/remove commands (where a change is remove+add).
2) Whenever you need to re-render take the cached version from the last render and perform the new add/remove commands that happened since the last render.
3) Cache the result for the next render and repeat.
If I understand correctly, you mean manually writing code that patches the result of an action to the last output.
That seems like a great approach for a simple transformation pipeline. For a full compiler it seems harder to pull off. That's the great thing about memorization: It more or less let's you write the compiler like you would have done without it.
I honestly do not care about instant preview... On one side I prefer to focus on my writing in text, witch means my LaTeX sources are well formatted for human readability and well spread as needed for the same reason when (rarely for me) I write not so short stuff, I have my collection of templates for almost anything and anything I need something different I collect the LaTeX structure a bit, even if trivial, in an org-mode note, to have ready made stuff as needed.
On the "final" step looking for produced pdf issues I have to recompile sometimes, mostly on tables/TiKz stuff, but the little build time does not disturb me... The only a bit annoying part is the "like-a-lisp" default interaction mode in case of error finding it essentially useless since I have to correct the sources anyway.
yes I agree, however as a student working with LaTeX for the first time, instant preview is awesome, it allows me to instantly see what my changes do to the preview, and greatly increases productivity when I'm not sure what I am doing and constantly checking the output for what it did.
For writing, it's great not to have the distraction.
But for publishing (especially book/e-book publishing, which always requires a lot of fiddling to get perfect!), it's really, really useful. My current workflow is TeXStudio with a lot of F5ing, which works pretty well...but that final run-through would be so much faster if I could see changes as they're made.
I'm a bit confused by this and the posts above. In vscode it is possible to configure it such that on every save a new pdf is generated. You can open the PDF to the right and it's essentially instant preview.
I've used this config when writing papers, etc, and it works flawlessly.
As for diffs (what has changed), it is also possible to color code the changes too.
I can't recall how I configured viscose, but it was a fairly standard approach.
LyX is great – it's what I used in college for physics papers. It's been a while but I think it was just LaTeX, so I'm not sure what your second point means.
Sadly it never took off. These days I would choose Jypter notebooks or markdown files with embedded LaTeX math, which also gives you instant previews.
> I always thought it was just LaTeX, so I'm not sure what your second point means.
LyX uses .lyx files but is able to import and output .tex files - and the fact that you remember it as "just LaTeX" means the integration is good enough.
From their Features Poll[0] page:
"By a general consensus of the developers, using LaTeX as a native format of LyX is no option. Query the lyx-devel archieves for details."
LyX has the best system for entering maths into a computer that I've ever used. The combination of (a) understanding standard LaTeX (and amsmath etc) commands, (b) keeping track of grouping for me (no need to manually deal with curly braces) and (c) seeing everything appearing immediately means that I often use this over pen+paper for moderately complex derivations. Even if though I've never really used it for full LaTeX documents, for me it's worth having around just for this.
I used to lecture with lyx. Think about trying to express how you’re solving an algebra problem. Set up a keyboard shortcut for “duplicate previous line” and you’re off to the races.
Instant typesetting would be very welcome – I have often wished for exactly this. But I do not think that it is a technical problem. TeX is very fast, after all. (As you would expect with software that age.) Rather, people do complicated things and those become slow at some point. If you cannot do complicated things, the system will likely not be popular, and the popularity of LaTeX is its main appeal, I think. Everything is just a package away. Perhaps it is possible to aim at another point on the pareto frontier and have something fast with fewer features, similar to the relationship between C and C++. Anyway, I hope I am wrong and wish you the best of luck!
This is great! I made LatexResume[1] very recently to solve a problem I'd been having as a first time LaTeX user and wrote about it as well. [2]
The app allows you to see what you're writing as soon as you click preview (no auto-reloads because I probably won't be able to handle the traffic) and the API lets me generate a PDF as soon as I push my resume to GitHub:
For my discertation I used TexPad (now called Texifier) which has live preview and it worked fine. I'm probably not the right person to ask though, because I only used Latex because it was clear that my Supervisor liked to sniff his own farts and would've given me a lower mark for the same work in Word.
23 comments
[ 2.1 ms ] story [ 70.4 ms ] threadIn particular, things like ToC generation, figure and formula numbering and back- and forward-referencing?
I was always intrigued by creating a TeX-like typesetting language that has similar properties, but I was always put off by having to reimplement the gist of the typesetting engine (entire box model and font support, especially math typesetting).
It'd also be nice to support more advanced data structures other than 255 registers to allow moving away from external file use in all the multi-pass processing features.
While I was heavily involved with typesetting in TeX, I mostly had my own PlainTeX macros for all of the above stuff (including syntax highlighted code listings with cross-page continuation logic), but that was 25 years ago when Unicode support was mostly very rudimentary: I don't have a need for a typesetting engine of the sort today, though I would love to switch my blog into a more semantic language with nice support for maths and programming that would allow instant print previews (and printouts) with TeX like formatting quality.
I would also love it if you open source your stuff, but I understand that you are likely trying to build a business around this too.
Multi-pass: We also do multiple passes, but thanks to comemo we can reuse most of the stuff from previous passes. The change tracking detects if a dependency on some other part of the document requires updating. This doesn't require file writing and reading; Typst has a built-in user-facing interface for these kinds of tasks.
Data structures: Typst has typical data types you'd expect from a modern programming language and also typical imperative control flow like if, for, and while. What's a bit non-standard is that Typst enforces that all user-defined functions are pure (else we'd break incremental).
Open Source: We do plan to open source the Typst compiler and CLI! Just not the collaborative web app.
1) Store all actions by a user as as an array of add/remove commands (where a change is remove+add).
2) Whenever you need to re-render take the cached version from the last render and perform the new add/remove commands that happened since the last render.
3) Cache the result for the next render and repeat.
That seems like a great approach for a simple transformation pipeline. For a full compiler it seems harder to pull off. That's the great thing about memorization: It more or less let's you write the compiler like you would have done without it.
On the "final" step looking for produced pdf issues I have to recompile sometimes, mostly on tables/TiKz stuff, but the little build time does not disturb me... The only a bit annoying part is the "like-a-lisp" default interaction mode in case of error finding it essentially useless since I have to correct the sources anyway.
But for publishing (especially book/e-book publishing, which always requires a lot of fiddling to get perfect!), it's really, really useful. My current workflow is TeXStudio with a lot of F5ing, which works pretty well...but that final run-through would be so much faster if I could see changes as they're made.
I've used this config when writing papers, etc, and it works flawlessly.
As for diffs (what has changed), it is also possible to color code the changes too.
I can't recall how I configured viscose, but it was a fairly standard approach.
Are you using LaTeX-Workshop?
https://www.lyx.org/
LaTeX code is not edited directly by LyX, though: you need to import and export it.
Sadly it never took off. These days I would choose Jypter notebooks or markdown files with embedded LaTeX math, which also gives you instant previews.
LyX uses .lyx files but is able to import and output .tex files - and the fact that you remember it as "just LaTeX" means the integration is good enough.
From their Features Poll[0] page:
"By a general consensus of the developers, using LaTeX as a native format of LyX is no option. Query the lyx-devel archieves for details."
[0] https://wiki.lyx.org/LyX/FeaturePoll2#toc8
The app allows you to see what you're writing as soon as you click preview (no auto-reloads because I probably won't be able to handle the traffic) and the API lets me generate a PDF as soon as I push my resume to GitHub:
curl --fail --show-error -X 'POST' 'https://latexresume.com/api/v1/resume' -F 'file=@resume.tex' --output resume.pdf
[1] https://latexresume.com/
[2] https://varunchopra.vc/posts/latex-resume/
TiddlyWiki[1] with KaTeX plugin[2] does that. Or any project that uses KaTeX for that matter.
Next?
[1]https://tiddlywiki.com/
[2]https://katex.org/