I have a bazillion of legacy TikZ, pictures converting them to cetz is not an option. They are also smart, since they can adopt their with to the context where they are used. Is there a way to include TikZ into typst? If not I was thinking of writing a function that measures the width of the context, starts a latex rendering and includes the graphic as SVG. Also it must be somehow cached since I don’t want to loose performance in compiling. Any thoughts?
Depending on your requirements, this may or may not be an option, but when I have to deal with stuff like this, I take the Tikz graphics, render them in a standalone document, minimize margins, and then compile the document to PDF.
Now, for Typst, I need one more step of converting ot SVG or PNG, at which point I can insert the graphic as a figure, but once inserting PDF content becomes a feature for Typst, you can skip this step.
You can’t directly include arbitrary LaTeX in Typst. There is mitex – Typst Universe, which bridges some gaps.
Function that is written in what language and used how?
Typst function results are cached automatically, though it only matters for the document writing stage, not for a standalone compilation.
I assume you can only output the figures in PDF? Regardless, if you can just get the figures in PNG, SVG, JPEG, or PDF, you can insert them with image
. The PDF one only available in the latest Git version or in dev version on the web app.
Not sure what else you can do.
Typst as Language would be fine. Is there a function to measure the width of the context? And a function for a command line call?
You can measure with measure. But since Typst is a sandboxed environment, you can’t access arbitrary I/O or network, or external execution during compilation. Only files within project root. You can use Wasm plugins, but you have to make it yourself or find one. And they have some limitations as well.
While measure()
tells you the space something takes up, layout()
tells you the available space. I think that’s what you need to fire up your TikZ compilation, right?
Once you know the width in Typst, you can use a command line query to get that value out of Typst and use it in a script. And once you have compiled your diagram, you can in turn include it in your document.
In principle, prequery is meant to help automate such workflows. But I haven’t done the larger part of the work yet: provide a tool that can query documents and dispatch to various applications according to some config. Yet, the package’s manual may give you some insight in how you can structure your workflow – even if the package doesn’t solve the bulk of the problem.