# Trouble using the @time module

**URL:** <https://discourse.julialang.org/t/trouble-using-the-time-module/100988>\
**Category:** New to Julia\
**Created:** [June 29, 2023, 4:29pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988 "2023-06-29T16:29:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KZ-Spectra](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@KZ-Spectra](https://discourse.julialang.org/u/KZ-Spectra)\
**Post date:** [June 29, 2023, 4:29pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/1 "2023-06-29T16:29:26Z")

</div>

I want to use the `@time begin ... end` module, but am encountering the following error

> ERROR: LoadError: UndefVarError: `@L_str` not defined

This error occurs only, it seems, when I have defined my code to be within a `module`. Why?

MWE:

```module
@time begin

using GLMakie,LaTeXStrings, MathTeXEngine
GLMakie.activate!()

scatter_data = [1,2,3,4,5,6,7,8]
x=1:8
fig = Figure(backgroundcolor=:snow2)

axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
scatter!(axis, x, scatter_data)

display(fig)
end
end

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [June 29, 2023, 4:38pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/2 "2023-06-29T16:38:22Z")

</div>

I think your issue is with the title value, `title=L"\mathbb{Z}"`. I’m assuming the L string macro comes from LatexStrings. Are you using a version of LatexStrings that defines that macro? Is it exported?

---

<div class="post-metadata">

**Author:** ![KZ-Spectra](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@KZ-Spectra](https://discourse.julialang.org/u/KZ-Spectra)\
**Post date:** [June 29, 2023, 4:50pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/3 "2023-06-29T16:50:31Z")

</div>

All my packages are up to date: [https://i.imgur.com/zjNMGjv.png](https://i.imgur.com/zjNMGjv.png)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [June 29, 2023, 5:01pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/4 "2023-06-29T17:01:57Z")

</div>

`@L_str` is exported from here:

> <https://github.com/JuliaStrings/LaTeXStrings.jl/blob/master/src/LaTeXStrings.jl#L9>

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [June 29, 2023, 5:07pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/5 "2023-06-29T17:07:00Z")

</div>

1. How are your files structured?
2. Can you elaborate how you are using modules?
3. Are you building a package, which may have a distinct Project.toml and Manifest.toml which is being loaded?
4. Can you provide a complete example including the module declaration?
5. Are you explicitly using environments?
6. Is `@time` necessary to create the error? If you remove it dows it work?

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [June 29, 2023, 5:30pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/6 "2023-06-29T17:30:34Z")

</div>

OP is mis-using the term “module”. There are no modules involved. The MWE problem is entirely below.

This works:

```julia
(@v1.9) pkg> activate --temp

(jl_IcBFB8) pkg> add GLMakie, LaTeXStrings, MathTeXEngine

julia> using GLMakie,LaTeXStrings, MathTeXEngine
       GLMakie.activate!()

       scatter_data = [1,2,3,4,5,6,7,8]
       x=1:8
       fig = Figure(backgroundcolor=:snow2)

       axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
       scatter!(axis, x, scatter_data)

       display(fig)
GLMakie.Screen(...)

```

This errors:

```julia
(@v1.9) pkg> activate --temp

(jl_IcBFB8) pkg> add GLMakie, LaTeXStrings, MathTeXEngine

julia> @time begin

       using GLMakie,LaTeXStrings, MathTeXEngine
       GLMakie.activate!()

       scatter_data = [1,2,3,4,5,6,7,8]
       x=1:8
       fig = Figure(backgroundcolor=:snow2)

       axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
       scatter!(axis, x, scatter_data)

       display(fig)
       end
ERROR: LoadError: UndefVarError: `@L_str` not defined
in expression starting at REPL[3]:10

```

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [June 29, 2023, 5:41pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/7 "2023-06-29T17:41:17Z")

</div>

The `@time` is irrelevant. I think `using` statements cannot be inside the same `begin` `end` block where you use ~~them~~ macros (_edited_).

```julia
julia> begin

              using GLMakie,LaTeXStrings, MathTeXEngine
              GLMakie.activate!()

              scatter_data = [1,2,3,4,5,6,7,8]
              x=1:8
              fig = Figure(backgroundcolor=:snow2)

              axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
              scatter!(axis, x, scatter_data)

              display(fig)
           end
ERROR: LoadError: UndefVarError: `@L_str` not defined
in expression starting at REPL[3]:10

julia> begin
              using GLMakie,LaTeXStrings, MathTeXEngine
           end

julia> begin
              GLMakie.activate!()

              scatter_data = [1,2,3,4,5,6,7,8]
              x=1:8
              fig = Figure(backgroundcolor=:snow2)

              axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
              scatter!(axis, x, scatter_data)

              display(fig)
        end
GLMakie.Screen(...)

```

You will have to time them separately and then add the times.

```julia
julia> t1 = @elapsed begin
       using GLMakie, LaTeXStrings, MathTeXEngine
       end
0.0034929

julia> t2 = @elapsed begin
              GLMakie.activate!()

              scatter_data = [1,2,3,4,5,6,7,8]
              x=1:8
              fig = Figure(backgroundcolor=:snow2)

              axis = Axis(fig[1,1], xlabel="Example scatter", title=L"\mathbb{Z}")
              scatter!(axis, x, scatter_data)

              display(fig)
       end
0.0995245

julia> t = t1 + t2 # seconds
0.10301740000000001

```

---

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [June 29, 2023, 6:45pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/8 "2023-06-29T18:45:37Z")

</div>

I think the problem is specifically using macros defined in modules that are _used/imported_ within the same begin/end block. Not generically about the using statements.

I believe this is because Julia first tries to compile all macros in the begin…end before executing it. I had this happen to me some times in Pluto

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 30, 2023, 4:30am UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/9 "2023-06-30T04:30:08Z")

</div>

Aren’t you supposed to `@time @eval begin...` anyway when timing `using` plus first call latency to avoid Julia compiling anything outside the timing operation? The `@eval` might also help with the macro bug here

---

<div class="post-metadata">

**Author:** ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Post date:** [June 30, 2023, 6:41pm UTC](https://discourse.julialang.org/t/trouble-using-the-time-module/100988/10 "2023-06-30T18:41:38Z")

</div>

Thank you for pointing this out! I also ran into this issue (when loading DimensionalData and defining a new `Dimension` using the `@dim` macro within the same `@everywhere begin ... end` block). I eventually figured out I needed two separate `@everywhere` blocks to make it work, but didn’t realize it was a general issue. Is this gotcha documented anywhere?
