# Course about creating reports with julia

**URL:** https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570
**Category:** Teaching & Outreach
**Tags:** announcement, latex
**Created:** [September 21, 2022, 12:54pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570 "2022-09-21T12:54:20Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 21, 2022, 12:54pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/1 "2022-09-21T12:54:20Z")

</div>

I create a little [walked example](https://comp-bio.idmpages.uni-h.de/teaching/julia-physics-report/) through the julia package landscape for creating \LaTeX - reports with julia.  
This course is targeted at physics students needing to write reports about physical experiments, but might also be useful for people in other fields.

Happy to hear your thoughts on it.

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [September 22, 2022, 6:56am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/2 "2022-09-22T06:56:15Z")

</div>

Looks very nice and useful. (I’m always trying to advertise the use of Unitful.jl in my group as well and will share this!)

A super tiny detail, in the first plots the unit is in `(` brackets and in the later plots with manual labels it is `[` brackets.

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [September 22, 2022, 8:05am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/3 "2022-09-22T08:05:03Z")

</div>

You could use `UnitfulLatexify.jl` to automate the latex labels as well.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [September 25, 2022, 9:48am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/4 "2022-09-25T09:48:52Z")

</div>

> [@BeastyBlacksmith](#):
>
> Happy to hear your thoughts on it.

Thank you for sharing this excellent course material.

I’ve tried to follow it using VSCode, Julia 1.8.0 on Win 11 and with MiKTeX installed, and it went more or less fine, with mistakes made on folder paths and missing loading some packages (ex: Statistics).

One issue encountered and one question:

- The LaTeX headers in the Pretty Table do not show well:  
 ![PrettyTable_Latex_issue](https://global.discourse-cdn.com/julialang/original/3X/5/5/55a95c6ab2b0084fb0e094fbef6603425a00882f.png)

- Not clear when/how the plot recipe is used in the workflow? It seems to affect the cross-references in the text to the figures and table numbers

Fyi, here is a screenshot of the VSCode project tree:

 ![PhysicsReport_VSCode_Julia1.8.0_Win11](https://global.discourse-cdn.com/julialang/original/3X/2/0/204029e1ad06dd4b2db32f0e7b111054aaf9d008.png)

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 27, 2022, 9:03am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/5 "2022-09-27T09:03:34Z")

</div>

Thanks for following it through!

> The LaTeX headers in the Pretty Table do not show well

Which PrettyTables version is that? Mine was 1.3.1 on julia 1.7.3.

> Not clear when/how the plot recipe is used in the workflow? It seems to affect the cross-references in the text to the figures and table numbers

That seems wierd. How exactly does it affect that? Also did you run lualatex again after the pythontex run?

For reference, my tree can be viewed [here](https://gitlab.uni-hannover.de/comp-bio/teaching/julia-physics-report/-/tree/quarto/working_directory).

---

<div class="post-metadata">

### Author: ![Olivier\_Merchiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_merchiers/32/4073_2.png) [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)
#### Post date: [September 27, 2022, 9:18am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/6 "2022-09-27T09:18:49Z")

</div>

This is super interesting. Thanks a lot for putting this together!  
I was just wondering, is there a reason to prefer plain LaTeX over other solutions like Weave.jl or Literate.jl?

Thanks again

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 27, 2022, 9:41am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/7 "2022-09-27T09:41:59Z")

</div>

The main advantage is that this solution is language agnostic (up to what pythontex supports) and you have more fine grained control over the final layout (e.g. where are my pagebreaks etc.).

I never managed to create a pdf-document with the others that looked how I liked it, I’m also impatient though 😃.  
I do use Literate.jl for web related content quite often though (documentation and notebooks).

---

<div class="post-metadata">

### Author: ![Olivier\_Merchiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_merchiers/32/4073_2.png) [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)
#### Post date: [September 27, 2022, 9:43am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/8 "2022-09-27T09:43:39Z")

</div>

makes sense indeed!

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [September 27, 2022, 9:21pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/9 "2022-09-27T21:21:55Z")

</div>

Thank you for your message.

Used PrettyTables v2.1.0 and Julia 1.8.0. Yes, I’ve run the sequence lualatex, pythontex, lualatex.

For the recipe question, nevermind, it does not make sense indeed.

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 28, 2022, 7:20am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/10 "2022-09-28T07:20:16Z")

</div>

Indeed that seems to have changed in PrettyTables:

```julia
julia> pretty_table(stdout, omega_m_data, header = latexify.(propertynames(omega_m_data)), nosubheader=true, backend=Val(:latex), wrap_table=false)
\begin{tabular}{rrr}
  \hline
  \textbf{\$\textbackslash{}omega\$} & \textbf{\$\textbackslash{}omega\_m\$} & \textbf{\$\textbackslash{}omega\_\{r e s\}\$} \\\hline
  21.3 MHz & 108.3 kHz & 21.1917 MHz \\
  21.25 MHz & 58.4 kHz & 21.1916 MHz \\
  21.22 MHz & 28.2 kHz & 21.1918 MHz \\
  21.202 MHz & 9.9 kHz & 21.1921 MHz \\
  21.192 MHz & 1.5 kHz & 21.1905 MHz \\\hline
\end{tabular}

(jl_jC7E1m) pkg> st PrettyTables
Status `/tmp/jl_jC7E1m/Project.toml`
  [08abe8d2] PrettyTables v2.1.1

```

```julia
julia> pretty_table(stdout, omega_m_data, header = latexify.(propertynames(omega_m_data)), nosubheader=true, backend=Val(:latex), wrap_table=false)
\begin{tabular}{rrr}
  \hline\hline
  \textbf{$\omega$} & \textbf{$\omega_m$} & \textbf{$\omega_{r e s}$} \\\hline
  21.3 MHz & 108.3 kHz & 21.1917 MHz \\
  21.25 MHz & 58.4 kHz & 21.1916 MHz \\
  21.22 MHz & 28.2 kHz & 21.1918 MHz \\
  21.202 MHz & 9.9 kHz & 21.1921 MHz \\
  21.192 MHz & 1.5 kHz & 21.1905 MHz \\\hline\hline
\end{tabular}

(jl_aleDSv) pkg> st PrettyTables
Status `/tmp/jl_aleDSv/Project.toml`
⌅ [08abe8d2] PrettyTables v1.3.1

```

@Ronis_BR I am not sure whether this is intentional?

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [September 28, 2022, 1:15pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/11 "2022-09-28T13:15:47Z")

</div>

Yes, this was a breaking change, sorry about that 😃

The problem is that we must escape all characters in LaTeX to avoid breaking the output. To circumvent this, we created a type called `LatexCell`. If you wrap a value using this structure, then it will not be escaped. Thus, you must ensure you are using valid LaTeX commands. In this case, we can accomplish the same thing we had by:

```julia
julia> data = rand(3, 3);

julia> header = LatexCell.([latexify("α"), latexify("β"), latexify("ω")]);

julia> pretty_table(data; header = header, backend = Val(:latex))
\begin{tabular}{rrr}
  \hline
  \textbf{$\alpha$} & \textbf{$\beta$} & \textbf{$\omega$} \\\hline
  0.379836 & 0.913338 & 0.271825 \\
  0.104393 & 0.598591 & 0.113788 \\
  0.943368 & 0.207498 & 0.0595488 \\\hline
\end{tabular}

```

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 28, 2022, 7:35pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/12 "2022-09-28T19:35:21Z")

</div>

I am curious why you didn’t use `LaTeXString`s for this though. That way it would compose a little bit better with other packages.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [September 28, 2022, 7:50pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/13 "2022-09-28T19:50:11Z")

</div>

I decided to go with that approach for cases that you have an object that when renders it outputs a LaTeX string.

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [September 29, 2022, 3:46am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/14 "2022-09-29T03:46:36Z")

</div>

I don’t understand. In many packages, `LaTeXString` fills exactly the function your `LaTeXCell` does.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [September 29, 2022, 3:49am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/15 "2022-09-29T03:49:54Z")

</div>

Yes, but it will require to add LaTeXString as dependency. I try to keep the number of dependencies as minimum as possible to reduce loading time. In this case, the current approach will work with LaTeXString, Latexify, etc.

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [September 29, 2022, 7:19am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/16 "2022-09-29T07:19:06Z")

</div>

> [@Ronis\_BR](#):
>
> I try to keep the number of dependencies as minimum as possible to reduce loading time.

I can understand that, but LaTeXStrings has zero dependencies and 0.7ms loading time on my machine. While anyone wanting to output `LatexCell`s in order communicate to PrettyTables that the output is a valid latex string has to depend on PrettyTables now, which has 130ms loading time.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [October 1, 2022, 1:05pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/17 "2022-10-01T13:05:24Z")

</div>

> [@BeastyBlacksmith](#):
>
> While anyone wanting to output `LatexCell`s in order communicate to PrettyTables that the output is a valid latex string has to depend on PrettyTables now, which has 130ms loading time.

PrettyTables is a low-level package to print tables. It does not make sense to output `LatexCell` if you are not using PrettyTables to print. No package should do this. When the time to print the data arrives, the function responsible for calling `pretty_table` can wrap the data in `LatexCell`.

I really want to keep the dependencies as low as possible. Now we have `LaTeXString`, but in the HTML backend, we might have the same problem and need to require another package. This can escalate quickly.

What can be implemented is a keyword `allow_latex_in_cells` (we have a similar one in HTML) that, if `true`, will not escape any cell. However, the user must be sure that all cells contain valid LaTeX code. What do you think?

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [October 21, 2023, 7:34am UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/18 "2023-10-21T07:34:37Z")

</div>

@Ronis_BR

Hi!

I found this and I am quite perplexed too, but new to Weave.jl etc. When I try to do what you suggest:

````julia
# My Weave Document with LaTeX Tables

First, we set up the necessary packages and data:

# Remove both \
\```julia
using PrettyTables, DataFrames, Latexify
data = rand(3, 3);
header = LatexCell.([latexify("α"), latexify("β"), latexify("ω")]);
pretty_table(data; header = header, backend = Val(:latex))
\```

````

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/8/88f4b279efb552322071ed94eab3298e50e0ef37.png)

I was under impression that this should just work now - would you know how to fix it, I am probably missing something somewhere 🙂

EDIT: Okay seems like I misread initial question, does not seem to have been Weave.jl related…

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [October 21, 2023, 3:17pm UTC](https://discourse.julialang.org/t/course-about-creating-reports-with-julia/87570/19 "2023-10-21T15:17:34Z")

</div>

Hi!

I do not know about Weave.jl, but it seems it is taking the output of the Julia command and pasting as code instead of text to be rendered by LaTeX.
