To evaluate many features of orgmode, such as
- drawing with code
- evaluating results of code snippets
- exporting orgmode file to pdf slides
All the orgmode “source text” is hosted in github: https://github.com/kimim/orgmode-examples
Following tools are used in this file:
- MSYS2 provides many tools and libraries
- GraalVM JDK supports Java, JS, R and more
- GNU Emacs with kimim-emacs configuration
- Org Mode, including org-babel, org-export
- TexLive with beamertheme-hippo style
- PlantUML, Graphviz, Mermaid, ditaa, \LaTeX{} tikz package
- LilyPond for music notation
- Inkscape to convert svg to pdf, during orgmode-pdf exporting
You may need to use kimim-emacs configuration:
# backup existing emacs config
cd ~ && mv .emacs .emacs-backup && mv .emacs.d .emacs.d-backup
# clone this config
git clone https://github.com/kimim/kimim-emacs
# copy default .emacs to ~
cp kimim-emacs/.emacs ~
Firstly, let’s check GNU Emacs[fn:1] and Orgmode[fn:2] version:
(concat (emacs-version)
"\nOrgmode " (org-version))
GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-03 Orgmode 9.6.6
Install TexLive[fn:3] to <texlive-path>
and clone beamertheme-hippo[fn:4], and
update \TeX{} cache:
git clone https://github.com/kimim/beamertheme-hippo \
<texlive-path>/texmf-local/tex/latex/beamertheme-hippo
mktexlsr
Install Inkscape[fn:5] to convert SVG image to PDF.
This is inkscape version on my Windows 10:
inkscape --version
Inkscape 1.3 (0e150ed6c4, 2023-07-21)
Download plantuml.jar[fn:6], and set jar-path
(require 'url-handlers)
(url-copy-file "https://nchc.dl.sourceforge.net/project/plantuml/plantuml.jar"
"./plantuml.jar" t)
(use-package ob-plantuml
:ensure nil
:config
(require 'plantuml-mode)
;; WARNING: if variables are from other package, setq them at :config
(setq org-plantuml-jar-path "./plantuml.jar")
(setq org-plantuml-executable-args "-headless -charset UTF-8")
(add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
(add-to-list 'org-babel-load-languages '(plantuml . t)))
Here is the version info on my machine, including JVM, dot and graphviz:
Let’s draw a simple sequence diagram with this plantuml code. We will use noweb cite:ramsey1994literate [cite:@ramsey1994literate] technique here to add code from other place with
<<name-of-code-snippet>>
.
@startuml
hide footbox
hide unlinked
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: Another authentication Response
@enduml
@startuml
class Car
Driver - Car : drives >
Car *- Wheel : have 4 >
Car -- Person : < owns
@enduml
Download ditaa.jar[fn:7], and set jar-path
(require 'url-handlers)
(url-copy-file "https://sourceforge.net/projects/ditaa/files/latest/download"
"./ditaa.zip" t)
(shell-command-to-string "unzip ditaa.zip && mv ditaa*.jar ditaa.jar")
(use-package ob-ditaa
:ensure nil
:custom
(org-ditaa-jar-path "./ditaa.jar")
:config
(add-to-list 'org-src-lang-modes '("ditaa" . artist))
(add-to-list 'org-babel-load-languages '(ditaa . t)))
+--------+ +-------+ +-------+
|cGRE | --+ ditaa +--> |cFF0 |
| Text | +-------+ |diagram|
|Document| |!magic!| | |
| {d}| | | | |
+---+----+ +-------+ +-------+
: ^
| Lots of work |
+-------------------------+
\begin{tikzpicture}
\filldraw[blue] (0,0) rectangle (-4,-2);
\filldraw[blue,rotate=-30] (0,0) rectangle (1,-0.2);
\filldraw[blue] (-4,0) circle (0.2);
\filldraw[blue] (-4,-2) rectangle (-3,-3);
\filldraw[blue] (0,-2) rectangle (-1,-3);
\filldraw[blue] (-4,0) rectangle (-5.5,-1.5);
\end{tikzpicture}
\begin{equation} \binom{n}{r}=\dbinom{n}{n-r}=\mathrm{C}_n^r=\mathrm{C}_nn-r \end{equation}
sh --version
GNU bash, version 5.2.15(2)-release (x86_64-pc-msys) Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
(emacs-version)
GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-03
(decoded-time-year (decode-time (current-time)))
2023
Babashka is a fast native Clojure scripting runtime, developed by Michiel Borkent.
Before evaluating following code block, you need to get bb.exe
to your
system PATH from https://github.com/babashka/babashka/releases and
configure ob-bb
from https://github.com/kimim/ob-bb .
(println "Babashka is" (- year 2019) "years old")
Babashka is 4 years oldWe use babashka to read this README.org file, and list the top frequent characters in this file. Then we use several programming language to generate a bar chart from the result table of this code.
(require '[clojure.string :as str])
(-> (slurp "README.org")
(str/split #"")
(->>
(filter #(re-matches #"\w" %)))
(frequencies)
(->>
(sort-by val)
(reverse)
(take 10)))
e | 1648 |
t | 1127 |
a | 1082 |
o | 1043 |
i | 968 |
r | 967 |
n | 885 |
s | 884 |
l | 815 |
c | 580 |
According to Rich Hickey cite:hickey2020history, Clojure was initially designed in 2005.
Visit deps.edn
and call cider-jack-in
before evaluating following code
block:
(println "Clojure is" (- year 2005) "years old")
Clojure is 18 years old
(doseq [item tbl]
(println (first item) "\t" (second item)))
e 1655 t 1130 a 1085 o 1043 i 969 r 967 n 889 s 887 l 816 c 582
(require '[clj-chart.chart :as chart])
(require '[clj-chart.plot :as plot])
(let [x (map first tbl)
y (map second tbl)
chart (chart/bar
{:series [{:name "char-freq"
:xs x :ys y}]})]
(plot/store! chart nil "images/clojure-chart.svg"))
Check Python version in shell:
python --version
Python 3.11.6
Evaluate Python code:
print("Python is " + str(year - 1991) + " years old")
Python is 32 years old
import matplotlib.pyplot as plt
import pandas as pd
data = pd.DataFrame(tbl)
fig=plt.figure(figsize=(4,2))
fig.tight_layout()
plt.bar(data[0], data[1])
fgname = 'images/python-pyplot.svg'
plt.savefig(fgname)
printf("%s is %d years old.\n", "C programming language", year - 1972);
C programming language is 51 years old.
cout << "C++ is " << year - 1979 << " years old" << endl;
C++ is 44 years old
TODO: can pass variable to java
import java.util.Calendar;
public class Main{
public static void main(String[] args){
int thisyear = Calendar.getInstance().get(Calendar.YEAR);
System.out.println("Java is " + (thisyear - 1995) + " years old");
}
}
Java is 28 years old
(package-install 'ob-rust)
Install rust-script
to evaluate Rust code blocks:
cargo install rust-script
TODO: cannot pass variable to rust
fn main() {
println!("Rust is {} years old", 2023 - 2016);
}
Rust is 7 years old
LilyPond cite:nienhuys2003lilypond is a system for automated music engraving.
You can get the installation file from https://lilypond.org/download.html and install it.
Check the version:
lilypond --version
GNU LilyPond 2.22.1 Copyright (c) 1996--2021 by Han-Wen Nienhuys <hanwen@xs4all.nl> Jan Nieuwenhuizen <janneke@gnu.org> and others. This program is free software. It is covered by the GNU General Public License and you are welcome to change it and/or distribute copies of it under certain conditions. Invoke as `lilypond --warranty' for more information.
\relative c' {
\chordmode {c1}
\chordmode {d1}
\chordmode {e1}
\chordmode {f1}
\chordmode {g1}
\chordmode {a1}
\chordmode {b1}
}
In this section, I will try some beamer settings in orgmode.
(princ (format "XeTeX version: %s\n"
(eshell-command-result "xelatex --version") "\n"))
XeTeX version: XeTeX 3.141592653-2.6-0.999994 (TeX Live 2022) kpathsea version 6.3.4 Copyright 2022 SIL International, Jonathan Kew and Khaled Hosny. There is NO warranty. Redistribution of this software is covered by the terms of both the XeTeX copyright and the Lesser GNU General Public License. For more information about these matters, see the file named COPYING and the XeTeX source. Primary author of XeTeX: Jonathan Kew. Compiled with ICU version 70.1; using 70.1 Compiled with zlib version 1.2.11; using 1.2.11 Compiled with FreeType2 version 2.11.1; using 2.11.1 Compiled with Graphite2 version 1.3.14; using 1.3.14 Compiled with HarfBuzz version 3.4.0; using 3.4.0 Compiled with libpng version 1.6.37; using 1.6.37 Compiled with pplib version v2.05 less toxic i hope Compiled with fontconfig version 2.13.96; using 2.13.96
This is a simple slide, with some formatted texts:
- important underline slashed
code
verbatim
deleted\alert{alert}- important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert}- important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert}
- important underline slashed
- important underline slashed
Enumerations:
- important underline slashed
code
verbatim
deleted\alert{alert}- important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert}- important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert} - important underline slashed
code
verbatim
deleted\alert{alert}
- important underline slashed
- important underline slashed
It is not recommended to have second level definition bullet…
- Beamer
- LaTeX package to generate slides
- Orgmode
- Powerful plain text format
- org-babel
- Let Orgmode understand and evaluate programming languages
- ox-latex
- Exporter to export orgmode to latex and further to PDF
- This slide has a nice wallpaper.
- It is the westlake in the morning.
- this is a block
- this is an alert block
- this is a theorem block
- This is proof
- this is a definition
- this is a beamercolorbox
- daily task [33%]
- [X] fetch the milk in the morning
- [ ] check the mailbox
- [ ] clean the garden
- learning task [50%]
- [X] read the book
- [X] write the reading notes
- [ ] make a presentation
- [ ] present to students
\rotatebox{45}{enrollment to the class} | \rotatebox{45}{name} | \rotatebox{45}{date} |
---|---|---|
x | Kimi | 2021-09-18 |
Ivy | 2021-09-28 | |
x | Anna | 2021-09-20 |
2 | 1 | |||
2 | ||||
2 | 1 | |||
[2, 2, 2] | [1, 1] | |||
3 | 2 | |||
6 | 2 |
- 1
- 2
- 3
- 4
- left column occupies 33%
- middle column occupies 33%
- right column occupies 33%
Quote:
If winter comes, can Spring be far behind?
Quotation:
The double @@
can be used to enclose active code.
For example:
This is very *@@beamer:<2->@@important*
This is very @@beamer:<2->@@important
#+ATTR_BEAMER: :overlay +-
can show list one by one:
- Can you remember
- The magic Mesosoic numbers
- The dinosaur one to ten
You can also add <3->
before each item to set the order:
- <6-> Can you remember
- <5-> The magic Mesosoic numbers
- <4-> The dinosaur one to ten
It can’t wait for the future or catch up with what’s behind.
When the Dao works in the world, the sage man works his ways,
When the Dao has disappeared the Sage lives out his days.
In times like these just keep far from the shackles and the blade.Good fortune’s lighter than a feather, but none knows how to bear it,
Disaster’s heavier than the earth, but none knows how to dodge it.
Enough! Enough! These toils of virtue serving man,Danger! Danger! Escape! – draw the line in the sand.
Brambles, brambles, don’t cut me as I go,
Twisting, twisting, my feet stay free of woe.
Great understanding is broad, small understanding is picky. Great words overflowing, small words haggling. Asleep the bodily soul goes roaming, awake it opens through our form.- Emacs is a long lasting, and wonderful text editor
- Orgmode is an awesome plain text format
- \LaTeX{} is great typesetting tool
- Beamer is a \LaTeX{} package for preparing presentation
- Thus, using these tools within Emacs is cool!
bibliography:references.bib
[fn:1] https://www.gnu.org/software/emacs
[fn:2] https://orgmode.org
[fn:3] http://tug.org/texlive
[fn:4] https://github.com/kimim/beamertheme-hippo
[fn:5] https://inkscape.org
[fn:6] https://plantuml.com
[fn:7] https://sourceforge.net/projects/ditaa/files/latest/download