Placing Images

I could not find a way to automatically display the images. The best way seems to be to manually write the following. Replace image.png with the full path if the file is not in the immediate location as the org file.

[[file: image.png]]

With this, images can be toggled on and off with iimage-mode.

You can make use of more options in the following manner.


#+CAPTION: Penguin body mass
#+ATTR_HTML: :width 600
[[./image.png]]

Exporting to HTML

I installed the package nice-org-html for exporting org files to html. Then the exporting is simply a matter of M-x nice-org-html-export-to-html followed by accepting the offered defaults.

One nice thing about this package is it allows choosing a theme: that way the html file resembles the emacs theming better.

Lots of boilerplate in the exported html file. Not ideal, but I can deal with that.

Changes to Emacs Config

Here are the additions I made to my-org.el.

(setq org-html-inline-images t)
(setq org-html-inline-image-rules
      '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\|webp\\)\\'")
        ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\|webp\\)\\'")
        ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\|webp\\)\\'")))


(use-package nice-org-html
  :ensure t
  :hook (org-mode . nice-org-html-mode)
  :config
  (setq nice-org-html-theme-alist
        '((light . doom-acario-light)      
          (dark  . doom-pine)))
  (setq nice-org-html-default-mode 'dark))

Appendix

The following file is used to test this and much of the aspects discussed earlier in this series.


#+TITLE: Grand Test
#+PROPERTY: header-args:python :results output :session *test-p* :exports both :python /home/alten/Documents/Projects/SDS/Python/.venv/bin/python  
#+PROPERTY: header-args:R :results output :session *test-r* :exports both :dir /home/alten/Documents/Projects/SDS/R 
#+PROPERTY: header-args:julia :results value :session *test-j* :exports both

Save file after writing the properties (header) and local variables (footer), then reopen the file. For the julia local variables, confirmation will be needed.

* Testing that the environments are loading properly and sessions are working.

** Python
#+begin_src python 
import sys
import numpy
import pandas
import scipy
import seaborn

print("Python:", sys.executable)
print("NumPy:", numpy.__version__)
print("Pandas:", pandas.__version__)
print("SciPy:", scipy.__version__)
print("Seaborn:", seaborn.__version__)
#+end_src

#+RESULTS:
: Python: /home/alten/Documents/Projects/SDS/Python/.venv/bin/python
: NumPy: 2.5.2
: Pandas: 3.0.5
: SciPy: 1.18.1
: Seaborn: 0.13.2

#+begin_src python :results output 
print(numpy.random.randint(10))
#+end_src

#+RESULTS:
: 4

** R
#+begin_src R 
library(tidyverse)
library(janitor)
library(skimr)
library(renv)

cat("R:", R.version.string, "\n")
cat("Project:", renv::project(), "\n")
cat("R home:", R.home(), "\n")
#+end_src

#+RESULTS:
: R: R version 4.6.1 (2026-06-24)
: Project: /home/alten/Documents/Projects/SDS/R
: R home: /usr/lib64/R

#+begin_src R
packageVersion("janitor")
#+end_src

#+RESULTS:
: 2.2.1

** Julia
#+begin_src julia :results silent
using DataFrames
using CSV
using Distributions
using Pkg

println("Julia project: ", Base.active_project())
println("Julia version: ", VERSION)

df = DataFrame(x = randn(5));
println("Rows: ", nrow(df))
println("Columns: ", ncol(df))
#+end_src

: Julia project: /home/alten/Documents/Projects/SDS/Julia/Project.toml
: Julia version: 1.12.7
: Rows: 5
: Columns: 1

#+begin_src julia :results silent
Pkg.status("DataFrames")
#+end_src

#+RESULTS:
: Status `~/Documents/Projects/SDS/Julia/Project.toml`
:   [a93c6f00] DataFrames v1.8.2

* Images

Images need to be manually placed as shown in this section. The code may be used to produce it, but the RESULTS do not show up as images or get exported to HTML. So far, only by explicitly stating their path in the format shown below works.

#+CAPTION: Penguin body mass
#+ATTR_HTML: :width 600
[[file: img.png]]

Use `org-display-inline-images`. Or toggle image display using `iimage-mode`.

** Python image creation
#+begin_src python 
import pandas as pd
penguins = pd.read_csv(
    "/home/alten/Documents/Projects/SDS/Data/Raw/penguins.csv"
)
print(penguins.head())
#+end_src

#+RESULTS:
:   species     island  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g     sex  year
: 0  Adelie  Torgersen            39.1           18.7              181.0       3750.0    male  2007
: 1  Adelie  Torgersen            39.5           17.4              186.0       3800.0  female  2007
: 2  Adelie  Torgersen            40.3           18.0              195.0       3250.0  female  2007
: 3  Adelie  Torgersen             NaN            NaN                NaN          NaN     NaN  2007
: 4  Adelie  Torgersen            36.7           19.3              193.0       3450.0  female  2007

#+begin_src python :results output
import matplotlib.pyplot as plt

plt.hist(penguins["body_mass_g"].dropna(), bins=20)
plt.xlabel("Body mass (g)")
plt.ylabel("Frequency")
plt.title("Penguin body mass")

fname = "img4.png"
plt.savefig(fname)

#+end_src

#+CAPTION: Penguins Histogram
[[./img4.png]]

** R image creation

#+begin_src R
penguins = read.csv(
    "/home/alten/Documents/Projects/SDS/Data/Raw/penguins.csv"
)
print(head(penguins, 2))
#+end_src

#+RESULTS:
: species    island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g    sex year
: 1  Adelie Torgersen           39.1          18.7               181        3750   male 2007
: 2  Adelie Torgersen           39.5          17.4               186        3800 female 2007


#+begin_src R :results silent
png("img4-r.png")
hist(
    penguins$body_mass_g,
    breaks = 20,
    xlab = "Body mass (g)",
    ylab = "Frequency",
    main = "Penguin body mass"
)
dev.off()
#+end_src

[[./img4-r.png]]

Note that the images are created in `SDS/R` when produced in this manner. To get the images to show up, I cut the image and pasted it in the folder containing this org file. 

** Julia image creation

Note that the data types in the source file needed to be fixed first. (The original csv stores numbers as strings.)

#+begin_src julia
using CSV
using DataFrames
penguins = CSV.read(
    "/home/alten/Documents/Projects/SDS/Data/Raw/penguins.csv",
    DataFrame
)
first(penguins, 2)
#+end_src

#+RESULTS:
: 2×8 DataFrame
:  Row  species   island     bill_length_mm  bill_depth_mm  flipper_length_mm   
:       String15  String15   String7         String7        String3             
: ─────┼──────────────────────────────────────────────────────────────────────────
:    1  Adelie    Torgersen  39.1            18.7           181                 
:    2  Adelie    Torgersen  39.5            17.4           186
:                                                                3 columns omitted


#+begin_src julia :results file
using Plots

histogram(
    skipmissing(penguins.body_mass_g),
    bins = 20,
    xlabel = "Body mass (g)",
    ylabel = "Frequency",
    title = "Penguin body mass"
)

savefig("img4-julia.png")
#+end_src

[[file: img4-julia.png]]



* Export
Use `nice-org-html-export-to-html` to export as html file.

For the Julia code blocks, it is necessary to set `:results silent` to export only previous results to html.

* Mathematical equations.
Make sure org-fragtog is activated.

\begin{align}
E[X] &= \mu \\
\operatorname{Var}(X) &= \sigma^2 \\
E[X^2] &= \mu^2 + \sigma^2
\end{align}







# Local Variables:
# julia-vterm-repl-program: "julia --project=/home/alten/Documents/Projects/SDS/Julia"
# End: