#Resolve cyclic import

5 messages · Page 1 of 1 (latest)

fleet cypress
#

I have a main file which has a variable x and includes a file child.typ. I need access to that variable in both main.typ and child.typ. Additionally both files should be able to compile standalone.
Is there a trick to make this work, except creating a third file with the variable x?

visual bear
#

I have made this work with.

main.typ

#import "template.typ": *
#let variable = (
...
)

#show: settings.with(
variable: variable
...
)

template.typ:

#let settings(
...
  variable: none,
  body,
) = {
...
}
fleet cypress
#

This doesn't solve my use case, but thanks for answering anyway. I played around a bit more with import/include and it seems like having a third file is the only option.

visual bear
#

Can you paste some MWE of yours?

fleet cypress
#

Sorry, that I didn't get back to you. I managed to resolve my issue by using a state variable. With it I'm able to include the child.typ only if I compile the main.typ. This allows me to import main.typ into child.typ and use variables from main.
It is probably a bit cursed and I have to check if there are any issues with it once I use it in a real document.