What's the essence of typst drawings? Would them be heavy like PNG album or slow like SVG?

I want to add box(symbol) onto pars/pages to make whole book lively and lovely. The number of different symbols is not big but may be used many times throughout a book. SVG is not heavy but take time to parse and view.

Here are some ways I could imagine:

  1. external icon svg files
  2. download icon font
  3. directly draw by raw typst or cetz pkg, e.g.
// rough demo only, may not run
#let x,y,z = (rect() line() curve()).map(box)

"Hello world" #x() #lorem(24)

Real world examples:

  1. O’Reilly book, page 12/291
  2. Web book

Are there any other way? What’s the best way to be lite and fast?

What kind of scale are you thinking of here? A document with 50 pages probably won’t be affected much here, but if you’re writing a 700 page book then it might make sense to find out now what runs fastest.

Regardless of which is fastest, it might make sense to pick one and go with that until you start having problems. Knuth famously said “premature optimization is the root of all evil” which is hyperbole but is memorable. The point is that you may never encounter problems with picking the “wrong” way to draw these elements in which case you can save time by ignoring them. In the case that you do need to optimize, you can spend your time doing it when you already have more information

Also, it’s hard to imagine what you will be doing with these drawn elements. Do you have any examples of existing documents that have a similar visual style to what you are trying to achieve?

Oh, and your example code doesn’t compile. I think does what you were intending:

#let (x,y,z) = (rect, line, curve).map(f => () => box(f()))

"Hello world" #x() #lorem(24)

But this is doing some syntax tricks and doesn’t affect the performance of drawing.

@gezepi

"I add two real world examples to the questino, please check them out."
/* The code piece is just idea, not real code actually.*/
1 Like

More a hint than a real answer: look at “icon” packages in the Typst Universe (using stuff like e.g. HeroIcons, FontAwesome). There is quite a few, and they solve your problem differently. Some rely on external fonts, some embed the SVGs, and I think there should also be some that embed images. That can also give you an idea of how to expose the icons so that they are easy to use in a document.

Thanks for those examples, it makes your question much clearer.

In short my answer is to use (in order) stock Typst, packages on Typst Universe, then images. If one can’t fulfill your need, use the next. If you have a giant document that takes too long to compile try to find the reason for the slowdown and make improvements then. There are a few posts on the forum about this exact topic.

First Example - PDF book

Quickly looking through it I see these things that “graphics”. For each of them I give a suggestion of how it makes sense to me to include them in your document

  • Tip/Info/Warning boxes which can be provided by a few packages on Typst Universe. I don’t see a good way to use SVG or image files for this. Native Typst seems like the clear choice
  • Diagrams can also be done by Universe packages with diagram source in its own file (or directly in the Typst file). Pre-computed SVG or images could be used here but depending on the type of diagram it would be extremely easy to switch between using a diagram package or a static image
  • Pictures would be image files. If you are include a lot of images, it can be useful to also have an option to compile the document with placeholders - blank rectangles the same size of the image (related question)
  • Software screenshots would also be image files. Though there are a couple packages that simulate the look of chat software - messeji and ourchat
  • Code blocks can easily be done with stock Typst or packages like codly or zebraw
  • Tables of CSV data can easily be displayed with stock Typst

Second Example - Online book

Maybe the printed version has some but I couldn’t find any images in the 10 or so pages I checked. I’m not sure this example relates to your question since the answer would be to simply use Typst for the entire thing.


One aspect that isn’t directly related to including images and graphics in a document but does affect speed is how you structure your chapters, sections, data, images, appendices, bibliographies, etc. In the case that the entire document compiles too slowly to be considered realtime, then you could work only on a file for a single section which will be much faster. Then you would compile everything much less often so the time is less critical.

One example of how to structure your project is here: