- org-mode-aez-notes
- TODO Citation engine
- Define the bibliography
- TODO Define the citation processor
- Inserting references
- Print the bibliography
- Using LaTeX
- Source code
- HTML export from header
- HTML export from body
- HTML export: attributes
- Images
- Publishing to HTML: How this site is generated
- Literate programming and notebooks
- Notebook example 1
- Notebook example 2
- Notebook example 3
- Literate programming with noweb
- Figures
- Linking
- Beamer
- Quotation
- Tables
- Table of contents
- Removing the table of contents
- Configuring the table of contents
- Macros
- Agenda
- Agenda view keys
- Org mode to html
org-mode-aez-notes
This configuration is explained in detail in the Summary of In-Buffer Settings. A sensible header for an org-mode file should contain the following:
- #+title:
- #+Time-stamp: <>
- #+startup: overview
- #+options: toc:nil with #+toc: headlines 2
- #+options: num:nil
You might use #+startup: noinlineimages if you do not want images to display in the window by default. This can be very useful if you have figures too big to fit on the screen.
TODO Citation engine
Org 9.5 provides a new library oc.el which provides tooling to handle citations in Org, e.g., activate, follow, insert, and export them, respectively called «activate», «follow», «insert» and «export» capabilities. Libraries responsible for providing some, or all, of these capabilities are called «citation processors».
The manual contains a few pointers to let you start and you may want to check this blog post. If you need help using this new features, please ask on the mailing list.
Thanks to Nicolas Goaziou for implementing this, to Bruce D’Arcus for helping him and to John Kitchin for paving the way with org-ref.el.
Define the bibliography
Use #+bibliography: to define the bibtex file to use.
TODO Define the citation processor
Use #+cite_export: to define the processor to use. It looks like this should be customised subtantially, but the csl option seemed to work nicely out of the box.
Inserting references
There is the org-cite-insert function to insert a reference. Note that once you have selected the citations to include use M-RET to actually include them in the text. Alternatively, they can be included manually as a semicolon seperated list of @key values.
[cite:@authorYYYYtitle;@authorYYYYtitle]
Print the bibliography
Use #+print_bibliography: at the end of the document to print the bibliography there.
Using LaTeX
Amazingly, you can use latex environments without any issue and they should be handled correctly in both latex and HTML export.
Source code
The following table is derived from this documentation.
Language | Identifier |
---|---|
Emacs Lisp | emacs-lisp |
LaTeX | latex |
Org mode | org |
Python | python |
R | R |
shell | sh |
Haskell | haskell |
Org mode | org |
Graphviz | dot |
HTML export from header
org-mode has functionality for exporting to HTML. The default maths support is good. If you want to include CSS this can be done by including a HTML_HEAD definition. For example, this page has the following line at the top of the file.
If you were to use a different CSS file you would need to change the href .
HTML export from body
If you want to incorporate a small snippet of HTML into the exported HTML use the #+begin_export html snippet to include that elements.
HTML export: attributes
There is the #+attr_html: declaration to specify how things should be exported to HTML. For example
will export the image with the additional attribute that the width should be 700 pixels.
Images
Publishing to HTML: How this site is generated
The code is used to configure the generation of this site looks roughly like the following snippet. For the version of the code actually used, check out my nicemacs.
(require 'ox-publish) (setq org-publish-project-alist '( ("org-notes" :base-directory "~/public-site/org/" :base-extension "org" :publishing-directory "~/aezarebski.github.io/" :recursive t :publishing-function org-html-publish-to-html :headline-levels 4 :auto-preamble t ) ("org-static" :base-directory "~/public-site/org/" :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|cur\\|svg\\|csv\\|json" :publishing-directory "~/aezarebski.github.io/" :recursive t :publishing-function org-publish-attachment ) ("org" :components ("org-notes" "org-static")))) (org-publish "org")
The org-publish-project-alist is the main variable that needs to be set for publishing. Each element of this list describes one destination of the publishing process. Destinations form a hierarchy as can be seen in the «org» element which takes «org-notes» and «org-static» as components.
The base-directory is where to look for source files and the publishing-directory is destination for the results.
Literate programming and notebooks
Notebook example 1
The following demonstrates how org-mode can be used as a notebook for R. Note that
Evaluate an expression and cache the values as =x=. #+name: x \#+begin_src R :cache yes mean(1:10) \#+end_src #+RESULTS[57c60ad6be3794c58f0a94dc3c107a692489cb2b]: x : 5.5 Carry out an action using the variable =x= \#+begin_src R :var x = x print(x) \#+end_src #+RESULTS: : 5.5
Notebook example 2
Another example which makes use of sessions and output files to facilitate viewing plots within the file is given below. To make it easier to specify which R session you want to evaluate the code in there is the rename-buffer function. To acutually evaluate evaluate the code there is org-babel-execute-buffer . If you have set :session this will evaluate it in that specified session.
#+header: :width 300 :height 300 #+begin_src R :session *R-demo* :file 2.png :results graphics file :tangle demo.R library(ggplot2) gNotebook example 3
In this example we use :exports both to ensure that both the code and the resulting output are exported.
#+header: :exports both #+begin_src maxima :results output a : (x* exp(-aa) + y + y * exp(-aa))/ (y*exp(-aa) + x); b : ratsimp(a); c : collectterms(expand(num(b)), exp(aa)) / denom(b); d : block( [ea: exp(-aa)], collectterms(expand(ea * num(b)), ea) / expand(ea * denom(b)) ); display(a, b, c, d);
Literate programming with noweb
The default behaviour when using noweb syntax is that it will be expanded when tangling and exporting. If you want to keep expansion on tangle but not on export set :noweb no-export as shown in the following example.
which is produced by the following orgmode
#+name: foobar #+begin_src javascript :noweb yes < "foo": "bar" >\#+end_srcNote that the block gets the name foobar which we can then reference in the following block
This was itself produced by the following
\#+name: mainjs \#+begin_src javascript :noweb no-export :tangle ../misc/silly-example.json < "fleeb": > > \#+end_srcTangling this produces the following JSON
Figures
org-toggle-inline-images will toggle the display of figures in an org document. To change the size of the displayed image use the following
#+attr_org: :width 450px #+attr_html: :width 450pxFor export there are other commands you might want to issue. See for example the HTML attributes.
Linking
Use #+name: fig:cool-name to label a figure and then [[fig:cool-name]] to reference it. You can use this to name an equation and then link back to it from else where in the document.
Beamer
The command org-beamer-export-to-latex produces a TEX file from your ORG file. So, given your presentation is in slides.org use the following to create a PDF
emacs slides.org --batch --eval="(org-beamer-export-to-latex)" pdflatex slides.tex
There are slightly shorter ways to do this, but having the intermediate TEX is good for fine tuning the resulting slides. NOTE if there are TODO items in the slides, these seem to break the export.
Quotation
This is achieved with #+begin_quote and #+end_quote
Everything should be made as simple as possible, but not any simpler —Albert Einstein
Tables
Table of contents
Removing the table of contents
To remove the table of contents from an org-mode export add the following definition to the top of the file.
Configuring the table of contents
If you want to label headers down to level x and include them down to level y in your table of contents, the following configuration can be added to the top of the org file.
Macros
Define a macro at the top of the file
#+MACRO: name replacement text $1, $2 are arguments
Agenda
The agenda files are used to track TODO items. Use org-agenda-file-to-front to add an org-mode file to the list of agenda files. If you are ever in doubt about which files are in the adgenda, use SPC h d v and request org-agenda-files .
Items in a TODO list can be prioritised by adding an annotation of [#] . There are only three levels available by default, and if no annotation is used it is assumed to be level B.
To make it easier to schedule items, bind org-schedule to SPC o o s ([o]wner-[o]rg-[s]chedule) which will bring up a calendar to select the date. You can hold S and then use the arrow keys to navigate the calendar. Times can be added in 24-hour format to the end of the date. This will add a SCHEDULED property under that item. If you want to add a time to the task, put it after the date. The +1w in the example below means that you want the task to be repeated each week. There are y,m,w,d for year, month, week and day (see here for details).
The following settings ensure that a sensible amount of material is shown in the agenda: items from up to 3 days ago and over a 30 day span in total.
(setq org-agenda-start-day "-3d") (setq org-agenda-span 30) (setq org-agenda-start-on-weekday nil)The org-todo-keywords variable is used to specify the different TODO types. The pipe, | , in the following example is used to designate that "DONE" is the only keyword which indicates that a task is finished. It is probably easiest to use customise to set these variables.
'(org-todo-keywords '((sequence "TODO" "BLOCKED" "DONE")))Agenda view keys
- To navigate up and down lines in the agend view use n/p .
- v d will show the day view.
- v w the week view.
- v m the month view.
- v SPC resets the view.
- . goes to today.
- j will jump to a date (selected via calendar).
Org mode to html
At some point you might want to print your notes, publish them on the web, or share them with people not using Org. Org can convert and export documents to a variety of other formats while retaining as much structure (see Document Structure) and markup (see Markup for Rich Contents) as possible.
The libraries responsible for translating Org files to other formats are called back-ends. Org ships with support for the following back-ends:
- ascii (ASCII format)
- beamer (LaTeX Beamer format)
- html (HTML format)
- icalendar (iCalendar format)
- latex (LaTeX format)
- md (Markdown format)
- odt (OpenDocument Text format)
- org (Org format)
- texinfo (Texinfo format)
- man (Man page format)
Users can install libraries for additional formats from the Emacs packaging system. For easy discovery, these packages have a common naming scheme: ox-NAME , where NAME is a format. For example, ox-koma-letter for koma-letter back-end. More libraries can be found in the ‘ org-contrib ’ repository (see Installation).
Org only loads back-ends for the following formats by default: ASCII, HTML, iCalendar, LaTeX, and ODT. Additional back-ends can be loaded in either of two ways: by configuring the org-export-backends variable, or by requiring libraries in the Emacs init file. For example, to load the Markdown back-end, add this to your Emacs config:
- The Export Dispatcher
- Export Settings
- Table of Contents
- Include Files
- Macro Replacement
- Comment Lines
- ASCII/Latin-1/UTF-8 export
- Beamer Export
- HTML Export
- LaTeX Export
- Markdown Export
- OpenDocument Text Export
- Org Export
- Texinfo Export
- iCalendar Export
- Other Built-in Back-ends
- Advanced Export Configuration
- Export in Foreign Buffers