Weave how to print markdown in for loop?

I currently trying to use GitHub - JunoLab/Weave.jl: Scientific reports/literate programming for Julia but not really getting my head around its usage.
In general I need more examples of the usage of julia markdown.
My current problem: I want to do the same plot for x folders and it should have a header (outside of the plots environment)
How do I achieve outputting markdown down in my julia code chunk? I assumed it works like this:

for dir_name in dirs
    println("## "*dir_name)
    display(plot_all(dir_name))
end

But results="markup" doesn’t seem to have an effect.

# Markdown test
```julia; results="raw"
using Plots, Markdown
dirs = ["a", "b"]
for dir_name in dirs
    show(stdout, "text/html", Markdown.parse("## $dir_name title"))
    show(stdout, "text/html", plot(rand(30), title=dir_name))
end
```

works fine if you’re weaving to HTML. show(..., "text/latex", ...) should work for pdf output, but I didn’t actually try that.

2 Likes

Thanks. Additionally is there a way to use get the doctype from weave and use it in the the jmd file? So that it can automatically use text/html or test/latext ?

# Markdown test
```julia; results="raw"
using Plots, Markdown
dirs = ["a", "b"]

mimes = Dict(
    "tex" => "text/latex",
    "html" => "text/html"
)
mime = mimes[Base.Multimedia.displays[end].formatdict[:extension]]
for dir_name in dirs
    show(stdout, mime, Markdown.parse("## $dir_name title"))
    show(stdout, mime, plot(rand(30), title=dir_name))
end
```

Unfortunately show(stdout, "text/latex", ...) usually doesn’t work. Not sure how to do this properly.

1 Like

Nice. Works for me but I don’t know how to have a reasonable size of the plots.
I’m saving them to a png file now as plotting takes quite a bit time (~500,000 dots in a scatter) and include them with ![](foobar.png) which looks nice in html and only a fraction is shown in the pdf. The size of the plots is 1920x1080. No idea where I can uses the options mentioned here:
http://weavejl.mpastell.com/stable/chunk_options/#Options-for-figures-1

Should be able to just append them after a ;, so e.g.

```julia; results="raw"; out_width="12cm"

or whatever.

So what I tried:

```julia; echo=false
mimes = Dict(
    "tex" => "text/latex",
    "html" => "text/html"
);
mime = mimes[Base.Multimedia.displays[end].formatdict[:extension]]
function m2o(ex)
    show(stdout, mime, Markdown.parse(ex))
end;

and

```julia; echo=false; results="raw"; out_width="12cm"
for dir_name in dirs
    m2o("## "*dir_name)
    png(plot(rand(30), size=(1920,1080)), "visuals/"*dir_name*"_combined_dgs")
    m2o("![$dir_name](visuals/"*dir_name*"_combined_dgs.png)")
end

Don’t know how to have code chunks in code :smiley: on this website