fredrikekre/Literate.jl

Plots.default propagating between different Literate examples?

JeffFessler opened this issue · 3 comments

I have a collection of Literate examples for a book I am writing here:
https://jefffessler.github.io/book-mmaj-demo/
In one of the examples I use Plots.default to set aspect_ratio=:equal
https://jefffessler.github.io/book-mmaj-demo/generated/demos/04/ls-cost1/
Unexpectedly, that default setting seems to affect every Literate example that follows,
which messes up the plots in the later examples, e.g.,
https://jefffessler.github.io/book-mmaj-demo/generated/demos/06/lr-sure/
This is unexpected (to me) because I thought that each Literate example is run in its own fresh Julia session.
If needed, I could add a call to Plots.default() to reset the defaults at the end of every example, but I really don't understand why the plots "state" is persisting from one Literate example to the next.
Perhaps this is a Documenter question?

I've concluded that my impression that each Literate example is run in its own Julia session must be incorrect, so I've gone ahead and added default() resets to my examples, so the links above will no longer illustrate the issue. Feel free to close the issue unless the question raises a concern that you want to address.

Yea that is correct. It runs in it's own module namespace, but process global settings will be shared. This is the same whether you use Literate or Documenter for the execution. If you use Literate for execution it is probably easier to setup new processes for each new notebook, something like

run(`julia -e 'using Literate; Literate.notebook(...)'`)

isn't so bad. If you have many examples this might also be a nice way to parallelize it.

run(`julia -e 'using Literate; Literate.notebook(...)'`)

To make sure I understand, you mean in docs/make.jl, right?
There I could replace the loop where I call Literate.markdown(...; documenter=execute) with calls to run, probably inside a Threads.foreach to get parallelism. I might try it!