WINNT
10/16/97 14:25 119 AUTOEXEC.BAT
2/13/94 6:21 54,619 COMMAND.COM
,#+end_example
#+end_src
* Prose excerpts
** Quote
Use the ~quote~ block for content that *doesn't require the preservation of line
breaks*.
#+begin_src org
,#+begin_quote
Let us change our traditional attitude to the construction of programs:
Instead of imagining that our main task is to instruct a computer what to do,
let us concentrate rather on explaining to human beings what we want a
computer to do.
The practitioner of literate programming can be regarded as an essayist, whose
main concern is with exposition and excellence of style. Such an author, with
thesaurus in hand, chooses the names of variables carefully and explains what
each variable means. He or she strives for a program that is comprehensible
because its concepts have been introduced in an order that is best for human
understanding, using a mixture of formal and informal methods that reinforce
each other.
-- Donald Knuth
,#+end_quote
#+end_src
A short one:
#+begin_src org
,#+begin_quote
Everything should be made as simple as possible,
but not any simpler. -- Albert Einstein
,#+end_quote
#+end_src
** Verse
In a ~verse~ environment, there is an *implicit line break at the end of each line*,
and *indentation* is preserved:
#+begin_src org
,#+begin_verse
Everything should be made as simple as possible,
but not any simpler. -- Albert Einstein
,#+end_verse
#+end_src
Typically used for quoting passages of an email message:
#+begin_src org
,#+begin_verse
>> The meeting has been postponed to next Friday.
>
> Has the deadline for the report been moved too?
Yes. And chekout http://www.doodle.com/ for rescheduling the meeting.
In the text body,
indentation is
preserved.
,#+end_verse
#+end_src
** Block quote with optional attribution line
#+begin_epigraph
epigraph
#+end_epigraph
** Block quotes with their own class attribute
#+begin_highlights
highlights
#+end_highlights
#+begin_pull-quote
pull-quote
#+end_pull-quote
#+begin_blockquote
Blockquote
#+end_blockquote
** Non-breaking space
Insert the Unicode character ~00A0~ to add a non-breaking space.
FIXME Or add/use an Org entity? Or use tilde?
* Comments
#+begin_src org
It's possible to add comments in the document.
# This Org comment here won't be displayed.
#+end_src
* Substitutions
** General replacements
#+begin_src org :eval no
,#+MACRO: longtext this very very long text
Insert {{{longtext}}} wherever required.
#+end_src
#+MACRO: longtext this very very long text
Insert {{{longtext}}} wherever required.
** Styled references
#+BEGIN_SRC org :eval no
,#+MACRO: color @@html:$2@@
{{{color(blue, This text is colored in blue.)}}}
{{{color(red, This other text is in red.)}}}
#+END_SRC
#+MACRO: color @@html:$2@@
{{{color(blue, This text is colored in blue.)}}}
{{{color(red, This other text is in red.)}}}
Find more macros on [[https://github.com/fniessen/org-macros][GitHub]].
** Special characters
We also use substitutions to include some of the widely used Unicode characters
(like ©, converted from text characters to its typographically correct entity).
*** Accents
#+begin_src org
- \Agrave \Aacute
#+end_src
*** Punctuation
#+begin_src org
- Dash: \ndash \mdash
- Marks: \iexcl \iquest
- Quotations: \laquo \raquo
- Miscellaneous: \para \ordf
#+end_src
*** Commercial symbols
#+begin_src org
- Property marks: \copy \reg
- Currency: \cent \EUR \yen \pound
#+end_src
*** Greek characters
#+begin_src org
The Greek letters \alpha, \beta, and \gamma are used to denote angles.
#+end_src
*** Math characters
#+begin_src org
- Science: \pm \div
- Arrows: \to \rarr \larr \harr \rArr \lArr \hArr
- Function names: \arccos \cos
- Signs and symbols: \bull \star
#+end_src
*** Misc
#+begin_src org
# Smilies: \smiley \sad
- Suits: \clubs \spades
#+end_src
* Source code
** Inline code
#+begin_src org
Reference code like ~variables~ or ~functions~ inline.
#+end_src
You can also evaluate code inline as follows: 1 + 1 is src_R{1 + 1}.
** Code blocks (with syntax highlighting)
The source code blocks support syntax highlighting:
#+begin_src cpp :eval no
/*
* Application that displays a "Hello" message to the standard output.
*/
int main(int arc, char **argv)
{
printf("Hello, %s!\n", (argc>1) ? argv[1] : "World");
return 0;
}
#+end_src
** Source mode
The following language strings are currently recognized:
#+begin_src emacs-lisp :results drawer :exports results
(concat (mapconcat (lambda (widget)
(widget-get widget :tag))
(cl-remove-if-not (lambda (it)
(and (consp it)
(eq (car it) 'const)))
(cdr
(widget-get
(get
'org-babel-load-languages 'custom-type)
:key-type)))
", ")
".")
#+end_src
#+results:
:RESULTS:
Awk, C, R, Asymptote, Calc, Clojure, CSS, Ditaa, Dot, Emacs Lisp, Fortran, Gnuplot, Haskell, IO, J, Java, Javascript, LaTeX, Ledger, Lilypond, Lisp, Makefile, Maxima, Matlab, Mscgen, Ocaml, Octave, Org, Perl, Pico Lisp, PlantUML, Python, Ruby, Sass, Scala, Scheme, Screen, Shell Script, Shen, Sql, Sqlite, ebnf2ps.
:END:
** Line break
Code block with long lines:
#+begin_src emacs-lisp :eval no
testing testing testing testing testing testing testing testing testing testing
0 1 2 3 4 5 6 7 8 9
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
#+end_src
For PDF (LaTeX), one solution is to surround the code block such as:
#+latex: \scriptsize
#+begin_src R
print("This block is in scriptsize")
#+end_src
#+latex: \normalize
** Line numbers
Both in ~example~ and in ~src~ snippets, you can add a ~-n~ switch to the end of the
~begin~ line, to get the lines of the example numbered.
#+header: :eval no
#+begin_src emacs-lisp -n
(defun org-xor (a b)
"Exclusive or."
#+end_src
If you use a ~+n~ switch, the numbering from the previous numbered snippet will
be continued in the current one:
#+header: :eval no
#+begin_src emacs-lisp +n
(if a (not b) b))
#+end_src
** Callouts
In literal examples, Org will interpret strings like ~(ref:name)~ as labels, and
use them as targets for special hyperlinks like ~[[(name)]]~ (i.e., the reference
name enclosed in single parenthesis). In HTML, hovering the mouse over such
a link will remote-highlight the corresponding code line, which is kind of
cool.
You can also add a ~-r~ switch which removes the labels from the source code.
With the ~-n~ switch, links to these references will be labeled by the line
numbers from the code listing, otherwise links will use the labels with no
parentheses. Here is an example:
#+header: :eval no
#+begin_src emacs-lisp -n -r
(save-excursion ; (ref:sc)
(goto-char (point-min))) ; (ref:jump)
#+end_src
In line [[(sc)]], we remember the current position. [[(jump)][Line (jump)]] jumps to
~point-min~.
* Math
You can embed LaTeX math formatting in Org mode files.
** Inline math expressions
For *inline math* expressions, use ~\(...\)~:
#+begin_src org
The formula \(a^2 + b^2 = c^2\) has been discovered by Pythagoras.
Let \(a=\sin(x) + \cos(x)\). Then \(a^2 = 2\sin(x)\cos(x)\) because \(\sin^2x +
\cos^2x = 1\).
#+end_src
#+begin_warning
It's /not/ advised to use the constructs ~$...$~ (both for Org and for MathJax).
#+end_warning
** Math expressions in display mode
For mathematical expressions which you want to make *stand out, centered on their
own lines*, use ~\[...\]~:
#+begin_src org
The /Euler theorem/:
\[
\int_0^\infty e^{-x^2} dx = {{\sqrt{\pi}} \over {2}}
\]
LaTeX allows to inline such ~\[...\]~ constructs (/quadratic formula/):
\[ \frac{-b \pm \sqrt{b^2 - 4 a c}}{2a} \]
#+end_src
#+begin_warning
Double dollar signs (~$$~) should not be used.
#+end_warning
** Equation numbers
Differently from ~$...$~ and ~\(...\)~, an equation environment produces a *numbered*
equation to which you can add a label and reference the equation by (label) name
in other parts of the text. This is not possibly with unnumbered math
environments (~$$~, ...).
#+begin_src org
The /Pythagoras theorem/:
#+name: pythag
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
See equation [[pythag]].
The /sinus theorem/ can be written as the equation:
\begin{equation}
\label{eqn:sinalpha}
\frac{\sin\alpha}{a}=\frac{\sin\beta}{b}
\end{equation}
See equation [[eqn:sinalpha]].
#+end_src
Only captioned equations are numbered.
Other alternatives: use
- ~\begin{equation*}~ or
- ~\begin{displaymath}~ (= the verbose form of the ~\[...\]~ construct).
~M-q~ does not fill those.
* Miscellaneous effects
** Include Org files
You can include another Org file and skip its title by using the ~:lines~ argument
to ~#+INCLUDE~:
#+begin_src org
,#+INCLUDE: chapter1.org :lines "2-"
#+end_src
#+begin_note
File inclusion, through INCLUDE keywords, is an *export-only feature*.
#+end_note
** Inline HTML
You can include raw HTML in your Org documents and it will get kept as HTML
when it's exported. XXX
#+HTML_BEGIN:
Text can be preformatted (in a fixed-width font).
#+HTML_END:
It is especially useful for more advanced stuff like images or tables where you
need more control of the HTML options than Org mode actually gives you.
Similarly, you can incorporate JS or do anything else you can do in a Web page
(such as importing a CSS file).
You can create named classes (to get style control from your CSS) with:
#+begin_example
,#+begin_note
,*Note example* \\
Did you know...
,#+end_note
#+end_example
You can also add interactive elements to the HTML such as interactive R plots.
Finally, you can include an HTML file verbatim (during export) with:
#+begin_src org
,#+INCLUDE: file.html html
#+end_src
Don't edit the exported HTML file!
** Inline LaTeX
You can also use raw LaTeX. XXX
#+LaTeX_BEGIN: \begin{verbatim}
Text can be preformatted (in a fixed-width font).
#+LaTeX_END: \end{verbatim}
* Notes at the footer
#+begin_src org
It is possible to define named footnotes[fn:myfootnote], or ones with automatic
anchors[fn:2].
#+end_src
* Useful extensions
** Todo extension
*** Dates
Timestamps: [2014-01-16 Thu] and <2014-01-16 Thu>.
*** TODO We need to achieve...
*** DONE [#A] Buy GTD book :online:
:LOGBOOK:
- State "TODO" -> "DONE" [2014-01-16 Thu 09:52]
:END:
By default, ~DONE~ actions will be collapsed.
Note that I should probably implement that default behavior only for ~ARCHIVE~'d
items.
*** TODO [#A] Read GTD book
SCHEDULED: <2014-09-11 Thu>
By default, *all* (active) entries will be expanded at page load, so that their
contents is visible.
That can be changed by adding such a line (into your Org document):
#+begin_src org :eval no
,#+HTML_HEAD:
#+end_src
*** TODO [#B] Apply GTD methodoloy
DEADLINE: <2014-12-01 Mon>
:PROPERTIES:
:HTML_CONTAINER_CLASS: hsCollapsed
:END:
This section will be collapsed when loading the page because the entry has the
value ~hsCollapsed~ for the property ~:HTML_CONTAINER_CLASS:~.
Powerful, no?
*** Some note :computer:write:
You can add tags to any entry, and hightlight all entries having some specific
tag by clicking on the buttons made accessible to you in the "Dashboard".
*** Weekly review :computer:
Now, you can even make your weekly review in the HTML export... Press the ~r~ key
to start entering the "review mode" where all but one active entry are
collapsed, so that you can really focus on one item at a time!
** Bigblow extension
The string ~fixme~ (in *upper case*) gets replaced by a "Fix Me!" image:
#+begin_src org
FIXME Delete this...
#+end_src
* Graphs with Graphviz
To enable the Graphviz extension, we have to add it to the extensions list in
conf.py:
extensions = ['sphinx.est.graphviz']
It uses directly the dot command to process DOT language.
** Undirected
#+begin_src org
,#+begin_src dot :file images/graph.png :cmdline -Tpng
graph foo {
"bar" -- "baz";
}
,#+end_src
#+end_src
** Directed
#+begin_src org :exports results
,#+begin_src dot :file images/digraph.png :cmdline -Tpng
digraph foo {
"bar" -> "baz";
}
,#+end_src
#+end_src
* Graphs with R
The output from the *execution* of programs, scripts or commands can be inserted
in the document itself, allowing you to work in the /reproducible research/
mindset.
** Text
A one-liner result:
#+begin_src shell :exports both :results verbatim
date +"%Y-%m-%d"
#+end_src
#+results:
: 2014-03-15
# A multiple-line result:
#
# #+name: list-of-styles
# #+begin_src shell :exports both :results verbatim
# # output all styles, but the default one (if any)
# ls styles | grep -v "default"
# #+end_src
#
# #+results: list-of-styles
# #+begin_example
# bigblow
# leuven
# maunakea
# #+end_example
** Example
Data to be charted:
#+name: data
| Month | Degrees |
|-------+---------|
| 1 | 3.8 |
| 2 | 4.1 |
| 3 | 6.3 |
| 4 | 9.0 |
| 5 | 11.9 |
| 6 | 15.1 |
| 7 | 17.1 |
| 8 | 17.4 |
| 9 | 15.7 |
| 10 | 11.8 |
| 11 | 7.7 |
| 12 | 4.8 |
Code:
#+name: R-plot
#+begin_src R :var data=data :results graphics :file images/Rplot.png :exports both
plot(data, type="b", bty="l", col=c("#ABD249"), las=1, lwd=4)
grid(nx=NULL, ny=NULL, col=c("#E8E8E8"), lwd=1)
legend("bottom", legend=c("Degrees"), col=c("#ABD249"), pch=c(19))
#+end_src
** Graph
The resulting chart:
#+results: R-plot
[[file:images/Rplot.png]]
** R code block
#+begin_src R
library(ggplot2)
summary(cars)
#+end_src
#+results:
Plot:
#+begin_src R
library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
#+end_src
* Index
* Glossary
* Bibliography
* Footnotes
[fn:myfootnote] Extensively used in large documents.
[fn:2] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.