Techniques for Writing

Table of Contents

1 Tmp

1.1 Footnote cite

See this for biblatex with org-mode:

#+LATEX_HEADER: \usepackage[style=authortitle,backend=bibtex]{biblatex}
#+LATEX_HEADER: \addbibresource{../../../smart-scholar-dist/bib/AAAI/AAAI-2015}

Cite like this:


Print reference slides:



# bibliographystyle:apalike
# bibliography:../../../smart-scholar-dist/bib/ICML/ICML-2013.bib,../../../smart-scholar-dist/bib/AAAI/AAAI-2015.bib

2 Org Mode

2.1 Structure

2.1.1 Drawer

The heading can have a drawer, meaning it is hidden by default. Under a headline, use :DRAWERNAME: and :END: to denote the beginning and end. C-c C-x d also creates drawer easily. If region is active, move the region to a drawer.

2.1.2 Footnote

Footnote can be of these format:

  • [fn:1] some text
  • [fn:name]
  • [fn:: anonymous inline footnote!]
  • [fn:name: named inline footnote that can be referenced from elsewhere]

There should be two empty lines after the footnote definition.

C-c C-x f inserts a footnote (at the end of page); C-c C-c jump to definition or back to reference; C-c ' :: edit the footnote in a seperate buffer.

2.1.3 Headings

Moving around
C-c C-n :: next heading C-c C-p :: previous heading C-c C-f :: next heading same level C-c C-b :: previous heading same level C-c C-u :: parent heading C-c C-j :: jump to some node. Direct type to navigate, and tab to expand.
Use the command org-promote-subtree and org-demote-subtree to adjust the heading level. M-h marks current tree. It is very useful to narrow the subtree using C-x n s and widen it back by C-x n w.

2.2 Agenda

It is very convenient to use org-capture to quickly write down a task to a pre-specified org file, and return from this interruption. After that, use org-refile (C-c C-w) to organize the entries inside the file, into different top-level headings. When a job is done, use org-archive-subtree to move it to the archive file, defaults to xxx_archive (C-c C-x C-s)in the same directory.

org-capture-goto-target will goto the file associated with template entry. org-capture-goto-last-stored goes directly to the last stored file.

A TODO keyword in the beginning of a heading mark it as a TODO item, or simply M-S-<RET> to create one.
You can add a schedule or deadline for such an item, by C-c C-s and C-c C-d respectively. Time-stamp is normally inserted C-c . inserts or modifies time stamp. It can recognize a variety of format. Also, in the interactive calendar and in the org buffer, use M-<ARROW> to move. An item can have a priority within A to C, set by C-c ,.
There're a lot of operations on the entries. In the org buffer, C-c t will rotate TODO state. For a list that is not a heading, you can pre-pend the list with [ ], and C-c C-c toggles it. A task can be clocked. Clock in via C-c C-x C-i and clock out via C-c C-x C-o. C-c ^ can sort the lists, based on many attributes such as todo status, time, priority.
Agenda View

It is better to view the TODO lists in a dedicated buffer. Org keeps the variable org-agenda-files for the global agenda files. You can add current file by C-c [. The global agenda has different view method, namely C-c a a for the week view, C-c a t for all todo items, and C-c a L for the timeline of current file. In side the buffer, <ENTER> enter the org file while <TAB> display the org file in another window.

In the agenda view, d,w,vm,vy change the range to day, week, month, year respectively. E to show the entry text (text inside the heading), R show the clock report. s saves all buffers, f, b and . go to next, previous week and today respectively.

As always g to refresh. It is easier to operate in such a buffer: you don't usually need the C-c prefix. t changes TODO status, , set the priority, with + and - to raise or lower it. You can still set deadline and schedule using the same binding. Clocking in and out becomes I and O, and cancel with X.

2.3 Tags

Tags can be the variable name plus @ is available. Every heading can have tags at the end of it. Use :tag1:tag2: syntax. Tags will be inherited by default for the subtrees. C-c C-c :: at the heading, set the tags.

2.4 Properties

Similar to tags, we can also set the property, the key value pairs. It is inside the PROPERTY drawer. Each line is a property, where key is surrounded with :, and value after it. Property is not inherited by default.

2.5 Exporting

2.5.1 bibliography

Normally you only need:


It remains to be seen how to put a set of default bib file instead of specifying this ugly file.

I can use hebi-gen-bib to generate a bibliography:xxx for used citations. Then, in generated .tex file, execute tex-bibtex-file to generate bib cache. Then, regenerate pdf will have citations.

To export the used citations to a separate bib file, remove the bibliography:xxx line and run org-ref-extract-bibtex-to-file.

2.5.2 Latex Exporting doc class & options
 #+OPTIONS: toc:nil author:nil

 #+BIBLIOGRAPHY: slicing plain
 #+INCLUDE: "appendix.org" :minlevel 1 appendix
 #+LaTeX: \appendix

 #+INCLUDE: "appendix-todo.org" :minlevel 1
 #+INCLUDE: "appendix-context.org" :minlevel 1
 #+INCLUDE: "appendix-helium-guard.org" :minlevel 1
 #+INCLUDE: "appendix-valgrind-exp.org" :minlevel 1 code listing
#+ATTR_LATEX: :options frame=shadowbox,label={expressions}

The options will be passed directly to latex option, e.g. when using minted \begin{minted}[frame=xxx,label=xxx].

#+ATTR_LATEX: :font \small
#+ATTR_LATEX: :float t

You can wrap it inside a minipage

#+ATTR_LATEX: :options [t]{0.33\textwidth}

2.5.3 Beamer

The header setup:

#+STARTUP: beamer
#+AUTHOR: Hebi Li
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+OPTIONS: H:2 toc:t num:t

The above configuration define "H" to be 2, meaning the frame is the second level heading (**). The top level heading (*) can be used to organize the presentation. To show the current section, add this just after every top level heading.

#+TOC: headlines [currentsection]

There's an automatic way to add table of contents before each section:

#+latex_header: \AtBeginSection[]{\begin{frame}<beamer>\frametitle{Topic}\tableofcontents[currentsection]\end{frame}}

The *** will becomes block. These blocks can utilize the horizontal space.

#+BEGINEXAMPLE Octave code   BMCOL B_block The output   BMCOL B_block


2.6 Table

#+TBLFM: $4=$2/10
#+TBLFM: $4=$2*100/$3
#+TBLFM: $4=(round $4)

2.7 Image


  • org-toggle-inline-image
  • org-display-inline-image
  • org-redisplay-inline-image
  • org-remove-inline-image

The width is defined by org-image-actual-width

  • t: actual width
  • 300: 300px

Use #+ATTR_HTML: :width 300px to set the html export size.

Reference: a good tutorial.

2.8 org-ref Commands
  • C-c ]: insert citation, typically with helm: org-ref-helm-insert-cite-link
  1. Navigation in the bib file
    next entry
    previous entry

3 Markdown


# xxx ## xxx


> xxx
*italic* **bold**
_italic_ __bld__

Image & link

[link name](http://www.lihebi.com)
![image name](http://xx.jpg)
[link name][url]
[url]: http://xxx.xxx

4 Latex

4.1 Configuration

To see what is your tex home:

kpsewhich -var-value=TEXMFHOME

It should be something like "~/texmf". Putting class and style file into correct path inside that folder will enable global usage of the class. check whether it works or not:

kpsewhich sig-alternate-05-2015.cls

Typically you don't need to update database, but if you want, Command to update the ls-R database

  • texhash
  • mktexlsr

4.2 Mathematics

  • Greek
\alpha (α) \beta (β) \gamma (γ) \theta (θ)
\phi (φ) \varphi (ϕ) \xi (ξ) \mu (μ)
\pi (π) \rho (ρ) \sigma (σ) \epsilon (ε)
\partial (∂) \ell (ℓ)        
  • spacing
\quad (\quad) \qquad (\qquad)
  • logic
\cup (∪) \bigcup (\bigcup) \cap (∩) \vee (∨)
\wedge (∧) \in (∈) \notin (∉) \neg (¬)
\subset (⊂) \subseteq (\subseteq) \supset (⊃)    
\supseteq (\supseteq) \le (≤) \ge (≥) \neq (≠)
\forall (∀) \exists (∃)        
  • arrow
\leftarrow (←) \rightarrow (→)
\Rightarrow (⇒) \Leftarrow (⇐)
\Leftrightarrow (⇔) \longrightarrow (\longrightarrow)
  • accents
\hat{a} (\hat{a}) \bar{a} (\bar{a}) \vec{x} (\vec{x})
  • math
\infty (∞) \propto (∝) \lfloor (⌊)
\rfloor (⌋) \lceil (⌈) \rceil (⌉)
\sum_i^j (∑ij) \sum\limits_i^j (\(\sum\limits_i^j\))    
\int (∫) \prod (∏) \times (×)
\ldots ( \ldots ) \frac{a}{b} (\frac{a}{b}) \sqrt{n} (\sqrt{n})
\overline{abc} (\overline{abc})        
  • mark
\checkmark (✓)
|x| =
-x & \text{if } x < 0,\\
0 & \text{if } x = 0,\\
x & \text{if } x > 0.
\begin{equation*} |x| = \begin{cases} -x & \text{if } x < 0,\\ 0 & \text{if } x = 0,\\ x & \text{if } x > 0. \end{cases} \end{equation*}

4.3 Primitives

Font size can be tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge.

The lists can be enumerate, itemize, description.

To make a double column table or figure, add * to the end of the environment name.

The general table and figures are:

Item & Quantity \\\hline
Widgets & 42 \\
Gadgets & 13
\caption{\label{tab:widgets}An example table.}
  \caption{\label{fig:frog}This frog was uploaded to writeLaTeX via the project menu.}

You can name a place by label and refer to it by ref.

The following primitives are provided by ulem:

regular underline
double underline
strike out
dense cross out

4.4 Tips

The the default for LaTeX is to have no indent after sectional headings. Thus the first paragraph will have no indent. To indent it, \usepackage{indentfirst}. \noindent before the text also seems to work.

The default article template is too narrow. To use the full page, \usepackage{fullpage}.

The fancyhdr package can be used to add header and footer.

\rhead{573 HW1}
\lhead{Hebi Li}
\rfoot{Page \thepage}
%% \lfoot{xxx}
%% \cfoot{xxx}

cite link (need to load a package like hyperref or url)

  title = {{MS Windows NT} Kernel Description},
  howpublished = {\url{http://web.archive.org/web/20080207010024/http://www.808multimedia.com/winnt/kernel.htm}},
  note = {Accessed: 2010-09-30}

4.5 Beamer

#+AUTHOR: Hebi Li
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+OPTIONS: H:2 toc:nil num:t author:t
#+LATEX_HEADER: \lstset{numbers=none,frame=shadowbox, basicstyle=\scriptsize, breaklines=true, basewidth={0.45em,0.3em}, stringstyle=\ttfamily}


  • Madrid
  • CambridgeUS

4.6 listings

4.6.1 Global setting:


\lstset{frame=trBL} % lowercase for single frame, upper case for double
\lstset{frameround=fttt} % from upper right, clock-wise
%% frame should not be too fancy


%% after using courier, the font here will be much better
%% none, left
\lstset{numbers=left, numberstyle=\tiny}
\lstset{keywordstyle=\color{black}\bfseries\underbar} % the keyword
\lstset{showspaces=false, showtabs=false} % the annoying space indicators


\lstset{emph={key1,word2}, emphstyle-\underbar}
\lstset{emph={square}, emphstyle=\color{red}
        emph={[2]root,base}, emphstyle={[2]\color{blue}}}
\lstset{morecomment=[s][\color{blue}]{/*+}{*/} % /*+ xxx */ will be in blue!

Style arbitrary content:

(*@\color{red}everything here will be red@*)

4.6.2 Local setting:

\begin{lstlisting}[float, caption=The caption] % using caption will cause the title be: "listing 1: xxx"
title=this is title
using title will remove the "listing 1:"

4.7 Tikz

4.7.1 Hacks

When fitting figure, if you put text direclty into the fitted node, it will not be vertically centered. Instead, create a new node at the (node.center), and put text in it.

4.7.2 FAQ

Use scale=0.5, transform shape to scale

4.7.3 Code Structure

First, use the package


Then load libraries


Optionally some settings (TODO). Except \tikzset command, all other command should be put inside tikzpicture.

  \tikzset{grid/.style={gray,very thin,opacity=1}}

To start a tikzpicture, you start the {tikzpicture} environment. It is suitable to be put inside a {figure} env. This also means, if it is not put inside a figure, it can actually be used as an inline image. The baseline is the center of current line, and you can use /tikz/baseline option to lower or raise it. This option is evaluted at the end of drawing, thus have access to the node names defined. It can also access the outmost current bounding box.


\tikz command; is the same as begin and end tikzpicture, and put command inside. At the end of this environment, tikz makes a guess about the bounding box, which is updated whenever it encounters a coordinate. This may be imprecise.

Finally, the background is transparent. In order to set to something else, you need the background package.

4.7.4 Parameters (options)

The options are the same as using \tikzset{options}. Sometimes there needs not a value, and it is interpreted like this:

  • If key is a color, color=key is processed
  • if key contains a dash, arrows=key is processed
  • if key is a name of a shape, shape=key is processed.

They are specified in key=value pairs.

  • color: a color can be the name (list TODO) or using xcolor extension, (color1!30!color2), where color2 is optional.
  • line width. Expect a dimension. The following are standalone options, specifying to line width
    • ultra thin
    • very thin
    • semithick
    • thick
    • very thick
    • ultra thick
  • Patterns
    • solid
    • dotted, densely dotted, loosely dotted
    • dashed, densely dashed, loosely dashed
    • dash dot, densely .., loosely ..
    • dash dot dot, densely .., loosely ..
    • double=<core color>
    • double distance=<dimension>

Path can be decorated, given decorate and decoration=<name>. Possible names:

  • zigzag Scope

Parameters can have scope. It is introduced by {scope} invironment, taking the parameters as options, i.e. \begin{scope}[key=value]. Scopes can be nested, and have lexcial scope. The top level {tikzpicture} env also acts like a scope.

There's also a every scope option to install styless for every scope.

The scopes package provide an easier way to specify scopes, using just {[options] ...}. This is pretty useful for inside-path scoping. One line scope command is also available as \scoped[options]<path command>. Styles

Another way to group code together is to define a style. Like help lines style. Styles are defined as an option, e.g.

my style/.style={draw=red, fill=red!20}

The .style means "these keys should not be applied immediately, but rather a definition". Later reference to it is same as written the key values literally.

There seems not to be a way to inherit a style, but rather, you can .append style. The appended style is added to the end, and the last style will win. There's also a .prefix style but not useful in this case. The content of style can be parameterized, by #n where n starts from 1. It seems that it will be replaced literally.

outline/.style={draw=#1, fill=#1!50},

Note 2 things:

  1. the lexer is actually pretty good
  2. can use default value (s?)

Use it as outline=blue

4.7.5 Coordinates

The general syntax is

([options] <coordinate spec>)

Options are optional, and coordinate spec can be any one of the system. The options includes

  • xshift=3cm
  • shift=(x,y)

The Systems. Inside each value, the arithmetic operations can be used. All numbers can accept the following unit (pt, cm, TODO), and if no unit is provided, it uses the coordinate system setting.

  • (x,y): xy-corredinate
  • (30:1cm): 1cm in the 30 degress direction.
  • (x,y,z): 3d

Node is also often used for specify a coordinate. The implicit way is

  • (a)
  • (a.north)
  • (a.10): 10 degree angle Intersection

Yet another way is to use perpendicular coordinate system. This calculate the intersection.

  • (2,1 |- 3,4): yield 2,4
  • (3,4 -| 2,1)

A more general way to find intersection of two pathes is to use intersections library (TODO). Relative position
  • ++(x,y): You can also use relative position. means shift to the last point used.
  • +(x,y): similar to ++ but does not change the last point

Note that the scoping will not localize the position, thus to make a local part "local", you can use the /tikz/current point is local option. calc

The package calc provide calculation for coordinates. The general syntax is:

([options] $<coordinate computation$)

The coordinate computation is roughly

compute ::= A [+-] A [+-] A ...
A ::= <factor>*<coordinate><modifiers>

Note that the <coordinate> must be surounded by (). Modifiers can be:

  • partway modifier: !number!angle:<second coordinate>, e.g. (1,2)!.75!(3,4). angle: is optional
  • distance modifiers: !dimension!angle:<second coordinate>. This differs with partway that it is a concrete distance (like 1cm) instead of a percentage.
  • projection modifiers: (a)!(b)!(c) means draw a line between a-c, and project b onto c, get the intersection point.

4.7.6 Path

Path is a list of path operations. The coordinates can be cycle, literally. Before each operation, options can be given. The option will apply to ALL following path operations.

  • rounded corners
  • sharp corners
  • color=red

There's a style set point as /tikz/every path.

Here are a list of all operations:

  • move-to: (a)
  • line-to:
    • straight line: -- (a)
    • horizontal and vertical line: -|(a) and |-(a)
  • curve-to: ..controls<c>and<d>..(a)
    • and<d> is optional.
  • rectangle: rectangle (a)
  • circle and ellipse circle[<options>]
    • the options are mandary. Set a radius. If set x radius and y radius differently, it will be a ellipse.
  • arc operation: arc[<options>]: TODO
  • grid operation: grid[<options>](a): add a grid filling the rectangle. Options include step, xstep, ystep. The typically used style is help lines.
\draw [help lines] (0,0) grid (3,2)
  • parabola TODO
  • sin/cos TODO
  • svg TODO
  • plot
  • to path operation: to[<options>]<nodes>(a): nodes are the label nodes, there's a every to style option to style it. Options include in and out to set the degree of the in and out lines.
  • foreach operation
    • foreach<variables>[<options>] in {values} {<path commands>}
    • E.g. foreach \x in {1,...,3} {--(\x,1) -- (\x,0)} This is weired.
  • let operation: seems to bind variable to coordinates.
  • scoping operation: {}
  • node and edge operation (Separate)
  • graph operation
  • pic operation

4.7.7 Actions (on path) Draw
  • \draw: \draw is an abbreviation for \path[draw]. It will draw the entire path if this option appear anywhere inside the path. The draw=color will specify the color.
  • \fill: only for closed path. abbrev for \path[fill]. \filldraw is abbrev for \path[fill,draw].
    • fill=<color>
    • pattern=<name> TODO list of patterns
      • dots
      • bricks
    • pattern color=<color>
  • \shade: similarly there're \shade and \shadedraw Clip
  • \clip: does NOT have \clipdraw because it seems not making sense. If you want, use \path[draw,clip] explicitly

clip can be nested, and the clipped area will be in effect for the subsequent path. Those path will not affect the picture size. The only way to end the clip is to close the scope. Thus scope is typically used to create local clip, and clip is typically the first path in a scope. Bounding box

A path can be used as a bounding box. It can be used in two ways, make it smaller or bigger.


  \draw[use as bounding box] (2,0) rectangle (3,1);
  \draw (1,0) -- (4.75);

The second draw will be out of the box of this picture, and strike through the text.


\useasboundingbox (0,0) rectangle (3,1);
\fill (0.75, .25) cicle (.5cm);

The bounding box is larger than the filled circle, so the text will be further apart.

There's a node current bounding box, which has the shape of rectangle. For a single path, there's also a node called current path bounding box. The tikzpicture env also supports a trim left (which has a default of 0pt) and trim right. It will trim the bounding box, not the figure.

4.7.8 Arrow

Use the library arrows.meta.


  • have specified arrows or its short form (it must have a dash) (just put -> inside the path option)
  • the tips must be valid
  • [C] do not use clip
  • [C] the path is not closed

Possible arrow specification (startspec-endspec) (arrows={xxx} is the full spec):

  • ->
  • >-Stealth: the first > actually change the tail of the arrow
  • -{Stealth[red]}: the red is applied to arrow tip. The option is inside the brackets, and multiple options can be provided, e.g. length, width, scale, scale length, scale width, color, fill, line width, round, sharp TODO Bending and flexing TODO arrow tips

4.7.9 Node

Nodes are intended for putting text. They cannot be easily nested. A node is created by a path operation, similar to other path operations, but node is not part of the path itself. A node has a shape, drawing a node means draw the shape.

The full syntax of the node:

node <foreach> [<options>] (<name>) at (<coordinate>) {<content>}

Everything between node and {} is optional, and the order does not matter except foreach. The node will be put at the current point, unless at presents. A node can have a name for future reference. It is given by name=<name> option, or by node(name){text}. Options

Options are only applied to the node itself, possible options are:

  • draw
  • fill
  • shape=rectangle, circle, ellipse
  • behind path
  • in front of path
  • inner sep: set the following together
    • inner xsep
    • inner ysep
  • outer sep: set the following together
    • outer xsep
    • outer ysep
  • minimum size: set the following together
    • minimum height
    • minimum width Foreach

Foreach works like this: the following creates three nodes. You can also nest the loops.

\tikz \draw (0,0) node foreach \x in {1,2,3} at (\x,0) {\x};
\tikz \draw (0,0) node foreach \x in {1,2,3} foreach \y in {1,2,3} at (\x,0) {\x}; Style

The style hooks are every node and every circle node, every rectangle node, etc.

The scope will not influence the lexical scope of the node names. Thus we can use another option name prefix and name suffix so that every node names inside the scope will be renamed under the hood. TODO Multi-part node Node Text


  • text=<color>
  • node font=<font command>
  • font=<font command>: font command can be \small, etc.
  • align: set the alignment. This also enables multiple line text.
    • left
    • flush left (use hyphen to break words)
    • right
    • flush right
    • center
    • flush center
    • justify (use variable spacing)
    • none
  • text width
  • text height
  • text depth: seems useless Node Positioning

It uses anchor. The default is the center of the node. Possible anchors

  • north east south west
  • base, center

This is good enough, but the author thinks it is not intuitive enough, thus he came up with some suger:

  • above, below, left, right
  • centered
  1. TODO positioning

    For more advanced placement, there's a library called positioning. This package actually redefines the above, etc, thus loading this package will make the program behaves differently. The detail seems to be interesting. Fitting

This fits the scenario that you want a box that is just big enough to hold something. You need to load the fit library.

You create a node, give fit as an option with the value of several nodes.

\node[fit=(a) (b) (c)]
  1. TODO how to get several boxes to hold several things, but those boxes are of same size and aligned? Place on a line

These continue the node options

  • pos=<fraction>
    • midway: same as pos=0.5
    • near start 0.25
    • near end 0.75
    • very near start 0.125
    • very near end 0.875
    • at start 0
    • at end 1
  • auto=<direction>: direction can be left, right
  • swap: swap left and right. The short alias is '
  • sloped: the text will be aligned with the line or on the tangent to the curve Label & Pin

This is used to add a node of text next to another node.

  • label=[<options>]<angle>:<text>
    • the angle can be the following, if it is not specified, the value of label position is used.
      • a number as degree
      • anchor like north
      • above, below, left, right
    • absolute is a style. It will change the meaning of angle
    • label distance
    • every label: a style placeholder
  • pin=[<options>]<angle>:<text>: it is very similar to label, the only difference is that it adds a line between the two nodes
    • pin distance
    • every pin
    • pin position
    • every pin edge
    • pin edge

The quotes syntax is very useful. It is in the library quotes. This must be placed inside the option of a node. The format is


options don't need to be surrounded by curly braces, unless there's a comma in it (because the comma should mean the next option for the node). If the text has comma or colon, it MUST be surrounded by curly braces, like "{hello, world}". This should be limitation of parser.

  • quotes mean label
  • quotes mean pin
  • every label quotes
  • every pin quotes
  • node quotes mean TODO 17.12 Edge and from here

4.7.10 Pic

You can define some shape, and then reuse it at any place a node can appear. But the pic itself cannot be referenced. But the node inside pic can be referenced.

You define a pic by

\tikzset {
mypic/.pic = {
\draw (-3mm, 0) to [bend left] (0,0) to [bend left] (3mm,0);

Reuse it by

\tikz \draw (1,1) -- (2,2) pic {mypic} -- (3,2) pic {mypic};

The pic syntax is

pic [<options>] {<pic type>}

You can also draw some inline pics. Note that you still need the curly brace, but leave it empty.

\tikz \pic [pics/code={\draw ...;}] {}

Pic can have actions, too, like

  • color=red
  • draw
  • fill

Finally, to style pic, you can use every pic. You can use quote syntax inside the option of pic, too.

4.7.11 Graph

The graph system is syntax suger for nodes, for the sake of creating a lot of similar nodes. The \graph command is sure a DSL, extending the DOT syntax. To use it, load the graphs library.

graph is actually a path command, and \graph is abbrev for \path graph. Thus it can be used anywhere on path that expect --. The styling hook is every graph. The syntax:

graph [<options>] <group spec>

Options can be:

  • nodes=<options>: these options are applied to nodes, multiple options require enclosing curly braces.
  • edges=<options>: edge options
  • edge: alias for edges
  • edge node=<node spec>: if this presents, it will cause a node to be added implicitly to each edge, placed next to it. A node spec is nothing special, just a node [options] {text}.
  • edge label=<text>: abbrev for edge node=node[auto]{text}
  • edge label'=<text>: abbrev for edge node=node[auto,swap]{text} Specs
  1. Group Spec
    <group spec> ::= {[options] <chain spec> [,;] <chain spec> ...}
    <chain spec> ::= <node spec> <edge spec> <node spec> ...
    <edge spec> ::= [-> | -- | <- | <-> | -!-] [<options>]

    Options will be local to the group.

    The chain spec are seperated by comma or semicolon, they are equivalent. A chain is a list of nodes seperated by edge, where 5 types of edge is availabe. The last one means no edge is desired, this is useful in simple graph. As opposite to multi graph, in simple graph there's only one edge (latter win) between two nodes. These are graph options.

    Foreach can be used inside a group spec at any place of a chain spec. Each of the iteration will create a chain spec, separated by comma. Macros can also be used here.

    \foreach \i in {1,2,3} {
      a\i -> {x_\i, y_\i}

    The edge spec options can be:

    • left anchor=<anchor>: use east, west, etc. It is the anchor of the source.
    • right anchor=<anchor>
  2. Node Spec
    <node spec> ::= <direct> | <reference> | <group spec>
    <direct> ::= <node name> / <text> [<options>]
    <reference> ::= (<node name> | <node set name>)

    If the node starts with open paren, it is treated as a reference to a existing node or set. If it starts with open brace, it is a group. Otherwise it is a direct.

    For a direct node, if the node name contains special symbols, it must be quoted by double quotes. The slash and text is optional, in which case the simple name is used (very likely to be the node name). Otherwise, the text is shown in the node.

    Typically if a node name is already created, it will use that. The behavior is controled by some group options.

    • use existing node=<true or false>
    • fresh nodes=<true or false>: all nodes are created, the repeated nodes are named by appending a '. This new name can be used as reference to this node.
    • number nodes=<start number=1>: same as fresh nodes, but repeated names are renamed by append a space and an increasing number.
    • name=<text>: it is a prefix added to all nodes, separated by space. Prefixes can be nested.

    The nodes also accept following options:

    • as=<text>: use text as shown in the node
    • empty nodes: node text will be empty
    • math nodes: the node name used as text will be treated as math (but without requiring the dollar sign) when shown.

    For a reference node, it is simple. But you can create a node set. The set must be created manually, before you can add nodes into the set. Create the set by the following option:

    • /tikz/new set=<set name>: Create a set. unlike most of graph options (which start from /tikz/graphs), this is under the root tikz name. That means it is intended to be used outside the group env.
    • /tikz/set=<set name>: add the current node to the already defined set

    Finally, the <group spec> in the syntax means that a group spec can appear at whatever places a node spec can be. Edge

The edge option can accept quotes.

  • edge quotes=<options>: abbrev for every edge quotes/.style
  • edge quotes center: abbrev for setting edge quotes={anchor=center}
  • edge quotes mid

A good trick is to specify a graph structure first, and then specify the edges to be colored. The nodes will not be recreated.

When connecting with groups, there're multiple edges. You can specify a single edge by add options to the node.

  • target edge style=<options>: abbrev > options
  • target edge clear: abbrev clear >
  • target edge node=<node spec>
  • source edge style=<options>: abbrev < options
  • source edge clear: abbrev clear <
  • source edge node=<node spec> Coloring

The color is logical color. Some predefined color including source and target. These are used by connecting groups. You can use not source and not target on some nodes to remove them from the list, thus they will not be connected. Another color class is all which reference to all nodes. You can also create classes, but I don't currently need this feature.

When joining groups, you can use complete bipartite for the connecting edge option. This is called graph operator, the effect is to connect the each source and each target. Note that the source and target are the color classes of the nodes, used by complete bipartite by default. You can change it.

E.g. create color class

color class=red, color class=green

Set the nodes to color class, and connect them.

{[red] a b c} -- [complete bipartite={red}{green}]
{[green] d e f} Node placement

The idea of graph is to make the positioning automatic. Thus we have some algorithm to use.

  • grow up, down, left, right
  • branch up, down, left, right
  • grid placement

We also have some positioning that takes the node size into consideration.

  • grow right/left/up/down sep
  • branch up/down/left/right sep

We also have circular placement

  • clockwise
  • counterclockwise

For the levels, we can give them styles at once.

level 1/.style={...}

4.7.12 Tree

The node syntax can also be used to draw a tree. A node can be followed by any number of children, each introduced by keyword child. The children are also nodes, thus they can have children using the same syntax. Trees have a set of options (TODO).

child must follow a full node, or another child. The syntax of child:

child ::= child [<options>] foreach <variables> in {<values>} {<child path>}

The foreach staff makes this seems complex, while it is not at all. Apart from child keyword, everything is optional, including the {<child path>}, in which case an empty node is added. Foreach has a special keyword, and the repeatition will start from the preceeding child keyword, i.e. the whole thing shown above.

The child path does not have a formal syntax, so allow me make one up

<child path> ::= <child> <child path> | <node spec>

Multiple children can be specified, in which case they are siblings. Each child should only have one node. Tikz will give a name for each children as <parent>-N where N starts from 1. This naming system is nested. The child can also be manually named, using (name), and this node will not have the automatic naming. However, the rest of the nodes will still have the same counting names, as if this node also counts. Styling


  • option before root: apply to the whole tree
  • option after root: apply to root node only
  • option before child: apply to all children from here
  • option after child: apply to this child and its children
  • option after node: apply to this node only

Some hooks

  • every child
  • every child node
  • level <number> Placement

The following options can be specified multiple times for each portion of the tree.

  • level distance
  • sibling distance
  • grow=direction: direction can be a degree, or down,up,left,right; north,east,etc.

A special option for use after the child is missing. It will leave the space, but don't draw the node. A special styling of edge is to put edge from parent[<options>] right after a node, styling the coming edge. forest

4.7.13 Matrix

Matrix is actually a node with matrix as option. The \matrix is abbrev for \path node [matrix].

A matrix consists of rows of cells. Inside each row, columns are seperated by &. Rows end with \\, even for the last one. Each cell picture is a light weight drawing canvas. It need not to be a node. It can be multiple nodes, a drawing path, etc.

The alignment defaults to the origin of the cell picture, i.e. for both row and column, origin of the cell pictures are aligned. The origin seems to be similar to the center of the node. Eash node can have left and right option, to change the alignment.

The separation of the rows and columns are controlled by column sep=<spacing list> and row sep=<spacing list>, where spacing list is 1cm or 1cm, between origin or 1cm, between borders. The & and \\ can also take options, but only spacing list. This will specify the spacing for the next separation. Styling
  • every cell={<row>}{<column>}: this is a style hook. The row and column are optional.
    • cells=<options>: abbrev for every cell/.append style=<options>
    • nodes=<options>: abbrev for every node/.append style=<options>
  • column <number>: style for the column
    • every odd column
    • every even column
  • row <number>: style for the row
    • every odd row
    • every even row
  • row <number> column <number>: more specific Anchoring
  • matrix anchor=<anchor>: this anchor will only apply to the matrix
  • anchor=<anchor>: apply to both matrix and cells

4.7.14 Data Visualization

Use the library datavisualization.

The syntax:

\datavisualization[options] <data spec>;

This command must be inside tikzpicture env, and the prefix is /tikz/data visulization. Thus, the common tikz command like red cannot be used. You have another set of options to use.

Options must have at least the following two components:

  • axis
  • visualizers

data spec is similar to path, it contains sequence of keywords with their own parameters.

Other commands include:

  • scope
  • info Axis system

You can specify axis system manually, but typically just choose from one of the pre-defined systems.

  • scientific axes
  • school book axes
\datavisualization [
  scientific axes,
  all axis={grid},
  x axis = {attribute=time, label, length=2.5cm, ticks=few},
  y axix = {attribute=colname2, label={$x^2$}},
  visualize as smooth line
] data {
  time, colname2

ticks can be

  • few
  • some
  • many

There are also absolute positioning and several positioning strategies. There are also styling options for ticks and grid. Provide data

Use data command.

data [<option>] {<inline data>}

This command, used inside data spec, give data. The whole {<inline data>} is optional. If present, it is used. Otherwise, option specify the file to read, by read from file=<filename> option.

data {
data point[<options>]

specify one single data point, options

  • x
  • y
data group [<options>] {<name>} = {<data spec>}
data group [<options>] {<name>} += {<data spec>}
data group [<options>] {<name>}
  1. define a group of data points
  2. extend a group
  3. use a group

This is for reuse some data points. Visualizers

Specified in options.

  • visualize as smooth line
  • visualize as scatter

You may use multiple visualizers. Then you want to use different colors, provide legends.

Using these without parameter will use line and scatter as default set name.

  • visualize as line,
  • visualize as scatter
  • visualize as smooth line

Use these to specify particular set name.

visualize as line=sin,
visualize as line=cos

This also has a sugar syntax:

visualize as line/.list={sin, cos}

To specify which data belong to which visualizer, you have two ways.

data {


data [set=sin] {
data [set=cos] {

The second one is obviously better in most cases.

After defining the visualizer with different name, you can set style to it by just assign options to the name.

style={<style options>}

Style options:

  • red
  • densely dotted
  • mark=x

Apart from style option, you also has legend option. Legend is actually automatically added.

legend={below, rows=2},
sin={label in legend={text=$x^2$}},
style sheet=strong colors Style sheets & Legends

style sheet values:


  • strong colors
  • vary hue
  • shades of blue
  • shades of red
  • gray scale


  • vary thickness
  • vary dashing


  • cross marks

A very good idea is to put label or pin directly inside the graph, for that, for each visualizer defined, assign the label in data or pin in data with proper text and style.

sin={label in data={text=$x^2$, when=y is 1, text colored}}

It will place x2 at the point of y=1, with the same color as the sin line.

For pin in data, you have also pin length and pin angle options.

Now back to legend placement, it can be (alias in parenthesis):

  • east outside (right)
  • north east outside
  • south east outside
  • west outside (left)
  • north west outside
  • south west outside
  • north outside (above)
  • south outside (below)

Inside placement is also supported

  • south east inside
  • east inside

Can also relative to data points

  • right of=<data point>: e.g. right of={x=1,y=2}
  • above right of=<data point>
  • above of
  • above left of
  • left of
  • below left of
  • below of
  • below right of

The text of legend can be styled as well.

4.7.15 TODO Packages shapes.multipart

It adds to the node following options:

mynode/.style={split, rectangle split parts=2}


5.1 Plantuml

5.1.1 Installation

Set the path in org-plantuml-jar-path variable in emacs. C-c C-c to evaluate it, and C-c C-x C-v (org-toggle-inline-image) to show the image inline.

The block line:

#+BEGIN_SRC plantuml :file wikitmp_plantuml.png :exports results

5.1.2 Class Diagram

abstract class AbstractClass {
  .. Seperators ..
  {static} StaticField
  {abstract} AbstractMethod()
class Concrete
class Single << (S,#FF7700) Singleton >>

Single "A side note" <|-- "B side note" Concrete : extension
AbstractClass --* Concrete : Composition,\nmultiline
AbstractClass --o Single : Aggregation
AbstractClass -- Single : just a line
AbstractClass ..|> Single : dotted, with arrow >
note left of AbstractClass : note left of A, can be\n<b>top,bottom,left,right</b>

5.1.3 Sequence Diagram

Sequence Diagram is used to describe the communication of participants. The message can be sent to myself.

title: Some Title
'this is a comment
participant Alice
actor Bob
database DB

Alice -> Bob : label on arrow
Alice <-- Bob : dotted arrow
note right: a note

== seperator ==
Alice -[#red]> DB : red arrow
...5 minutes later...
Alice -[#0000ff]-> Cindy : the color #0000ff
Bob -> Cindy
Bob -> Bob : self-messaging

note left
end note

note left of Alice #cyan
        left of Alice,
        in background cyan
end note

note left of Bob: Bob is an "actor"
note left of DB: DB is a "database"
note left of Cindy: Cindy is anonymous

note over Alice: note over Alice

6 Graphviz/Dot

6.1 Language

A graphviz source start from either graph or digraph. In graph, you need to use -- for edges, while in digraph, use -> instead. An optional strict means there's no duplicated edges (previous will be removed).

Statements are separated by semicolon. Typically there are node stmt, edge stmt, and subgraph to group statements.

graph :: [strict] (graph | digraph) [ID] '{' stmt_list '}'
subgraph :: [subgraph [ID] ] '{' stmt_list '}'
stmt_list :: stmt ';' stmt_list
stmt :: node_stmt | edge_stmt | attr_stmt | ID '=' ID | subgraph

Attributes can be associated with node, edge, graph, subgraph, or cluster of subgraph. It is a list of key=value pairs. The attr_stmt is meant for setting style for the whole subgraph.

attr_stmt :: (graph | node | edge) attr_list
attr_list :: '[' (ID = ID) + ']'

If you only want to apply attr to node, you should write the nodestmt separately, otherwise it will be applied on the edges.

edge_stmt :: (node_id | subgraph) (->|--) (node_id | subgraph) + [attr_list]
node_stmt :: node_id [attr_list]

A subgraph is a cluster, if its name has prefix cluster.

6.2 Attributes

name used by (NEC by default) value
labeldistance E  
labelfontsize E  
shape N  

common style:

  • solid
  • dashed
  • dotted
  • bold

node style:

  • rounded
  • diagonals
  • filled
  • striped
  • wedged

Edge style: just common style.

Cluster style

  • rounded
  • filled
  • striped

Node shape (some):

  • box
  • ellipse
  • oval
  • circle
  • diamond
  • plaintext

6.3 CMD

dot -Tpng -o xxx.png xxx.dot
# automatic generate output filename based on input name
dot -Tpng -O xxx.dot

Popular output format:

  • png
  • pdf
  • svg