I’ve been spinning my wheels on this for a while now. I’m using the command line version of typst and trying to set up a system of imports/includes for writing problem sets.
Each problem set should be its own file (call it pset.typ
), and each problem that appears in the problem set should be its own file (say p1.typ
, p2.typ
, etc). So far no problem, just use #include "p1.typ"
in the main file.
Each problem file p1.typ
should also include a solution that is shown or not depending on a variable (call it show_solns
) set in pset.typ
. Here, #include
breaks down because it is evaluated before returning content to the main file. I’ve gotten around this with something like:
#eval(read("p1.typ"),
mode: "markup",
scope: (show_solns: show_solns)
)
I don’t want to write this out for every problem in the problem set, so I could wrap it in a function. However, I don’t want to define this function in every problem set I write, so it makes sense to define it in a library file that gets #import
ed, but then I run into all sorts of issues with paths being relative to the imported file, not the problem set.
Additionally, I don’t want to have to recreate the show/no show logic in every problem. Potential solutions are defining a solution
function that gets imported to each problem, or perhaps importing something that shows/doesn’t show a section if its heading is == Solution
.
On top of it, I’d like to import the same library for a bunch of different classes that live all over the filesystem.
All of this is super simple in latex, with the use of \input{}
, however that doesn’t exist in typst and the developers have made it clear that they will not support it. Which is frustrating for people like me that aren’t programmers and just want to get stuff done in a markup language.