The Org Manual

Table of Contents


Next: , Previous: (dir), Up: (dir)

Org Mode Manual

This manual is for Org (version 6.12b).

Copyright © 2004, 2005, 2006, 2007, 2008 Free Software Foundation

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”

(a) The FSF's Back-Cover Text is: “You have the freedom to copy and modify this GNU manual. Buying copies from the FSF supports it in developing GNU and promoting software freedom.”

This document is part of a collection distributed under the GNU Free Documentation License. If you want to distribute this document separately from the collection, you can do so by adding a copy of the license to the document, as described in section 6 of the license.

--- The Detailed Node Listing ---

Introduction

Document Structure

Archiving

Tables

The spreadsheet

Hyperlinks

Internal links

TODO Items

Extended use of TODO keywords

Progress logging

Tags

Properties and Columns

Column view

Defining columns

Dates and Times

Creating timestamps

Deadlines and scheduling

Capture

Remember

Agenda Views

The built-in agenda views

Presentation and sorting

Custom agenda views

Embedded LaTeX

Exporting

Markup rules

HTML export

LaTeX and PDF export

Publishing

Configuration

Sample configuration

Miscellaneous

Interaction with other packages

Extensions

Hacking

Tables and lists in arbitrary syntax


Next: , Previous: Top, Up: Top

1 Introduction


Next: , Previous: Introduction, Up: Introduction

1.1 Summary

Org is a mode for keeping notes, maintaining TODO lists, and doing project planning with a fast and effective plain-text system.

Org develops organizational tasks around NOTES files that contain lists or information about projects as plain text. Org is implemented on top of Outline mode, which makes it possible to keep the content of large files well structured. Visibility cycling and structure editing help to work with the tree. Tables are easily created with a built-in table editor. Org supports TODO items, deadlines, time stamps, and scheduling. It dynamically compiles entries into an agenda that utilizes and smoothly integrates much of the Emacs calendar and diary. Plain text URL-like links connect to websites, emails, Usenet messages, BBDB entries, and any files related to the projects. For printing and sharing of notes, an Org file can be exported as a structured ASCII file, as HTML, or (TODO and agenda items only) as an iCalendar file. It can also serve as a publishing tool for a set of linked web pages.

An important design aspect that distinguishes Org from for example Planner/Muse is that it encourages to store every piece of information only once. In Planner, you have project pages, day pages and possibly other files, duplicating some information such as tasks. In Org, you only have notes files. In your notes you mark entries as tasks, label them with tags and timestamps. All necessary lists like a schedule for the day, the agenda for a meeting, tasks lists selected by tags etc are created dynamically when you need them.

Org keeps simple things simple. When first fired up, it should feel like a straightforward, easy to use outliner. Complexity is not imposed, but a large amount of functionality is available when you need it. Org is a toolbox and can be used in different ways, for example as:

     • outline extension with visibility cycling and structure editing
     • ASCII system and table editor for taking structured notes
     • ASCII table editor with spreadsheet-like capabilities
     • TODO list editor
     • full agenda and planner with deadlines and work scheduling
     • environment to implement David Allen's GTD system
     • a basic database application
     • simple hypertext system, with HTML and LaTeX export
     • publishing tool to create a set of interlinked webpages

Org's automatic, context sensitive table editor with spreadsheet capabilities can be integrated into any major mode by activating the minor Orgtbl mode. Using a translation step, it can be used to maintain tables in arbitrary file types, for example in LaTeX. The structure editing and list creation capabilities can be used outside Org with the minor Orgstruct mode.

There is a website for Org which provides links to the newest version of Org, as well as additional information, frequently asked questions (FAQ), links to tutorials etc. This page is located at http://orgmode.org.


Next: , Previous: Summary, Up: Introduction

1.2 Installation

Important: If Org is part of the Emacs distribution or an XEmacs package, please skip this section and go directly to Activation.

If you have downloaded Org from the Web, either as a distribution .zip or .tar file, or as a GIT archive, you must take the following steps to install it: Go into the unpacked Org distribution directory and edit the top section of the file Makefile. You must set the name of the Emacs binary (likely either emacs or xemacs), and the paths to the directories where local Lisp and Info files are kept. If you don't have access to the system-wide directories, you can simply run Org directly from the distribution directory by adding the lisp subdirectory to the Emacs load path. To do this, add the following line to .emacs:

     (setq load-path (cons "~/path/to/orgdir/lisp" load-path))

If you plan to use code from the contrib subdirectory, do a similar step for this directory:

     (setq load-path (cons "~/path/to/orgdir/contrib/lisp" load-path))

XEmacs users now need to install the file noutline.el from the xemacs sub-directory of the Org distribution. Use the command:

     make install-noutline

Now byte-compile the Lisp files with the shell command:

     make

If you are running Org from the distribution directory, this is all. If you want to install into the system directories, use

     make install
     make install-info

Then add to .emacs:

     ;; This line only if Org is not part of the X/Emacs distribution.
     (require 'org-install)


Next: , Previous: Installation, Up: Introduction

1.3 Activation

Add the following lines to your .emacs file. The last three lines define global keys for the commands org-store-link, org-agenda, and org-iswitchb - please choose suitable keys yourself.

     ;; The following lines are always needed.  Choose your own keys.
     (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
     (global-set-key "\C-cl" 'org-store-link)
     (global-set-key "\C-ca" 'org-agenda)
     (global-set-key "\C-cb" 'org-iswitchb)

Furthermore, you must activate font-lock-mode in Org buffers, because significant functionality depends on font-locking being active. You can do this with either one of the following two lines (XEmacs user must use the second option):

     (global-font-lock-mode 1)                     ; for all buffers
     (add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only

With this setup, all files with extension `.org' will be put into Org mode. As an alternative, make the first line of a file look like this:

     MY PROJECTS    -*- mode: org; -*-

which will select Org mode for this buffer no matter what the file's name is. See also the variable org-insert-mode-line-in-empty-file.


Next: , Previous: Activation, Up: Introduction

1.4 Feedback

If you find problems with Org, or if you have questions, remarks, or ideas about it, please mail to the Org mailing list emacs-orgmode@gnu.org. If you are not a member of the mailing list, your mail will be reviewed by a moderator and then passed through to the list.

For bug reports, please provide as much information as possible, including the version information of Emacs (C-h v emacs-version <RET>) and Org (C-h v org-version <RET>), as well as the Org related setup in .emacs. If an error occurs, a backtrace can be very useful (see below on how to create one). Often a small example file helps, along with clear information about:

  1. What exactly did you do?
  2. What did you expect to happen?
  3. What happened instead?
Thank you for helping to improve this mode.
How to create a useful backtrace

If working with Org produces an error with a message you don't understand, you may have hit a bug. The best way to report this is by providing, in addition to what was mentioned above, a Backtrace. This is information from the built-in debugger about where and how the error occurred. Here is how to produce a useful backtrace:

  1. Start a fresh Emacs or XEmacs, and make sure that it will load the original Lisp code in org.el instead of the compiled version in org.elc. The backtrace contains much more information if it is produced with uncompiled code. To do this, either rename org.elc to something else before starting Emacs, or ask Emacs explicitly to load org.el by using the command line
              emacs -l /path/to/org.el
         
  2. Go to the Options menu and select Enter Debugger on Error (XEmacs has this option in the Troubleshooting sub-menu).
  3. Do whatever you have to do to hit the error. Don't forget to document the steps you take.
  4. When you hit the error, a *Backtrace* buffer will appear on the screen. Save this buffer to a file (for example using C-x C-w) and attach it to your bug report.


Previous: Feedback, Up: Introduction

1.5 Typesetting conventions used in this manual

Org uses three types of keywords: TODO keywords, tags, and property names. In this manual we use the following conventions:

TODO
WAITING
TODO keywords are written with all capitals, even if they are user-defined.
boss
ARCHIVE
User-defined tags are written in lowercase; built-in tags with special meaning are written with all capitals.
Release
PRIORITY
User-defined properties are capitalized; built-in properties with special meaning are written with all capitals.


Next: , Previous: Introduction, Up: Top

2 Document Structure

Org is based on outline mode and provides flexible commands to edit the structure of the document.


Next: , Previous: Document Structure, Up: Document Structure

2.1 Outlines

Org is implemented on top of Outline mode. Outlines allow a document to be organized in a hierarchical structure, which (at least for me) is the best representation of notes and thoughts. An overview of this structure is achieved by folding (hiding) large parts of the document to show only the general document structure and the parts currently being worked on. Org greatly simplifies the use of outlines by compressing the entire show/hide functionality into a single command org-cycle, which is bound to the <TAB> key.


Next: , Previous: Outlines, Up: Document Structure

2.2 Headlines

Headlines define the structure of an outline tree. The headlines in Org start with one or more stars, on the left margin1. For example:

     * Top level headline
     ** Second level
     *** 3rd level
         some text
     *** 3rd level
         more text
     
     * Another top level headline

Some people find the many stars too noisy and would prefer an outline that has whitespace followed by a single star as headline starters. Clean view describes a setup to realize this.

An empty line after the end of a subtree is considered part of it and will be hidden when the subtree is folded. However, if you leave at least two empty lines, one empty line will remain visible after folding the subtree, in order to structure the collapsed view. See the variable org-cycle-separator-lines to modify this behavior.


Next: , Previous: Headlines, Up: Document Structure

2.3 Visibility cycling

Outlines make it possible to hide parts of the text in the buffer. Org uses just two commands, bound to <TAB> and S-<TAB> to change the visibility in the buffer.

<TAB>
Subtree cycling: Rotate current subtree among the states
          ,-> FOLDED -> CHILDREN -> SUBTREE --.
          '-----------------------------------'
     

The cursor must be on a headline for this to work2. When the cursor is at the beginning of the buffer and the first line is not a headline, then <TAB> actually runs global cycling (see below)3. Also when called with a prefix argument (C-u <TAB>), global cycling is invoked.


S-<TAB>
C-u <TAB>
Global cycling: Rotate the entire buffer among the states
          ,-> OVERVIEW -> CONTENTS -> SHOW ALL --.
          '--------------------------------------'
     

When S-<TAB> is called with a numeric prefix argument N, the CONTENTS view up to headlines of level N will be shown. Note that inside tables, S-<TAB> jumps to the previous field.


C-u C-u C-u <TAB>
Show all, including drawers.
C-c C-r
Reveal context around point, showing the current entry, the following heading and the hierarchy above. Useful for working near a location that has been exposed by a sparse tree command (see Sparse trees) or an agenda command (see Agenda commands). With a prefix argument show, on each level, all sibling headings.
C-c C-x b
Show the current subtree in an indirect buffer4. With a numeric prefix argument N, go up to level N and then take that tree. If N is negative then go up that many levels. With a C-u prefix, do not remove the previously used indirect buffer.

When Emacs first visits an Org file, the global state is set to OVERVIEW, i.e. only the top level headlines are visible. This can be configured through the variable org-startup-folded, or on a per-file basis by adding one of the following lines anywhere in the buffer:

     #+STARTUP: overview
     #+STARTUP: content
     #+STARTUP: showall

Forthermore, any entries with a `VISIBILITY' property (see Properties and Columns) will get their visibility adapted accordingly. Allowed values for this property are folded, children, content, and all.

C-u C-u <TAB>
Switch back to the startup visibility of the buffer, i.e. whatever is requested by startup options and `VISIBILITY' properties in individual entries.


Next: , Previous: Visibility cycling, Up: Document Structure

2.4 Motion

The following commands jump to other headlines in the buffer.

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
Backward to higher level heading.
C-c C-j
Jump to a different place without changing the current outline visibility. Shows the document structure in a temporary buffer, where you can use the following keys to find your destination:
          <TAB>         Cycle visibility.
          <down> / <up>   Next/previous visible headline.
          <RET>         Select this location.
          /           Do a Sparse-tree search
          The following keys work if you turn off org-goto-auto-isearch
          n / p        Next/previous visible headline.
          f / b        Next/previous headline same level.
          u            One level up.
          0-9          Digit argument.
          q            Quit
     


Next: , Previous: Motion, Up: Document Structure

2.5 Structure editing

M-<RET>
Insert new heading with same level as current. If the cursor is in a plain list item, a new item is created (see Plain lists). To force creation of a new headline, use a prefix argument, or first press <RET> to get to the beginning of the next line. When this command is used in the middle of a line, the line is split and the rest of the line becomes the new headline5. If the command is used at the beginning of a headline, the new headline is created before the current line. If at the beginning of any other line, the content of that line is made the new heading. If the command is used at the end of a folded subtree (i.e. behind the ellipses at the end of a headline), then a headline like the current one will be inserted after the end of the subtree.
C-<RET>
Just like M-<RET>, except when adding a new heading below the current heading, the new heading is placed after the body instead of before it. This command works from anywhere in the entry.
M-S-<RET>
Insert new TODO entry with same level as current heading.
C-S-<RET>
Insert new TODO entry with same level as current heading. Like C-<RET>, the new headline will be inserted after the current subtree.
M-<left>
Promote current heading by one level.
M-<right>
Demote current heading by one level.
M-S-<left>
Promote the current subtree by one level.
M-S-<right>
Demote the current subtree by one level.
M-S-<up>
Move subtree up (swap with previous subtree of same level).
M-S-<down>
Move subtree down (swap with next subtree of same level).
C-c C-x C-w
Kill subtree, i.e. remove it from buffer but save in kill ring. With a numeric prefix argument N, kill N sequential subtrees.
C-c C-x M-w
Copy subtree to kill ring. With a numeric prefix argument N, copy the N sequential subtrees.
C-c C-x C-y
Yank subtree from kill ring. This does modify the level of the subtree to make sure the tree fits in nicely at the yank position. The yank level can also be specified with a numeric prefix argument, or by yanking after a headline marker like `****'.
C-y
Depending on the variables org-yank-adjusted-subtrees and org-yank-folded-subtrees, Org's internal yank command will paste subtrees folded and in a clever way, using the same command as C-c C-x C-y. With the default settings, level adjustment will take place and yanked trees will be folded unless doing so would swallow text previously visible. Any prefix argument to this command will force a normal yank to be executed, with the prefix passed along. A good way to force a normal yank is C-u C-y.
C-c C-w
Refile entry or region to a different location. See Refiling notes.
C-c ^
Sort same-level entries. When there is an active region, all entries in the region will be sorted. Otherwise the children of the current headline are sorted. The command prompts for the sorting method, which can be alphabetically, numerically, by time (using the first time stamp in each entry), by priority, or by TODO keyword (in the sequence the keywords have been defined in the setup). Reverse sorting is possible as well. You can also supply your own function to extract the sorting key. With a C-u prefix, sorting will be case-sensitive. With two C-u C-u prefixes, duplicate entries will also be removed.
C-x n s
Narrow buffer to current subtree.
C-x n w
Widen buffer to remove a narrowing.
C-c *
Turn a normal line or plain list item into a headline (so that it becomes a subheading at its location). Also turn a headline into a normal line by removing the stars. If there is an active region, turn all lines in the region into headlines. Or, if the first line is a headline, remove the stars from all headlines in the region.

When there is an active region (Transient mark mode), promotion and demotion work on all headlines in the region. To select a region of headlines, it is best to place both point and mark at the beginning of a line, mark at the beginning of the first headline, and point at the line just after the last headline to change. Note that when the cursor is inside a table (see Tables), the Meta-Cursor keys have different functionality.


Next: , Previous: Structure editing, Up: Document Structure

2.6 Archiving

When a project represented by a (sub)tree is finished, you may want to move the tree out of the way and to stop it from contributing to the agenda. Org mode knows two ways of archiving. You can mark a tree with the ARCHIVE tag, or you can move an entire (sub)tree to a different location.


Next: , Previous: Archiving, Up: Archiving

2.6.1 The ARCHIVE tag

A headline that is marked with the ARCHIVE tag (see Tags) stays at its location in the outline tree, but behaves in the following way:

The following commands help managing the ARCHIVE tag:

C-c C-x a
Toggle the ARCHIVE tag for the current headline. When the tag is set, the headline changes to a shadowed face, and the subtree below it is hidden.
C-u C-c C-x a
Check if any direct children of the current headline should be archived. To do this, each subtree is checked for open TODO entries. If none are found, the command offers to set the ARCHIVE tag for the child. If the cursor is not on a headline when this command is invoked, the level 1 trees will be checked.
C-TAB
Cycle a tree even if it is tagged with ARCHIVE.


Previous: ARCHIVE tag, Up: Archiving

2.6.2 Moving subtrees

Once an entire project is finished, you may want to move it to a different location. Org can move it to an Archive Sibling in the same tree, to a different tree in the current file, or to a different file, the archive file.

C-c C-x A
Move the current entry to the Archive Sibling. This is a sibling of the entry with the heading `Archive' and the tag `ARCHIVE' (see ARCHIVE tag). The entry becomes a child of that sibling and in this way retains a lot of its original context, including inherited tags and approximate position in the outline.
C-c C-x C-s
Archive the subtree starting at the cursor position to the location given by org-archive-location. Context information that could be lost like the file name, the category, inherited tags, and the TODO state will be store as properties in the entry.
C-u C-c C-x C-s
Check if any direct children of the current headline could be moved to the archive. To do this, each subtree is checked for open TODO entries. If none are found, the command offers to move it to the archive location. If the cursor is not on a headline when this command is invoked, the level 1 trees will be checked.

The default archive location is a file in the same directory as the current file, with the name derived by appending _archive to the current file name. For information and examples on how to change this, see the documentation string of the variable org-archive-location. There is also an in-buffer option for setting this variable, for example6:

     #+ARCHIVE: %s_done::

If you would like to have a special ARCHIVE location for a single entry or a (sub)tree, give the entry an :ARCHIVE: property with the location as the value (see Properties and Columns).

When a subtree is moved, it receives a number of special properties that record context information like the file from where the entry came, it's outline path the archiving time etc. Configure the variable org-archive-save-context-info to adjust the amount of information added.


Next: , Previous: Archiving, Up: Document Structure

2.7 Sparse trees

An important feature of Org mode is the ability to construct sparse trees for selected information in an outline tree, so that the entire document is folded as much as possible, but the selected information is made visible along with the headline structure above it7. Just try it out and you will see immediately how it works.

Org mode contains several commands creating such trees, all these commands can be accessed through a dispatcher:

C-c /
This prompts for an extra key to select a sparse-tree creating command.
C-c / r
Occur. Prompts for a regexp and shows a sparse tree with all matches. If the match is in a headline, the headline is made visible. If the match is in the body of an entry, headline and body are made visible. In order to provide minimal context, also the full hierarchy of headlines above the match is shown, as well as the headline following the match. Each match is also highlighted; the highlights disappear when the buffer is changed by an editing command8, or by pressing C-c C-c. When called with a C-u prefix argument, previous highlights are kept, so several calls to this command can be stacked.

For frequently used sparse trees of specific search strings, you can use the variable org-agenda-custom-commands to define fast keyboard access to specific sparse trees. These commands will then be accessible through the agenda dispatcher (see Agenda dispatcher). For example:

     (setq org-agenda-custom-commands
           '(("f" occur-tree "FIXME")))

will define the key C-c a f as a shortcut for creating a sparse tree matching the string `FIXME'.

The other sparse tree commands select headings based on TODO keywords, tags, or properties and will be discussed later in this manual.

To print a sparse tree, you can use the Emacs command ps-print-buffer-with-faces which does not print invisible parts of the document 9. Or you can use the command C-c C-e v to export only the visible part of the document and print the resulting file.


Next: , Previous: Sparse trees, Up: Document Structure

2.8 Plain lists

Within an entry of the outline tree, hand-formatted lists can provide additional structure. They also provide a way to create lists of checkboxes (see Checkboxes). Org supports editing such lists, and the HTML exporter (see Exporting) parses and formats them.

Org knows ordered lists, unordered lists, and description lists.

Items belonging to the same list must have the same indentation on the first line. In particular, if an ordered list reaches number `10.', then the 2–digit numbers must be written left-aligned with the other numbers in the list. Indentation also determines the end of a list item. It ends before the next line that is indented like the bullet/number, or less. Empty lines are part of the previous item, so you can have several paragraphs in one item. If you would like an empty line to terminate all currently open plain lists, configure the variable org-empty-line-terminates-plain-lists. Here is an example:

     ** Lord of the Rings
        My favorite scenes are (in this order)
        1. The attack of the Rohirrim
        2. Eowyns fight with the witch king
           + this was already my favorite scene in the book
           + I really like Miranda Otto.
        3. Peter Jackson being shot by Legolas
            - on DVD only
           He makes a really funny face when it happens.
        But in the end, not individual scenes matter but the film as a whole.
        Important actors in this film are:
        - Elijah Wood :: He plays the Frodo
        - Sean Austin :: He plays the Sam, Frodos friend.  I still remember
          him very well from his role as Mikey Walsh a in the Goonies.

Org supports these lists by tuning filling and wrapping commands to deal with them correctly11, and by exporting them properly (see Exporting).

The following commands act on items when the cursor is in the first line of an item (the line with the bullet or number).

<TAB>
Items can be folded just like headline levels if you set the variable org-cycle-include-plain-lists. The level of an item is then given by the indentation of the bullet/number. Items are always subordinate to real headlines, however; the hierarchies remain completely separated.

If org-cycle-include-plain-lists has not been set, <TAB> fixes the indentation of the current line in a heuristic way.

M-<RET>
Insert new item at current level. With a prefix argument, force a new heading (see Structure editing). If this command is used in the middle of a line, the line is split and the rest of the line becomes the new item12. If this command is executed in the whitespace before a bullet or number, the new item is created before the current item. If the command is executed in the white space before the text that is part of an item but does not contain the bullet, a bullet is added to the current line.
M-S-<RET>
Insert a new item with a checkbox (see Checkboxes).
S-<up>
S-<down>
Jump to the previous/next item in the current list.
M-S-<up>
M-S-<down>
Move the item including subitems up/down (swap with previous/next item of same indentation). If the list is ordered, renumbering is automatic.
M-S-<left>
M-S-<right>
Decrease/increase the indentation of the item, including subitems. Initially, the item tree is selected based on current indentation. When these commands are executed several times in direct succession, the initially selected region is used, even if the new indentation would imply a different hierarchy. To use the new hierarchy, break the command chain with a cursor motion or so.
C-c C-c
If there is a checkbox (see Checkboxes) in the item line, toggle the state of the checkbox. If not, this command makes sure that all the items on this list level use the same bullet. Furthermore, if this is an ordered list, make sure the numbering is OK.
C-c -
Cycle the entire list level through the different itemize/enumerate bullets (`-', `+', `*', `1.', `1)'). With a numeric prefix argument N, select the Nth bullet from this list. If there is an active region when calling this, all lines will be converted to list items. If the first line already was a list item, any item markers will be removed from the list. Finally, even without an active region, a normal line will be converted into a list item.


Next: , Previous: Plain lists, Up: Document Structure

2.9 Drawers

Sometimes you want to keep information associated with an entry, but you normally don't want to see it. For this, Org mode has drawers. Drawers need to be configured with the variable org-drawers13. Drawers look like this:

     ** This is a headline
        Still outside the drawer
        :DRAWERNAME:
           This is inside the drawer.
        :END:
        After the drawer.

Visibility cycling (see Visibility cycling) on the headline will hide and show the entry, but keep the drawer collapsed to a single line. In order to look inside the drawer, you need to move the cursor to the drawer line and press <TAB> there. Org mode uses a drawer for storing properties (see Properties and Columns), and another one for storing clock times (see Clocking work time).


Previous: Drawers, Up: Document Structure

2.10 The Orgstruct minor mode

If you like the intuitive way the Org mode structure editing and list formatting works, you might want to use these commands in other modes like Text mode or Mail mode as well. The minor mode Orgstruct mode makes this possible. You can always toggle the mode with M-x orgstruct-mode. To turn it on by default, for example in Mail mode, use

     (add-hook 'mail-mode-hook 'turn-on-orgstruct)

When this mode is active and the cursor is on a line that looks to Org like a headline of the first line of a list item, most structure editing commands will work, even if the same keys normally have different functionality in the major mode you are using. If the cursor is not in one of those special lines, Orgstruct mode lurks silently in the shadow.


Next: , Previous: Document Structure, Up: Top

3 Tables

Org comes with a fast and intuitive table editor. Spreadsheet-like calculations are supported in connection with the Emacs calc package (see the Emacs Calculator manual for more information about the Emacs calculator).


Next: , Previous: Tables, Up: Tables

3.1 The built-in table editor

Org makes it easy to format tables in plain ASCII. Any line with `|' as the first non-whitespace character is considered part of a table. `|' is also the column separator. A table might look like this:

     | Name  | Phone | Age |
     |-------+-------+-----|
     | Peter |  1234 |  17 |
     | Anna  |  4321 |  25 |

A table is re-aligned automatically each time you press <TAB> or <RET> or C-c C-c inside the table. <TAB> also moves to the next field (<RET> to the next row) and creates new table rows at the end of the table or before horizontal lines. The indentation of the table is set by the first line. Any line starting with `|-' is considered as a horizontal separator line and will be expanded on the next re-align to span the whole table width. So, to create the above table, you would only type

     |Name|Phone|Age|
     |-

and then press <TAB> to align the table and start filling in fields.

When typing text into a field, Org treats <DEL>, <Backspace>, and all character keys in a special way, so that inserting and deleting avoids shifting other fields. Also, when typing immediately after the cursor was moved into a new field with <TAB>, S-<TAB> or <RET>, the field is automatically made blank. If this behavior is too unpredictable for you, configure the variables org-enable-table-editor and org-table-auto-blank-field.

Creation and conversion

C-c |
Convert the active region to table. If every line contains at least one TAB character, the function assumes that the material is tab separated. If every line contains a comma, comma-separated values (CSV) are assumed. If not, lines are split at whitespace into fields. You can use a prefix argument to force a specific separator: C-u forces CSV, C-u C-u forces TAB, and a numeric argument N indicates that at least N consecutive spaces, or alternatively a TAB will be the separator.
If there is no active region, this command creates an empty Org table. But it's easier just to start typing, like |Name|Phone|Age <RET> |- <TAB>.
Re-aligning and field motion

C-c C-c
Re-align the table without moving the cursor.
<TAB>
Re-align the table, move to the next field. Creates a new row if necessary.
S-<TAB>
Re-align, move to previous field.
<RET>
Re-align the table and move down to next row. Creates a new row if necessary. At the beginning or end of a line, <RET> still does NEWLINE, so it can be used to split a table.
Column and row editing

M-<left>
M-<right>
Move the current column left/right.
M-S-<left>
Kill the current column.
M-S-<right>
Insert a new column to the left of the cursor position.
M-<up>
M-<down>
Move the current row up/down.
M-S-<up>
Kill the current row or horizontal line.
M-S-<down>
Insert a new row above the current row. With a prefix argument, the line is created below the current one.
C-c -
Insert a horizontal line below current row. With a prefix argument, the line is created above the current line.
C-c ^
Sort the table lines in the region. The position of point indicates the column to be used for sorting, and the range of lines is the range between the nearest horizontal separator lines, or the entire table. If point is before the first column, you will be prompted for the sorting column. If there is an active region, the mark specifies the first line and the sorting column, while point should be in the last line to be included into the sorting. The command prompts for the sorting type (alphabetically, numerically, or by time). When called with a prefix argument, alphabetic sorting will be case-sensitive.
Regions

C-c C-x M-w
Copy a rectangular region from a table to a special clipboard. Point and mark determine edge fields of the rectangle. The process ignores horizontal separator lines.
C-c C-x C-w
Copy a rectangular region from a table to a special clipboard, and blank all fields in the rectangle. So this is the “cut” operation.
C-c C-x C-y
Paste a rectangular region into a table. The upper left corner ends up in the current field. All involved fields will be overwritten. If the rectangle does not fit into the present table, the table is enlarged as needed. The process ignores horizontal separator lines.
C-c C-q
M-RET
Wrap several fields in a column like a paragraph. If there is an active region, and both point and mark are in the same column, the text in the column is wrapped to minimum width for the given number of lines. A numeric prefix argument may be used to change the number of desired lines. If there is no region, the current field is split at the cursor position and the text fragment to the right of the cursor is prepended to the field one line down. If there is no region, but you specify a prefix argument, the current field is made blank, and the content is appended to the field above.
Calculations

C-c +
Sum the numbers in the current column, or in the rectangle defined by the active region. The result is shown in the echo area and can be inserted with C-y.
S-<RET>
When current field is empty, copy from first non-empty field above. When not empty, copy current field down to next row and move cursor along with it. Depending on the variable org-table-copy-increment, integer field values will be incremented during copy. Integers that are too large will not be incremented. Also, a 0 prefix argument temporarily dispables the increment. This key is also used by CUA mode (see Cooperation).
Miscellaneous

C-c `
Edit the current field in a separate window. This is useful for fields that are not fully visible (see Narrow columns). When called with a C-u prefix, just make the full field visible, so that it can be edited in place.
M-x org-table-import
Import a file as a table. The table should be TAB- or whitespace separated. Useful, for example, to import a spreadsheet table or data from a database, because these programs generally can write TAB-separated text files. This command works by inserting the file into the buffer and then converting the region to a table. Any prefix argument is passed on to the converter, which uses it to determine the separator.
C-c |
Tables can also be imported by pasting tabular text into the Org buffer, selecting the pasted text with C-x C-x and then using the C-c | command (see above under Creation and conversion).
M-x org-table-export
Export the table, by default as a TAB-separated file. Useful for data exchange with, for example, spreadsheet or database programs. The format used to export the file can be configured in the variable org-table-export-default-format. You may also use properties TABLE_EXPORT_FILE and TABLE_EXPORT_FORMAT to specify the file name and the format for table export in a subtree. Org supports quite general formats for exported tables. The exporter format is the same as the format used by Orgtbl radio tables, see Translator functions for a detailed description.

If you don't like the automatic table editor because it gets in your way on lines which you would like to start with `|', you can turn it off with

     (setq org-enable-table-editor nil)

Then the only table command that still works is C-c C-c to do a manual re-align.


Next: , Previous: Built-in table editor, Up: Tables

3.2 Narrow columns

The width of columns is automatically determined by the table editor. Sometimes a single field or a few fields need to carry more text, leading to inconveniently wide columns. To limit14 the width of a column, one field anywhere in the column may contain just the string `<N>' where `N' is an integer specifying the width of the column in characters. The next re-align will then set the width of this column to no more than this value.

     |---+------------------------------|               |---+--------|
     |   |                              |               |   | <6>    |
     | 1 | one                          |               | 1 | one    |
     | 2 | two                          |     ----\     | 2 | two    |
     | 3 | This is a long chunk of text |     ----/     | 3 | This=> |
     | 4 | four                         |               | 4 | four   |
     |---+------------------------------|               |---+--------|

Fields that are wider become clipped and end in the string `=>'. Note that the full text is still in the buffer, it is only invisible. To see the full text, hold the mouse over the field - a tool-tip window will show the full content. To edit such a field, use the command C-c ` (that is C-c followed by the backquote). This will open a new window with the full field. Edit it and finish with C-c C-c.

When visiting a file containing a table with narrowed columns, the necessary character hiding has not yet happened, and the table needs to be aligned before it looks nice. Setting the option org-startup-align-all-tables will realign all tables in a file upon visiting, but also slow down startup. You can also set this option on a per-file basis with:

     #+STARTUP: align
     #+STARTUP: noalign


Next: , Previous: Narrow columns, Up: Tables

3.3 Column groups

When Org exports tables, it does so by default without vertical lines because that is visually more satisfying in general. Occasionally however, vertical lines can be useful to structure a table into groups of columns, much like horizontal lines can do for groups of rows. In order to specify column groups, you can use a special row where the first field contains only `/'. The further fields can either contain `<' to indicate that this column should start a group, `>' to indicate the end of a column, or `<>' to make a column a group of its own. Boundaries between column groups will upon export be marked with vertical lines. Here is an example:

     |   |  N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
     |---+----+-----+-----+-----+---------+------------|
     | / | <> |   < |     |   > |       < |          > |
     | # |  1 |   1 |   1 |   1 |       1 |          1 |
     | # |  2 |   4 |   8 |  16 |  1.4142 |     1.1892 |
     | # |  3 |   9 |  27 |  81 |  1.7321 |     1.3161 |
     |---+----+-----+-----+-----+---------+------------|
     #+TBLFM: $3=$2^2::$4=$2^3::$5=$2^4::$6=sqrt($2)::$7=sqrt(sqrt(($2)))

It is also sufficient to just insert the column group starters after every vertical line you'd like to have:

     |  N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
     |----+-----+-----+-----+---------+------------|
     | /  | <   |     |     | <       |            |


Next: , Previous: Column groups, Up: Tables

3.4 The Orgtbl minor mode

If you like the intuitive way the Org table editor works, you might also want to use it in other modes like Text mode or Mail mode. The minor mode Orgtbl mode makes this possible. You can always toggle the mode with M-x orgtbl-mode. To turn it on by default, for example in mail mode, use

     (add-hook 'mail-mode-hook 'turn-on-orgtbl)

Furthermore, with some special setup, it is possible to maintain tables in arbitrary syntax with Orgtbl mode. For example, it is possible to construct LaTeX tables with the underlying ease and power of Orgtbl mode, including spreadsheet capabilities. For details, see Tables in arbitrary syntax.


Next: , Previous: Orgtbl mode, Up: Tables

3.5 The spreadsheet

The table editor makes use of the Emacs calc package to implement spreadsheet-like capabilities. It can also evaluate Emacs Lisp forms to derive fields from other fields. While fully featured, Org's implementation is not identical to other spreadsheets. For example, Org knows the concept of a column formula that will be applied to all non-header fields in a column without having to copy the formula to each relevant field.


Next: , Previous: The spreadsheet, Up: The spreadsheet

3.5.1 References

To compute fields in the table from other fields, formulas must reference other fields or ranges. In Org, fields can be referenced by name, by absolute coordinates, and by relative coordinates. To find out what the coordinates of a field are, press C-c ? in that field, or press C-c } to toggle the display of a grid.

Field references

Formulas can reference the value of another field in two ways. Like in any other spreadsheet, you may reference fields with a letter/number combination like B3, meaning the 2nd field in the 3rd row.

Org also uses another, more general operator that looks like this:

     @row$column

Column references can be absolute like `1', `2',...`N', or relative to the current column like `+1' or `-2'.

The row specification only counts data lines and ignores horizontal separator lines (hlines). You can use absolute row numbers `1'...`N', and row numbers relative to the current row like `+3' or `-1'. Or specify the row relative to one of the hlines: `I' refers to the first hline15, `II' to the second etc. `-I' refers to the first such line above the current line, `+I' to the first such line below the current line. You can also write `III+2' which is the second data line after the third hline in the table. Relative row numbers like `-3' will not cross hlines if the current line is too close to the hline. Instead, the value directly at the hline is used.

`0' refers to the current row and column. Also, if you omit either the column or the row part of the reference, the current row/column is implied.

Org's references with unsigned numbers are fixed references in the sense that if you use the same reference in the formula for two different fields, the same field will be referenced each time. Org's references with signed numbers are floating references because the same reference operator can reference different fields depending on the field being calculated by the formula.

Here are a few examples:

     @2$3      2nd row, 3rd column
     C2        same as previous
     $5        column 5 in the current row
     E&        same as previous
     @2        current column, row 2
     @-1$-3    the field one row up, three columns to the left
     @-I$2     field just under hline above current row, column 2
Range references

You may reference a rectangular range of fields by specifying two field references connected by two dots `..'. If both fields are in the current row, you may simply use `$2..$7', but if at least one field is in a different row, you need to use the general @row$column format at least for the first field (i.e the reference must start with `@' in order to be interpreted correctly). Examples:

     $1..$3        First three fields in the current row.
     $P..$Q        Range, using column names (see under Advanced)
     @2$1..@4$3    6 fields between these two fields.
     A2..C4        Same as above.
     @-1$-2..@-1   3 numbers from the column to the left, 2 up to current row

Range references return a vector of values that can be fed into Calc vector functions. Empty fields in ranges are normally suppressed, so that the vector contains only the non-empty fields (but see the `E' mode switch below). If there are no non-empty fields, `[0]' is returned to avoid syntax errors in formulas.

Named references

`$name' is interpreted as the name of a column, parameter or constant. Constants are defined globally through the variable org-table-formula-constants, and locally (for the file) through a line like

     #+CONSTANTS: c=299792458. pi=3.14 eps=2.4e-6

Also properties (see Properties and Columns) can be used as constants in table formulas: For a property `:Xyz:' use the name `$PROP_Xyz', and the property will be searched in the current outline entry and in the hierarchy above it. If you have the constants.el package, it will also be used to resolve constants, including natural constants like `$h' for Planck's constant, and units like `$km' for kilometers16. Column names and parameters can be specified in special table lines. These are described below, see Advanced features. All names must start with a letter, and further consist of letters and numbers.


Next: , Previous: References, Up: The spreadsheet

3.5.2 Formula syntax for Calc

A formula can be any algebraic expression understood by the Emacs Calc package. Note that calc has the non-standard convention that `/' has lower precedence than `*', so that `a/b*c' is interpreted as `a/(b*c)'. Before evaluation by calc-eval (see calc-eval), variable substitution takes place according to the rules described above. The range vectors can be directly fed into the Calc vector functions like `vmean' and `vsum'.

A formula can contain an optional mode string after a semicolon. This string consists of flags to influence Calc and other modes during execution. By default, Org uses the standard Calc modes (precision 12, angular units degrees, fraction and symbolic modes off). The display format, however, has been changed to (float 5) to keep tables compact. The default settings can be configured using the variable org-calc-default-modes.

     p20           switch the internal precision to 20 digits
     n3 s3 e2 f4   normal, scientific, engineering, or fixed display format
     D R           angle modes: degrees, radians
     F S           fraction and symbolic modes
     N             interpret all fields as numbers, use 0 for non-numbers
     T             force text interpretation
     E             keep empty fields in ranges

In addition, you may provide a printf format specifier to reformat the final result. A few examples:

     $1+$2                Sum of first and second field
     $1+$2;%.2f           Same, format result to two decimals
     exp($2)+exp($1)      Math functions can be used
     $0;%.1f              Reformat current cell to 1 decimal
     ($3-32)*5/9          Degrees F -> C conversion
     $c/$1/$cm            Hz -> cm conversion, using constants.el
     tan($1);Dp3s1        Compute in degrees, precision 3, display SCI 1
     sin($1);Dp3%.1e      Same, but use printf specifier for display
     vmean($2..$7)        Compute column range mean, using vector function
     vmean($2..$7);EN     Same, but treat empty fields as 0
     taylor($3,x=7,2)     taylor series of $3, at x=7, second degree

Calc also contains a complete set of logical operations. For example

     if($1<20,teen,string(""))  ``teen'' if age $1 less than 20, else empty


Next: , Previous: Formula syntax for Calc, Up: The spreadsheet

3.5.3 Emacs Lisp forms as formulas

It is also possible to write a formula in Emacs Lisp; this can be useful for string manipulation and control structures, if the Calc's functionality is not enough. If a formula starts with a single quote followed by an opening parenthesis, then it is evaluated as a lisp form. The evaluation should return either a string or a number. Just as with calc formulas, you can specify modes and a printf format after a semicolon. With Emacs Lisp forms, you need to be conscious about the way field references are interpolated into the form. By default, a reference will be interpolated as a Lisp string (in double quotes) containing the field. If you provide the `N' mode switch, all referenced elements will be numbers (non-number fields will be zero) and interpolated as Lisp numbers, without quotes. If you provide the `L' flag, all fields will be interpolated literally, without quotes. I.e., if you want a reference to be interpreted as a string by the Lisp form, enclose the reference operator itself in double quotes, like "$3". Ranges are inserted as space-separated fields, so you can embed them in list or vector syntax. A few examples, note how the `N' mode is used when we do computations in lisp.

     Swap the first two characters of the content of column 1
       '(concat (substring $1 1 2) (substring $1 0 1) (substring $1 2))
     Add columns 1 and 2, equivalent to the Calc's $1+$2
       '(+ $1 $2);N
     Compute the sum of columns 1-4, like Calc's vsum($1..$4)
       '(apply '+ '($1..$4));N


Next: , Previous: Formula syntax for Lisp, Up: The spreadsheet

3.5.4 Field formulas

To assign a formula to a particular field, type it directly into the field, preceded by `:=', for example `:=$1+$2'. When you press <TAB> or <RET> or C-c C-c with the cursor still in the field, the formula will be stored as the formula for this field, evaluated, and the current field replaced with the result.

Formulas are stored in a special line starting with `#+TBLFM:' directly below the table. If you typed the equation in the 4th field of the 3rd data line in the table, the formula will look like `@3$4=$1+$2'. When inserting/deleting/swapping column and rows with the appropriate commands, absolute references (but not relative ones) in stored formulas are modified in order to still reference the same field. Of cause this is not true if you edit the table structure with normal editing commands - then you must fix the equations yourself.

Instead of typing an equation into the field, you may also use the following command

C-u C-c =
Install a new formula for the current field. The command prompts for a formula, with default taken from the `#+TBLFM:' line, applies it to the current field and stores it.


Next: , Previous: Field formulas, Up: The spreadsheet

3.5.5 Column formulas

Often in a table, the same formula should be used for all fields in a particular column. Instead of having to copy the formula to all fields in that column, Org allows to assign a single formula to an entire column. If the table contains horizontal separator hlines, everything before the first such line is considered part of the table header and will not be modified by column formulas.

To assign a formula to a column, type it directly into any field in the column, preceded by an equal sign, like `=$1+$2'. When you press <TAB> or <RET> or C-c C-c with the cursor still in the field, the formula will be stored as the formula for the current column, evaluated and the current field replaced with the result. If the field contains only `=', the previously stored formula for this column is used. For each column, Org will only remember the most recently used formula. In the `TBLFM:' line, column formulas will look like `$4=$1+$2'.

Instead of typing an equation into the field, you may also use the following command:

C-c =
Install a new formula for the current column and replace current field with the result of the formula. The command prompts for a formula, with default taken from the `#+TBLFM' line, applies it to the current field and stores it. With a numeric prefix argument(e.g. C-5 C-c =) the command will apply it to that many consecutive fields in the current column.


Next: , Previous: Column formulas, Up: The spreadsheet

3.5.6 Editing and debugging formulas

You can edit individual formulas in the minibuffer or directly in the field. Org can also prepare a special buffer with all active formulas of a table. When offering a formula for editing, Org converts references to the standard format (like B3 or D&) if possible. If you prefer to only work with the internal format (like @3$2 or $4), configure the variable org-table-use-standard-references.

C-c =
C-u C-c =
Edit the formula associated with the current column/field in the minibuffer. See Column formulas and Field formulas.
C-u C-u C-c =
Re-insert the active formula (either a field formula, or a column formula) into the current field, so that you can edit it directly in the field. The advantage over editing in the minibuffer is that you can use the command C-c ?.
C-c ?
While editing a formula in a table field, highlight the field(s) referenced by the reference at the cursor position in the formula.
C-c }
Toggle the display of row and column numbers for a table, using overlays. These are updated each time the table is aligned, you can force it with C-c C-c.
C-c {
Toggle the formula debugger on and off. See below.
C-c '
Edit all formulas for the current table in a special buffer, where the formulas will be displayed one per line. If the current field has an active formula, the cursor in the formula editor will mark it. While inside the special buffer, Org will automatically highlight any field or range reference at the cursor position. You may edit, remove and add formulas, and use the following commands:
C-c C-c
C-x C-s
Exit the formula editor and store the modified formulas. With C-u prefix, also apply the new formulas to the entire table.
C-c C-q
Exit the formula editor without installing changes.
C-c C-r
Toggle all references in the formula editor between standard (like B3) and internal (like @3$2).
<TAB>
Pretty-print or indent lisp formula at point. When in a line containing a lisp formula, format the formula according to Emacs Lisp rules. Another <TAB> collapses the formula back again. In the open formula, <TAB> re-indents just like in Emacs lisp mode.
M-<TAB>
Complete Lisp symbols, just like in Emacs lisp mode.
S-<up>/<down>/<left>/<right>
Shift the reference at point. For example, if the reference is B3 and you press S-<right>, it will become C3. This also works for relative references, and for hline references.
M-S-<up>/<down>
Move the test line for column formulas in the Org buffer up and down.
M-<up>/<down>
Scroll the window displaying the table.
C-c }
Turn the coordinate grid in the table on and off.

Making a table field blank does not remove the formula associated with the field, because that is stored in a different line (the `TBLFM' line) - during the next recalculation the field will be filled again. To remove a formula from a field, you have to give an empty reply when prompted for the formula, or to edit the `#+TBLFM' line.

You may edit the `#+TBLFM' directly and re-apply the changed equations with C-c C-c in that line, or with the normal recalculation commands in the table.

Debugging formulas

When the evaluation of a formula leads to an error, the field content becomes the string `#ERROR'. If you would like see what is going on during variable substitution and calculation in order to find a bug, turn on formula debugging in the Tbl menu and repeat the calculation, for example by pressing C-u C-u C-c = <RET> in a field. Detailed information will be displayed.


Next: , Previous: Editing and debugging formulas, Up: The spreadsheet

3.5.7 Updating the table

Recalculation of a table is normally not automatic, but needs to be triggered by a command. See Advanced features for a way to make recalculation at least semi-automatically.

In order to recalculate a line of a table or the entire table, use the following commands:

C-c *
Recalculate the current row by first applying the stored column formulas from left to right, and all field formulas in the current row.
C-u C-c *
C-u C-c C-c
Recompute the entire table, line by line. Any lines before the first hline are left alone, assuming that these are part