`using SomePackage` in block

The problem is that in a regular block, julia is macroexpanding the whole thing at once, so it tries to expand the macro before it gets loaded.

One way around this would be to use this:

macro toplevel(ex::Expr)
    if ex.head == :block
        ex.head = :toplevel
        return esc(ex)
    else
        throw(ArgumentError("@toplevel must be used on `begin ... end` blocks"))
    end
end

Now, writing

@toplevel begin
    using GLMakie
    L"f(x)"
end

should work.

1 Like