Is there an equivalent `\input{file.tex}` command (from LaTeX) in Typst?

Consider the following two Typst files.

config.typ:

#set page(paper: "a4")
This is the *config.typ* file.

main.typ:

#include "config.typ"
This is the *main.typ* file.

I noticed that when previewing the main.typ file there’s a page break after the contents of the config.typ file. Why? How can this be avoided?

This is likely not the best way to configure the layout of a document in Typst, however I still think an #input(file.typ) function could be helpful in some scenarios as also suggested in this GitHub issue.

My objective with this functionality (if it exists) would be to split a very long main.typ file into several smaller Typst files so that the project could be “organized better”. Is that possible? Any help is appreciated!

The correct function is include, but you are setting the page element.

This behaviour is not very well documented, but you can read at the page setup guide

If you make changes with this set rule, Typst will ensure that there is a new and conforming empty page afterward, so it may insert a page break.

A crucial difference to remember is that include evaluates the file and returns content, whereas import will return a module (from which you can select functions, etc.). See Scripting – Typst Documentation.

1 Like

Thank you for the explanation! Though I still find it a bit “confusing” that a page break is blindly inserted even though the page layout is already conforming.

Are you maybe looking for how to make a template? Page setup could be part of a template, that you define in the template but import and apply in the document.

See Making a Template – Typst Documentation

1 Like

Yes, thank you for the clarification! I’ll look into making a template and how to use the #import function.