# Multiple environments in Documenter

**URL:** <https://discourse.julialang.org/t/multiple-environments-in-documenter/63436>\
**Category:** General Usage\
**Tags:** documentation, documenter, environment\
**Created:** [June 23, 2021, 11:48am UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436 "2021-06-23T11:48:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [June 23, 2021, 11:48am UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/1 "2021-06-23T11:48:52Z")

</div>

Hi!  
For [KernelFunctions.jl](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl), we are generating examples via [Literate.jl](https://github.com/fredrikekre/Literate.jl), pass them to Documenter.jl and we would like that each example has its own environment/Project.toml.

The problem of course is that when running `makedocs` it is not possible to use different environments. When activating one environment after another, the packages would stay loaded and this would create some clash.  
Has anyone tried to solve this or even succeeded?

Thanks!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 23, 2021, 11:53am UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/2 "2021-06-23T11:53:45Z")

</div>

You can run each example in a separate julia process where you set up the environment you need.

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [June 23, 2021, 12:01pm UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/3 "2021-06-23T12:01:27Z")

</div>

That’s what we had in mind, but it’s quite unclear how one should go about it.  
Each “example” process should call `makedocs` specifically on the `example.md` generated by Literate and then there would be one common `makedocs` call to build the rest of the docs and combine it with the examples which have now been run?  
I could not find anything on how to fine tune Documenter generation in the docs.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 23, 2021, 12:40pm UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/4 "2021-06-23T12:40:28Z")

</div>

Why do you want more than one `makedocs` call? I thought only the calls to `Literate` would have to be in their own environments?

This is what I had in mind:

```bash
$ tree .
.
|-- docs
| |-- make.jl
| |-- Manifest.toml
| |-- Project.toml # Documenter, Literate, ...
| `-- src
| `-- literate-src
| |-- example-1
| | |-- Manifest.toml
| | `-- Project.toml # Example-1 specific deps
| `-- example-2
| |-- Manifest.toml
| `-- Project.toml # Example-2 specific deps
|-- Manifest.toml
|-- Project.toml
`-- src
    `-- KernelFunctions.jl

```

And then in `make.jl` you would use something like

```julia
using Documenter

# Run Literate examples in their own processes
examples = joinpath(@ __DIR__ , "src", "literate-src")
cmd = Base.julia_cmd()
docs_env = @ __DIR__
for example in readdir(examples; join=true)
    load_path = "$(example):$(docs_env)"
    code = """
    using Literate
    Literate.markdown(...)
    """
    run(addenv(`$(cmd) -e $(code)`, Dict("JULIA_LOAD_PATH" => load_path)))
end

makedocs(
    # ...
)

deploydocs(
    # ...
)

```

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [June 23, 2021, 1:45pm UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/5 "2021-06-23T13:45:51Z")

</div>

Thanks! That’s already one important step, but this does not solve the whole problem.  
The output for the code with the `Literate.markdown()` command will be `@example` blocks right?  
And these blocks will be effectively run by Documenter (via `makedocs`), but there will be the same problem of having only one process to run them all.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 23, 2021, 1:48pm UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/6 "2021-06-23T13:48:38Z")

</div>

Ah okay. You can actually execute using Literate though (pass `execute=true`).

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [June 23, 2021, 1:52pm UTC](https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/7 "2021-06-23T13:52:07Z")

</div>

Thanks that’s exactly what I was missing!  
Thanks again for you amazing work on Literate 🙂
