# Weave.jl: order of text and plots

**URL:** <https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656>\
**Category:** General Usage\
**Tags:** weave\
**Created:** [July 14, 2021, 8:02pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656 "2021-07-14T20:02:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco-Congedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco-congedo/32/7321_2.png) [@Marco-Congedo](https://discourse.julialang.org/u/Marco-Congedo)\
**Post date:** [July 14, 2021, 8:02pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656/1 "2021-07-14T20:02:58Z")

</div>

Weaving a .jmd file like this within a ```julia code block:

```julia
println("line 1")
println("line 2")
display(plot(rand(10)))
println("line 3")
println("line 4")

```

gives this both in html and pdf output:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/0/10c2b82a4832bcbcd98b13fce3c0286c8b0208af.png)

Is there a way to get plots appearing in the right place within a single code block?

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [July 14, 2021, 8:47pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656/2 "2021-07-14T20:47:45Z")

</div>

Most simple solution I can think of:

````julia
```julia
println("line 1")
println("line 2")
```

```julia
display(plot(rand(10))
```

```julia
println("line 3")
println("line 4")
```

````

I believe with how Weave executes code blocks, HTML output is embedded after STDOUT. Not 💯 sure on that one, but hope this helps @Marco-Congedo

---

<div class="post-metadata">

**Author:** ![Marco-Congedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco-congedo/32/7321_2.png) [@Marco-Congedo](https://discourse.julialang.org/u/Marco-Congedo)\
**Post date:** [July 14, 2021, 9:03pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656/3 "2021-07-14T21:03:32Z")

</div>

Yeah, that works, but i would like to have all the code in a single code block…

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [July 14, 2021, 9:26pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656/4 "2021-07-14T21:26:33Z")

</div>

I am rather unclear as to what your use case is for having all the code in a single code block. What are you exactly trying to achieve? What do you envision being in your final report? If your goal is to remove the code blocks in your report, one could do this to hide the code blocks:

````julia
```julia, echo = false
println("line 1")
println("line 2")
```

```julia, echo = false
display(plot(rand(10))
```

```julia, echo = false
println("line 3")
println("line 4")
```

````

In the end, it would look similar to I believe what you are trying to do.

---

<div class="post-metadata">

**Author:** ![Marco-Congedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco-congedo/32/7321_2.png) [@Marco-Congedo](https://discourse.julialang.org/u/Marco-Congedo)\
**Post date:** [July 14, 2021, 9:51pm UTC](https://discourse.julialang.org/t/weave-jl-order-of-text-and-plots/64656/5 "2021-07-14T21:51:28Z")

</div>

What i am trying to do is to have .jl files, it does not matter how long they are, that can be included with a single line in a ```julia block located in the .jmd Weave file. For this to be effective, text and plots should output in the given order.

If that is achievable, it would be possible to weave a complex document with text and plots with a few lines of code in the .jmd file. Not sure this would be really useful though.
