kimim / orgmode-examples

A demo of orgmode with beamer, plantuml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

orgmode examples

1 Introduction

1.1 Purpose

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

1.2 How

Following tools are used in this file:

2 Preparation

2.1 Emacs settings

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 ~

2.2 Emacs and Orgmode version

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

2.3 TexLive and Beamer Theme

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

2.4 Inkscape version

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)

3 Drawing in code

3.1 PlantUML settings in Emacs

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)))

3.2 PlantUML version

Here is the version info on my machine, including JVM, dot and graphviz:

3.3 Sequence Diagram

3.3.1 code

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

3.3.2 output

images/alice-and-bob.svg

3.4 Class Diagram

3.4.1 code

A simple class diagram
@startuml
class Car
Driver - Car : drives >
Car *- Wheel : have 4 >
Car -- Person : < owns
@enduml

3.4.2 output

images/class-diagram.svg

3.5 ditaa settings in Emacs

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)))

3.6 ditaa

3.6.1 code

+--------+   +-------+    +-------+
|cGRE    | --+ ditaa +--> |cFF0   |
|  Text  |   +-------+    |diagram|
|Document|   |!magic!|    |       |
|     {d}|   |       |    |       |
+---+----+   +-------+    +-------+
    :                         ^
    |       Lots of work      |
    +-------------------------+

3.6.2 output

images/ditaa-process.svg

3.7 tikz logo

3.7.1 code

\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}

3.7.2 output

images/logo.svg

3.8 tikz background

3.8.1 code

3.8.2 output

images/background.svg

4 Equations

4.1 latex equation

\begin{equation} \binom{n}{r}=\dbinom{n}{n-r}=\mathrm{C}_n^r=\mathrm{C}_nn-r \end{equation}

5 Org-babel Evaluating Programming Languages

5.1 shell

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.

5.2 emacs lisp - get current year

(emacs-version)
GNU Emacs 29.1 (build 2, x86_64-w64-mingw32)
 of 2023-08-03
(decoded-time-year (decode-time (current-time)))
2023

5.3 Babashka

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 old

5.4 Babashka - Word Frequency

5.4.1 code

We 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)))

5.4.2 output

e1648
t1127
a1082
o1043
i968
r967
n885
s884
l815
c580

5.5 Clojure

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

5.6 Clojure - get table

5.6.1 code

(doseq [item tbl]
  (println (first item) "\t" (second item)))

5.6.2 output

e 	 1655
t 	 1130
a 	 1085
o 	 1043
i 	 969
r 	 967
n 	 889
s 	 887
l 	 816
c 	 582

5.7 Clojure - chart

5.7.1 code

(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"))

5.7.2 output

images/clojure-chart.svg

5.8 Python

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

5.9 Python pyplot

5.9.1 code

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)

5.9.2 output

images/python-pyplot.svg

5.10 C

printf("%s is %d years old.\n", "C programming language", year - 1972);
C programming language is 51 years old.

5.11 C++

cout << "C++ is " << year - 1979 << " years old" << endl;
C++ is 44 years old

5.12 Java

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

5.13 Rust

(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

6 Org-babel for music and others

6.1 Install LilyPond

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.

6.2 LilyPond

\relative c' {
  \chordmode {c1}
  \chordmode {d1}
  \chordmode {e1}
  \chordmode {f1}
  \chordmode {g1}
  \chordmode {a1}
  \chordmode {b1}
}

images/chords.svg

7 Presenting with Org-beamer

7.1 Beamer

In this section, I will try some beamer settings in orgmode.

7.2 XeTeX version

(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

7.3 simple slide

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}

Enumerations:

  1. important underline slashed code verbatim deleted \alert{alert}
    1. important underline slashed code verbatim deleted \alert{alert}
    2. important underline slashed code verbatim deleted \alert{alert}
      1. important underline slashed code verbatim deleted \alert{alert}
      2. important underline slashed code verbatim deleted \alert{alert}
      3. important underline slashed code verbatim deleted \alert{alert}

7.4 simple slide with definition

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

7.5 simple slide with wallpaper

  • This slide has a nice wallpaper.
  • It is the westlake in the morning.

7.6 full screen with a wallpaper

7.7 special blocks with heading - 1

7.7.1 block

  • this is a block

7.7.2 alert block

  • this is an alert block

7.7.3 theorem block

  • this is a theorem block

7.7.4 proof

  • This is proof

7.8 special blocks with heading - 2

7.8.1 example

This is an example

7.8.2 example block

Example block

7.8.3 definition

  • this is a definition

7.9 special blocks without heading

7.9.1 beamercolorbox

  • this is a beamercolorbox

7.9.2 verse

verse is a poem? maybe.

7.9.3 quotation

Software is eating the world.

7.9.4 quote

This is a quote.

7.10 some todo list

  • 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

7.11 table rotated title

\rotatebox{45}{enrollment to the class}\rotatebox{45}{name}\rotatebox{45}{date}
xKimi2021-09-18
Ivy2021-09-28
xAnna2021-09-20

7.12 table fixed width

7.13 table formula

21
2
21
[2, 2, 2][1, 1]
32
62

7.14 4 dimension

7.14.1 up

7.14.1.1 up-left

  • 1

7.14.1.2 up-right

  • 2

7.14.2 down

7.14.2.1 down-left

  • 3

7.14.2.2 down-right

  • 4

7.15 three columns

7.15.1 col1

  • left column occupies 33%

7.15.2 col2

  • middle column occupies 33%

7.15.3 col3

  • right column occupies 33%

7.16 quote and quotation

Quote:

If winter comes, can Spring be far behind?

Quotation:

7.17 Highlighting text

The double @@ can be used to enclose active code.

For example:

This is very *@@beamer:<2->@@important*

This is very @@beamer:<2->@@important

7.18 Lists in action

#+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

7.19 Columns in action

7.19.1 col1

Phoenix! Phoenix! How virtue has declined.

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.

7.19.2 col2

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.

7.19.3 col3

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.

7.20 Blocks in action

7.20.1 Block1

Great understanding is broad, small understanding is picky.

7.20.2 Block2

Great words overflowing, small words haggling.

7.20.3 Block3

Asleep the bodily soul goes roaming, awake it opens through our form.

8 Conclusion

8.1 Key Takeaways

  • 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!

9 Appendix

9.1 References

bibliography:references.bib

9.2 OC References

10 Footnotes

[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

About

A demo of orgmode with beamer, plantuml


Languages

Language:TeX 79.0%Language:Makefile 21.0%