org.texi 333 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1 2
\input texinfo
@c %**start of header
3
@setfilename ../../info/org
Glenn Morris's avatar
Glenn Morris committed
4 5
@settitle Org Mode Manual

6 7
@set VERSION 5.19
@set DATE January 2008
Glenn Morris's avatar
Glenn Morris committed
8 9 10 11 12 13 14

@dircategory Emacs
@direntry
* Org Mode: (org).      Outline-based notes management and organizer
@end direntry

@c Version and Contact Info
15
@set MAINTAINERSITE @uref{http://orgmode.org,maintainers webpage}
Glenn Morris's avatar
Glenn Morris committed
16 17
@set AUTHOR Carsten Dominik
@set MAINTAINER Carsten Dominik
18 19
@set MAINTAINEREMAIL @email{carsten at orgmode dot org}
@set MAINTAINERCONTACT @uref{mailto:carsten at orgmode dot org,contact the maintainer}
Glenn Morris's avatar
Glenn Morris committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
@c %**end of header
@finalout

@c Macro definitions

@c Subheadings inside a table.
@macro tsubheading{text}
@ifinfo
@subsubheading \text\
@end ifinfo
@ifnotinfo
@item @b{\text\}
@end ifnotinfo
@end macro

@copying
This manual is for Org-mode (version @value{VERSION}).

38
Copyright @copyright{} 2004, 2005, 2006, 2007, 2008 Free Software Foundation
Glenn Morris's avatar
Glenn Morris committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 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 freedom to copy and modify
this GNU Manual, like GNU software.  Copies published by the Free
Software Foundation raise funds for GNU development.''
@end quotation
@end copying

@titlepage
@title Org Mode Manual

@subtitle Release @value{VERSION}
@author by Carsten Dominik

@c The following two commands start the copyright page.
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@c Output the table of contents at the beginning.
@contents

@ifnottex
@node Top, Introduction, (dir), (dir)
@top Org Mode Manual

@insertcopying
@end ifnottex

@menu
* Introduction::                Getting started
* Document structure::          A tree works like your brain
* Tables::                      Pure magic for quick formatting
* Hyperlinks::                  Notes in context
* TODO items::                  Every tree branch can be a TODO item
* Tags::                        Tagging headlines and matching sets of tags
84 85 86
* Properties and columns::      Storing information about an entry
* Dates and times::             Making items useful for planning
* Remember::                    Quickly adding nodes to the outline tree
Glenn Morris's avatar
Glenn Morris committed
87 88 89 90 91 92 93
* Agenda views::                Collecting information into views
* Embedded LaTeX::              LaTeX fragments and formulas
* Exporting::                   Sharing and publishing of notes
* Publishing::                  Create a web site of linked Org-mode files
* Miscellaneous::               All the rest which did not fit elsewhere
* Extensions and Hacking::      It is possible to write add-on code
* History and Acknowledgments::  How Org-mode came into being 
94
* Main Index::                  
Glenn Morris's avatar
Glenn Morris committed
95 96 97 98 99 100 101 102 103 104 105
* Key Index::                   Key bindings and where they are described

@detailmenu
 --- The Detailed Node Listing ---

Introduction

* Summary::                     Brief summary of what Org-mode does
* Installation::                How to install a downloaded version of Org-mode
* Activation::                  How to activate Org-mode for certain buffers.
* Feedback::                    Bug reports, ideas, patches etc.
106
* Conventions::                 Type-setting conventions in the manual
Glenn Morris's avatar
Glenn Morris committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

Document Structure

* Outlines::                    Org-mode is based on outline-mode
* Headlines::                   How to typeset org-tree headlines
* Visibility cycling::          Show and hide, much simplified
* Motion::                      Jumping to other headlines
* Structure editing::           Changing sequence and level of headlines
* Archiving::                   Move done task trees to a different place
* Sparse trees::                Matches embedded in context
* Plain lists::                 Additional structure within an entry
* Drawers::                     Tucking stuff away
* orgstruct-mode::              Structure editing outside Org-mode

Archiving

* ARCHIVE tag::                 Marking a tree as inactive
* Moving subtrees::             Moving a tree to an archive file

Tables

* Built-in table editor::       Simple tables
* Narrow columns::              Stop wasting space in tables   
* Column groups::               Grouping to trigger vertical lines
* orgtbl-mode::                 The table editor as minor mode
* The spreadsheet::             The table editor has spreadsheet capabilities.

The spreadsheet

* References::                  How to refer to another field or range
* Formula syntax for Calc::     Using Calc to compute stuff
* Formula syntax for Lisp::     Writing formulas in Emacs Lisp
* Field formulas::              Formulas valid for a single field
* Column formulas::             Formulas valid for an entire column
* Editing and debugging formulas::  Fixing formulas
* Updating the table::          Recomputing all dependent fields
* Advanced features::           Field names, parameters and automatic recalc

Hyperlinks

* Link format::                 How links in Org-mode are formatted
* Internal links::              Links to other places in the current file
* External links::              URL-like links to the world
* Handling links::              Creating, inserting and following
* Using links outside Org-mode::  Linking from my C source code?
* Link abbreviations::          Shortcuts for writing complex links
* Search options::              Linking to a specific location
* Custom searches::             When the default search is not enough

Internal links

* Radio targets::               Make targets trigger links in plain text.

TODO items

* TODO basics::                 Marking and displaying TODO entries
* TODO extensions::             Workflow and assignments
164
* Progress logging::            Dates and notes for progress
Glenn Morris's avatar
Glenn Morris committed
165 166 167 168 169 170 171
* Priorities::                  Some things are more important than others
* Breaking down tasks::         Splitting a task into manageable pieces
* Checkboxes::                  Tick-off lists

Extended use of TODO keywords

* Workflow states::             From TODO to DONE in steps
172
* TODO types::                  I do this, Fred does the rest
Glenn Morris's avatar
Glenn Morris committed
173
* Multiple sets in one file::   Mixing it all, and still finding your way
174 175 176 177 178 179 180 181
* Fast access to TODO states::  Single letter selection of a state
* Per-file keywords::           Different files, different requirements
* Faces for TODO keywords::     Highlighting states

Progress Logging

* Closing items::               When was this entry marked DONE?
* Tracking TODO state changes::  When did the status change?
Glenn Morris's avatar
Glenn Morris committed
182 183 184 185 186 187 188 189 190 191 192 193

Tags

* Tag inheritance::             Tags use the tree structure of the outline
* Setting tags::                How to assign tags to a headline
* Tag searches::                Searching for combinations of tags

Properties and Columns

* Property syntax::             How properties are spelled out
* Special properties::          Access to other Org-mode features
* Property searches::           Matching property values
194
* Property inheritance::        Passing values down the tree
Glenn Morris's avatar
Glenn Morris committed
195 196 197 198 199 200 201
* Column view::                 Tabular viewing and editing
* Property API::                Properties for Lisp programmers

Column View

* Defining columns::            The COLUMNS format property
* Using column view::           How to create and use column view
202
* Capturing Column View::       A dynamic block for column view
Glenn Morris's avatar
Glenn Morris committed
203 204 205 206 207 208

Defining Columns

* Scope of column definitions::  Where defined, where valid?
* Column attributes::           Appearance and content of a column

209
Dates and Times
Glenn Morris's avatar
Glenn Morris committed
210 211 212 213

* Time stamps::                 Assigning a time to a tree entry
* Creating timestamps::         Commands which insert timestamps
* Deadlines and scheduling::    Planning your work
214
* Clocking work time::          
Glenn Morris's avatar
Glenn Morris committed
215 216 217 218 219 220 221 222 223 224 225

Creating timestamps

* The date/time prompt::        How org-mode helps you entering date and time
* Custom time format::          Making dates look differently

Deadlines and Scheduling

* Inserting deadline/schedule::  Planning items
* Repeated tasks::              Items that show up again and again

226
Remember
Glenn Morris's avatar
Glenn Morris committed
227

228 229 230 231
* Setting up remember::         Some code for .emacs to get things going
* Remember templates::          Define the outline of different note types
* Storing notes::               Directly get the note to where it belongs
* Refiling notes::              Moving a note or task to a project
Glenn Morris's avatar
Glenn Morris committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

Agenda Views

* Agenda files::                Files being searched for agenda information
* Agenda dispatcher::           Keyboard access to agenda views
* Built-in agenda views::       What is available out of the box?
* Presentation and sorting::    How agenda items are prepared for display
* Agenda commands::             Remote editing of org trees
* Custom agenda views::         Defining special searches and views

The built-in agenda views

* Weekly/Daily agenda::         The calendar page with current tasks
* Global TODO list::            All unfinished action items
* Matching tags and properties::  Structured information with fine-tuned search
* Timeline::                    Time-sorted view for single file
* Stuck projects::              Find projects you need to review

Presentation and sorting

* Categories::                  Not all tasks are equal
* Time-of-day specifications::  How the agenda knows the time
* Sorting of agenda items::     The order of things

Custom agenda views

* Storing searches::            Type once, use often
* Block agenda::                All the stuff you need in a single buffer
* Setting Options::             Changing the rules
* Exporting Agenda Views::      Writing agendas to files.
* Extracting Agenda Information for other programs::  

Embedded LaTeX

* Math symbols::                TeX macros for symbols and Greek letters
* Subscripts and Superscripts::  Simple syntax for raising/lowering text
* LaTeX fragments::             Complex formulas made easy
* Processing LaTeX fragments::  Previewing LaTeX processing
* CDLaTeX mode::                Speed up entering of formulas

Exporting

* ASCII export::                Exporting to plain ASCII
* HTML export::                 Exporting to HTML
* LaTeX export::                Exporting to LaTeX
* XOXO export::                 Exporting to XOXO
* iCalendar export::            Exporting in iCalendar format
* Text interpretation::         How the exporter looks at the file

HTML export

* HTML Export commands::        How to invoke LaTeX export
* Quoting HTML tags::           Using direct HTML in Org-mode
* Links::                       Transformation of links for HTML
* Images::                      How to include images
* CSS support::                 Changing the appearence of the output

LaTeX export

* LaTeX export commands::       How to invoke LaTeX export
* Quoting LaTeX code::          Incorporating literal LaTeX code
293
* Sectioning structure::        
Glenn Morris's avatar
Glenn Morris committed
294 295 296 297 298 299

Text interpretation by the exporter

* Comment lines::               Some lines will not be exported
* Initial text::                Text before the first headline
* Footnotes::                   Numbers like [1]
300
* Quoted examples::             Inserting quoted chnuks of text            
Glenn Morris's avatar
Glenn Morris committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
* Enhancing text::              Subscripts, symbols and more
* Export options::              How to influence the export settings

Publishing

* Configuration::               Defining projects
* Sample configuration::        Example projects
* Triggering publication::      Publication commands

Configuration

* Project alist::               The central configuration variable
* Sources and destinations::    From here to there
* Selecting files::             What files are part of the project?
* Publishing action::           Setting the function doing the publishing
* Publishing options::          Tweaking HTML export
* Publishing links::            Which links keep working after publishing?
* Project page index::          Publishing a list of project files

Sample configuration

* Simple example::              One-component publishing
* Complex example::             A multi-component publishing example

Miscellaneous

* Completion::                  M-TAB knows what you need
* Customization::               Adapting Org-mode to your taste
* In-buffer settings::          Overview of the #+KEYWORDS
* The very busy C-c C-c key::   When in doubt, press C-c C-c
* Clean view::                  Getting rid of leading stars in the outline
* TTY keys::                    Using Org-mode on a tty
* Interaction::                 Other Emacs packages
* Bugs::                        Things which do not work perfectly

Interaction with other packages

* Cooperation::                 Packages Org-mode cooperates with
* Conflicts::                   Packages that lead to conflicts

Extensions, Hooks and Hacking

* Extensions::                  Existing 3rd-part extensions
* Adding hyperlink types::      New custom link types
* Tables in arbitrary syntax::  Orgtbl for LaTeX and other programs
* Dynamic blocks::              Automatically filled blocks
* Special agenda views::        Customized views
* Using the property API::      Writing programs that use entry properties

350
Tables and Lists in arbitrary syntax
Glenn Morris's avatar
Glenn Morris committed
351 352 353 354

* Radio tables::                Sending and receiving
* A LaTeX example::             Step by step, almost a tutorial
* Translator functions::        Copy and modify
355
* Radio lists::                 Doing the same for lists.
Glenn Morris's avatar
Glenn Morris committed
356 357 358 359 360 361 362 363 364 365 366 367 368

@end detailmenu
@end menu

@node Introduction, Document structure, Top, Top
@chapter Introduction
@cindex introduction

@menu
* Summary::                     Brief summary of what Org-mode does
* Installation::                How to install a downloaded version of Org-mode
* Activation::                  How to activate Org-mode for certain buffers.
* Feedback::                    Bug reports, ideas, patches etc.
369
* Conventions::                 Type-setting conventions in the manual
Glenn Morris's avatar
Glenn Morris committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
@end menu

@node Summary, Installation, Introduction, Introduction
@section Summary
@cindex summary

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

Org-mode develops organizational tasks around NOTES files that contain
lists or information about projects as plain text.  Org-mode 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-mode 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-mode file can be exported as a
390
structured ASCII file, as HTML, or (TODO and agenda items only) as an
Glenn Morris's avatar
Glenn Morris committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
iCalendar file.  It can also serve as a publishing tool for a set of
linked webpages.

An important design aspect that distinguishes Org-mode 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-mode,
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-mode 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-mode is a toolbox and can be used in different ways, for
example as:

@example
@r{@bullet{} outline extension with visibility cycling and structure editing}
@r{@bullet{} ASCII system and table editor for taking structured notes}
@r{@bullet{} ASCII table editor with spreadsheet-like capabilities}
@r{@bullet{} TODO list editor}
@r{@bullet{} full agenda and planner with deadlines and work scheduling}
@r{@bullet{} environment to implement David Allen's GTD system}
@r{@bullet{} a basic database application}
417
@r{@bullet{} simple hypertext system, with HTML and LaTeX export}
Glenn Morris's avatar
Glenn Morris committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431
@r{@bullet{} publishing tool to create a set of interlinked webpages}
@end example

Org-mode'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 La@TeX{}.  The structure
editing and list creation capabilities can be used outside Org-mode with
the minor Orgstruct-mode.

@cindex FAQ
There is a website for Org-mode which provides links to the newest
version of Org-mode, as well as additional information, frequently asked
questions (FAQ), links to tutorials etc.  This page is located at
432
@uref{http://orgmode.org}.
Glenn Morris's avatar
Glenn Morris committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536

@page


@node Installation, Activation, Summary, Introduction
@section Installation
@cindex installation
@cindex XEmacs

@b{Important:} @i{If Org-mode is part of the Emacs distribution or an
XEmacs package, please skip this section and go directly to
@ref{Activation}.}

If you have downloaded Org-mode from the Web, you must take the
following steps to install it: Go into the Org-mode distribution
directory and edit the top section of the file @file{Makefile}.  You
must set the name of the Emacs binary (likely either @file{emacs} or
@file{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, create your own two directories for these files, enter them
into the Makefile, and make sure Emacs finds the Lisp files by adding
the following line to @file{.emacs}:

@example
(setq load-path (cons "~/path/to/lispdir" load-path))
@end example

@b{XEmacs users now need to install the file @file{noutline.el} from
the @file{xemacs} subdirectory of the Org-mode distribution.  Use the
command:}

@example
@b{make install-noutline}
@end example

@noindent Now byte-compile and install the Lisp files with the shell
commands:

@example
make
make install
@end example

@noindent If you want to install the info documentation, use this command:

@example
make install-info
@end example

@noindent Then add to @file{.emacs}:

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

@node Activation, Feedback, Installation, Introduction
@section Activation
@cindex activation
@cindex autoload
@cindex global keybindings
@cindex keybindings, global

@iftex
@b{Important:} @i{If you use copy-and-paste to copy lisp code from the
PDF documentation as viewed by Acrobat reader to your .emacs file, the
single quote character comes out incorrectly and the code will not work.
You need to fix the single quotes by hand, or copy from Info
documentation.}
@end iftex

Add the following lines to your @file{.emacs} file.  The last two lines
define @emph{global} keys for the commands @command{org-store-link} and
@command{org-agenda} - please choose suitable keys yourself.

@lisp
;; 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)
@end lisp

Furthermore, you must activate @code{font-lock-mode} in org-mode
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):
@lisp
(global-font-lock-mode 1)                     ; for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock)  ; org-mode buffers only
@end lisp

@cindex org-mode, turning on
With this setup, all files with extension @samp{.org} will be put
into Org-mode.  As an alternative, make the first line of a file look
like this:

@example
MY PROJECTS    -*- mode: org; -*-
@end example

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

537
@node Feedback, Conventions, Activation, Introduction
Glenn Morris's avatar
Glenn Morris committed
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
@section Feedback
@cindex feedback
@cindex bug reports
@cindex maintainer
@cindex author

If you find problems with Org-mode, or if you have questions, remarks,
or ideas about it, please contact the maintainer @value{MAINTAINER} at
@value{MAINTAINEREMAIL}.

For bug reports, please provide as much information as possible,
including the version information of Emacs (@kbd{C-h v emacs-version
@key{RET}}) and Org-mode (@kbd{C-h v org-version @key{RET}}), as well as
the Org-mode related setup in @file{.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:

@enumerate
@item What exactly did you do?
@item What did you expect to happen?
@item What happened instead?
@end enumerate
@noindent Thank you for helping to improve this mode.

@subsubheading How to create a useful backtrace

@cindex backtrace of an error
If working with Org-mode 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 @emph{Backtrace}.
This is information from the built-in debugger about where and how the
error occurred.  Here is how to produce a useful backtrace:

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

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
@node Conventions,  , Feedback, Introduction
@section Typesetting conventions used in this manual

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

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

Glenn Morris's avatar
Glenn Morris committed
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
@node Document structure, Tables, Introduction, Top
@chapter Document Structure
@cindex document structure
@cindex structure of document

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

@menu
* Outlines::                    Org-mode is based on outline-mode
* Headlines::                   How to typeset org-tree headlines
* Visibility cycling::          Show and hide, much simplified
* Motion::                      Jumping to other headlines
* Structure editing::           Changing sequence and level of headlines
* Archiving::                   Move done task trees to a different place
* Sparse trees::                Matches embedded in context
* Plain lists::                 Additional structure within an entry
* Drawers::                     Tucking stuff away
* orgstruct-mode::              Structure editing outside Org-mode
@end menu

@node Outlines, Headlines, Document structure, Document structure
@section Outlines
@cindex outlines
@cindex outline-mode

Org-mode 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-mode greatly simplifies the use of
outlines by compressing the entire show/hide functionality into a single
command @command{org-cycle}, which is bound to the @key{TAB} key.

@node Headlines, Visibility cycling, Outlines, Document structure
@section Headlines
@cindex headlines
@cindex outline tree

Headlines define the structure of an outline tree.  The headlines in
Org-mode start with one or more stars, on the left margin@footnote{See
the variable @code{org-special-ctrl-a/e} to configure special behavior
of @kbd{C-a} and @kbd{C-e} in headlines.}.  For example:

@example
* Top level headline
** Second level
*** 3rd level
    some text
*** 3rd level
    more text

* Another top level headline
@end example

@noindent Some people find the many stars too noisy and would prefer an
outline that has whitespace followed by a single star as headline
starters.  @ref{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 @code{org-cycle-separator-lines} to modify this behavior.

@node Visibility cycling, Motion, Headlines, Document structure
@section Visibility cycling
@cindex cycling, visibility
@cindex visibility cycling
@cindex trees, visibility
@cindex show hidden text
@cindex hide text

Outlines make it possible to hide parts of the text in the buffer.
Org-mode uses just two commands, bound to @key{TAB} and
@kbd{S-@key{TAB}} to change the visibility in the buffer.

@cindex subtree visibility states
@cindex subtree cycling
@cindex folded, subtree visibility state
@cindex children, subtree visibility state
@cindex subtree, subtree visibility state
@table @kbd
@kindex @key{TAB}
@item @key{TAB}
@emph{Subtree cycling}: Rotate current subtree among the states

@example
,-> FOLDED -> CHILDREN -> SUBTREE --.
'-----------------------------------'
@end example

The cursor must be on a headline for this to work@footnote{see, however,
the option @code{org-cycle-emulate-tab}.}.  When the cursor is at the
beginning of the buffer and the first line is not a headline, then
@key{TAB} actually runs global cycling (see below)@footnote{see the
option @code{org-cycle-global-at-bob}.}.  Also when called with a prefix
argument (@kbd{C-u @key{TAB}}), global cycling is invoked.

@cindex global visibility states
@cindex global cycling
@cindex overview, global visibility state
@cindex contents, global visibility state
@cindex show all, global visibility state
@kindex S-@key{TAB}
@item S-@key{TAB}
@itemx C-u @key{TAB}
@emph{Global cycling}: Rotate the entire buffer among the states

@example
,-> OVERVIEW -> CONTENTS -> SHOW ALL --.
'--------------------------------------'
@end example

When @kbd{S-@key{TAB}} is called with a numerical prefix N, the CONTENTS
view up to headlines of level N will be shown.
Note that inside tables, @kbd{S-@key{TAB}} jumps to the previous field.

@cindex show all, command
@kindex C-c C-a
@item C-c C-a
Show all.
@kindex C-c C-r
@item 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
742 743 744 745
that has been exposed by a sparse tree command (@pxref{Sparse trees}) or
an agenda command (@pxref{Agenda commands}).  With prefix arg show, on
each

Glenn Morris's avatar
Glenn Morris committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
level, all sibling headings.
@kindex C-c C-x b
@item C-c C-x b
Show the current subtree in an indirect buffer@footnote{The indirect
buffer
@ifinfo
(@pxref{Indirect Buffers,,,emacs,GNU Emacs Manual})
@end ifinfo
@ifnotinfo
(see the Emacs manual for more information about indirect buffers)
@end ifnotinfo
will contain the entire buffer, but will be narrowed to the current
tree.  Editing the indirect buffer will also change the original buffer,
but without affecting visibility in that buffer.}.  With numerical
prefix ARG, go up to this level and then take that tree.  If ARG is
negative, go up that many levels.  With @kbd{C-u} prefix, do not remove
the previously used indirect buffer.
@end table

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

@example
#+STARTUP: overview
#+STARTUP: content
#+STARTUP: showall
@end example

@node Motion, Structure editing, Visibility cycling, Document structure
@section Motion
@cindex motion, between headlines
@cindex jumping, to headlines
@cindex headline navigation
The following commands jump to other headlines in the buffer.

@table @kbd
@kindex C-c C-n
@item C-c C-n
Next heading.
@kindex C-c C-p
@item C-c C-p
Previous heading.
@kindex C-c C-f
@item C-c C-f
Next heading same level.
@kindex C-c C-b
@item C-c C-b
Previous heading same level.
@kindex C-c C-u
@item C-c C-u
Backward to higher level heading.
@kindex C-c C-j
@item 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:
@example
@key{TAB}         @r{Cycle visibility.}
@key{down} / @key{up}   @r{Next/previous visible headline.}
n / p        @r{Next/previous visible headline.}
f / b        @r{Next/previous headline same level.}
u            @r{One level up.}
0-9          @r{Digit argument.}
@key{RET}         @r{Select this location.}
@end example
@end table

@node Structure editing, Archiving, Motion, Document structure
@section Structure editing
@cindex structure editing
@cindex headline, promotion and demotion
@cindex promotion, of subtrees
@cindex demotion, of subtrees
@cindex subtree, cut and paste
@cindex pasting, of subtrees
@cindex cutting, of subtrees
@cindex copying, of subtrees
@cindex subtrees, cut and paste

@table @kbd
@kindex M-@key{RET}
@item M-@key{RET}
Insert new heading with same level as current.  If the cursor is in a
plain list item, a new item is created (@pxref{Plain lists}).  To force
creation of a new headline, use a prefix arg, or first press @key{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 headline.  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.
842 843 844 845
@kindex C-@key{RET}
@item C-@key{RET}
Insert a new heading after the current subtree, same level as the
current headline.  This command works from anywhere in the entry.
Glenn Morris's avatar
Glenn Morris committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
@kindex M-S-@key{RET}
@item M-S-@key{RET}
Insert new TODO entry with same level as current heading.
@kindex M-@key{left}
@item M-@key{left}
Promote current heading by one level.
@kindex M-@key{right}
@item M-@key{right}
Demote current heading by one level.
@kindex M-S-@key{left}
@item M-S-@key{left}
Promote the current subtree by one level.
@kindex M-S-@key{right}
@item M-S-@key{right}
Demote the current subtree by one level.
@kindex M-S-@key{up}
@item M-S-@key{up}
Move subtree up (swap with previous subtree of same
level).
@kindex M-S-@key{down}
@item M-S-@key{down}
Move subtree down (swap with next subtree of same level).
@kindex C-c C-x C-w
@kindex C-c C-x C-k
@item C-c C-x C-w
@itemx C-c C-x C-k
Kill subtree, i.e. remove it from buffer but save in kill ring.
873
With prefix arg, kill N sequential subtrees.
Glenn Morris's avatar
Glenn Morris committed
874 875
@kindex C-c C-x M-w
@item C-c C-x M-w
876
Copy subtree to kill ring.  With prefix arg, copy N sequential subtrees.
Glenn Morris's avatar
Glenn Morris committed
877 878 879 880 881 882
@kindex C-c C-x C-y
@item 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 prefix arg, or by yanking after a
headline marker like @samp{****}.
883 884 885
@kindex C-c C-w
@item C-c C-w
Refile entry to a different location.  @xref{Refiling notes}.
Glenn Morris's avatar
Glenn Morris committed
886 887 888 889 890 891
@kindex C-c ^
@item 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
892 893
in each entry), by priority, and each of these in reverse order.  You
can also supply your own function to extract the sorting key.  With a
Glenn Morris's avatar
Glenn Morris committed
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
@kbd{C-u} prefix, sorting will be case-sensitive.  With two @kbd{C-u
C-u} prefixes, duplicate entries will also be removed.
@end table

@cindex region, active
@cindex active region
@cindex transient-mark-mode
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 (@pxref{Tables}), the Meta-Cursor keys have different
functionality.

@node Archiving, Sparse trees, Structure editing, Document structure
@section Archiving
@cindex 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.

@menu
* ARCHIVE tag::                 Marking a tree as inactive
* Moving subtrees::             Moving a tree to an archive file
@end menu

@node ARCHIVE tag, Moving subtrees, Archiving, Archiving
@subsection The ARCHIVE tag
@cindex internal archiving

A headline that is marked with the ARCHIVE tag (@pxref{Tags}) stays at
its location in the outline tree, but behaves in the following way:
@itemize @minus
@item
It does not open when you attempt to do so with a visibility cycling
command (@pxref{Visibility cycling}).  You can force cycling archived
subtrees with @kbd{C-@key{TAB}}, or by setting the option
@code{org-cycle-open-archived-trees}.  Also normal outline commands like
@code{show-all} will open archived subtrees.
@item
During sparse tree construction (@pxref{Sparse trees}), matches in
archived subtrees are not exposed, unless you configure the option
@code{org-sparse-tree-open-archived-trees}.
@item
During agenda view construction (@pxref{Agenda views}), the content of
archived trees is ignored unless you configure the option
@code{org-agenda-skip-archived-trees}.
@item
Archived trees are not exported (@pxref{Exporting}), only the headline
is.  Configure the details using the variable
@code{org-export-with-archived-trees}.
@end itemize

The following commands help managing the ARCHIVE tag:

@table @kbd
@kindex C-c C-x C-a
@item C-c C-x C-a
Toggle the ARCHIVE tag for the current headline.  When the tag is set,
the headline changes to a shadowish face, and the subtree below it is
hidden.
@kindex C-u C-c C-x C-a
@item C-u C-c C-x C-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 @emph{not} on a headline when this command is invoked, the
level 1 trees will be checked.
@kindex C-@kbd{TAB}
@item C-@kbd{TAB}
Cycle a tree even if it is tagged with ARCHIVE.
@end table

@node Moving subtrees,  , ARCHIVE tag, Archiving
@subsection Moving subtrees
@cindex external archiving

Once an entire project is finished, you may want to move it to a
different location, either in the current file, or even in a different
file, the archive file.

@table @kbd
@kindex C-c C-x C-s
@item C-c C-x C-s
Archive the subtree starting at the cursor position to the location
given by @code{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.
@kindex C-u C-c C-x C-s
@item 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 @emph{not} on a headline when this command
is invoked, the level 1 trees will be checked.
@end table

@cindex archive locations
The default archive location is a file in the same directory as the
current file, with the name derived by appending @file{_archive} to the
current file name.  For information and examples on how to change this,
see the documentation string of the variable
@code{org-archive-location}.  There is also an in-buffer option for
1001 1002 1003 1004 1005 1006 1007
setting this variable, for example@footnote{For backward compatibility,
the following also works: If there are several such lines in a file,
each specifies the archive location for the text below it.  The first
such line also applies to any text before its definition.  However,
using this method is @emph{strongly} deprecated as it is incompatible
with the outline structure of the document.  The correct method for
setting multiple archive locations in a buffer is using a property.}:
Glenn Morris's avatar
Glenn Morris committed
1008 1009 1010 1011 1012 1013

@example
#+ARCHIVE: %s_done::
@end example

@noindent
1014 1015 1016
If you would like to have a special ARCHIVE location for a single entry
or a (sub)tree, give the entry an @code{:ARCHIVE:} property with the
location as the value (@pxref{Properties and columns}).
Glenn Morris's avatar
Glenn Morris committed
1017 1018 1019 1020 1021 1022 1023 1024 1025

@node Sparse trees, Plain lists, Archiving, Document structure
@section Sparse trees
@cindex sparse trees
@cindex trees, sparse
@cindex folding, sparse trees
@cindex occur, command

An important feature of Org-mode is the ability to construct
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
@emph{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
it@footnote{See also the variables @code{org-show-hierarchy-above},
@code{org-show-following-heading}, and @code{org-show-siblings} for
detailed control on how much context is shown around each match.}.  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:
Glenn Morris's avatar
Glenn Morris committed
1036 1037 1038 1039

@table @kbd
@kindex C-c /
@item C-c /
1040 1041 1042
This prompts for an extra key to select a sparse-tree creating command.
@kindex C-c / r
@item C-c / r
Glenn Morris's avatar
Glenn Morris committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
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 command, or by pressing
@kbd{C-c C-c}.  When called with a @kbd{C-u} prefix argument, previous
highlights are kept, so several calls to this command can be stacked.
@end table
1053

Glenn Morris's avatar
Glenn Morris committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
@noindent
For frequently used sparse trees of specific search strings, you can
use the variable @code{org-agenda-custom-commands} to define fast
keyboard access to specific sparse trees.  These commands will then be
accessible through the agenda dispatcher (@pxref{Agenda dispatcher}).
For example:

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

@noindent will define the key @kbd{C-c a f} as a shortcut for creating
a sparse tree matching the string @samp{FIXME}.

1069 1070
The other sparse tree commands select headings based on TODO keywords,
tags, or properties and will be discussed later in this manual.
Glenn Morris's avatar
Glenn Morris committed
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091

@kindex C-c C-e v
@cindex printing sparse trees
@cindex visible text, printing
To print a sparse tree, you can use the Emacs command
@code{ps-print-buffer-with-faces} which does not print invisible parts
of the document @footnote{This does not work under XEmacs, because
XEmacs uses selective display for outlining, not text properties.}.
Or you can use the command @kbd{C-c C-e v} to export only the visible
part of the document and print the resulting file.

@node Plain lists, Drawers, Sparse trees, Document structure
@section Plain lists
@cindex plain lists
@cindex lists, plain
@cindex lists, ordered
@cindex ordered 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 (@pxref{Checkboxes}).  Org-mode supports editing such lists,
1092
and the HTML exporter (@pxref{Exporting}) parses and formats them.
Glenn Morris's avatar
Glenn Morris committed
1093 1094 1095 1096 1097 1098 1099

Org-mode knows ordered and unordered lists.  Unordered list items start
with @samp{-}, @samp{+}, or @samp{*}@footnote{When using @samp{*} as a
bullet, lines must be indented or they will be seen as top-level
headlines.  Also, when you are hiding leading stars to get a clean
outline view, plain list items starting with a star are visually
indistinguishable from true headlines.  In short: even though @samp{*}
1100 1101 1102
is supported, it may be better to not use it for plain list items.} as
bullets.  Ordered list items start with a numeral followed by either a
period or a right parenthesis, such as @samp{1.} or @samp{1)}.  Items
Glenn Morris's avatar
Glenn Morris committed
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
belonging to the same list must have the same indentation on the first
line.  In particular, if an ordered list reaches number @samp{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
@code{org-empty-line-terminates-plain-lists}.  Here is an example:

@example
@group
** 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.
@end group
@end example

Org-mode supports these lists by tuning filling and wrapping commands to
deal with them correctly@footnote{Org-mode only changes the filling
settings for Emacs.  For XEmacs, you should use Kyle E. Jones'
@file{filladapt.el}.  To turn this on,  put into @file{.emacs}:
@code{(require 'filladapt)}}. 

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

@table @kbd
@kindex @key{TAB}
@item @key{TAB}
Items can be folded just like headline levels if you set the variable
@code{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 @code{org-cycle-include-plain-lists} has not been set, @key{TAB}
fixes the indentation of the curent line in a heuristic way.
@kindex M-@key{RET}
@item M-@key{RET}
Insert new item at current level.  With prefix arg, force a new heading
(@pxref{Structure editing}).  If this command is used in the middle of a
line, the line is @emph{split} and the rest of the line becomes the new
item.  If this command is executed in the @emph{whitespace before a bullet or
number}, the new item is created @emph{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.
@kindex M-S-@key{RET}
@item M-S-@key{RET}
Insert a new item with a checkbox (@pxref{Checkboxes}).
@kindex S-@key{up}
@kindex S-@key{down}
@item S-@key{up}
@itemx S-@key{down}
Jump to the previous/next item in the current list.
@kindex M-S-@key{up}
@kindex M-S-@key{down}
@item M-S-@key{up}
@itemx M-S-@key{down}
Move the item including subitems up/down (swap with previous/next item
of same indentation).  If the list is ordered, renumbering is
automatic.
@kindex M-S-@key{left}
@kindex M-S-@key{right}
@item M-S-@key{left}
@itemx M-S-@key{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.
@kindex C-c C-c
@item C-c C-c
If there is a checkbox (@pxref{Checkboxes}) in the item line, toggle the
1186 1187 1188
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.
Glenn Morris's avatar
Glenn Morris committed
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
@kindex C-c -
@item C-c -
Cycle the entire list level through the different itemize/enumerate
bullets (@samp{-}, @samp{+}, @samp{*}, @samp{1.}, @samp{1)}).
With prefix arg, select the nth bullet from this list.
@end table

@node Drawers, orgstruct-mode, Plain lists, Document structure
@section Drawers
@cindex drawers
@cindex visibility cycling, 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 @emph{drawers}.
1203 1204 1205
Drawers need to be configured with the variable
@code{org-drawers}@footnote{You can define drawers on a per-file basis
with a line like @code{#+DRAWERS: HIDDEN PROPERTIES STATE}}.  Drawers
Glenn Morris's avatar
Glenn Morris committed
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
look like this:

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

Visibility cycling (@pxref{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 @key{TAB} there.  Org-mode uses a drawer for
storing properties (@pxref{Properties and columns}).

@node orgstruct-mode,  , Drawers, Document structure
@section The Orgstruct minor mode
@cindex orgstruct-mode
@cindex minor mode for structure editing

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 @kbd{M-x
orgstruct-mode}.  To turn it on by default, for example in mail mode,
use

@lisp
(add-hook 'mail-mode-hook 'turn-on-orgstruct)
@end lisp

When this mode is active and the cursor is on a line that looks to
Org-mode 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.

@node Tables, Hyperlinks, Document structure, Top
@chapter Tables
@cindex tables
@cindex editing tables

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
Org-mode comes with a fast and intuitive table editor.  Spreadsheet-like
calculations are supported in connection with the Emacs @file{calc}
package 
@ifinfo
(@pxref{Calc,,,calc,Gnu Emacs Calculator Manual}).
@end ifinfo
@ifnotinfo
(see the Emacs Calculator manual for more information about the Emacs
calculator).
@end ifnotinfo
Glenn Morris's avatar
Glenn Morris committed
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317

@menu
* Built-in table editor::       Simple tables
* Narrow columns::              Stop wasting space in tables   
* Column groups::               Grouping to trigger vertical lines
* orgtbl-mode::                 The table editor as minor mode
* The spreadsheet::             The table editor has spreadsheet capabilities.
@end menu

@node Built-in table editor, Narrow columns, Tables, Tables
@section The built-in table editor
@cindex table editor, built-in

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

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

A table is re-aligned automatically each time you press @key{TAB} or
@key{RET} or @kbd{C-c C-c} inside the table.  @key{TAB} also moves to
the next field (@key{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
@samp{|-} 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

@example
|Name|Phone|Age|
|-
@end example

@noindent and then press @key{TAB} to align the table and start filling in
fields.

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

@table @kbd
@tsubheading{Creation and conversion}
@kindex C-c |
@item 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.
1318
If every line contains a comma, comma-separated values (CSV) are assumed.
Glenn Morris's avatar
Glenn Morris committed
1319
If not, lines are split at whitespace into fields.  You can use a prefix
1320 1321 1322 1323
argument to force a specific separator: @kbd{C-u} forces CSV, @kbd{C-u
C-u} forces TAB, and a numeric argument N indicates that at least N
consequtive spaces, or alternatively a TAB will be the separator.
@* 
Glenn Morris's avatar
Glenn Morris committed
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
If there is no active region, this command creates an empty Org-mode
table.  But it's easier just to start typing, like
@kbd{|Name|Phone|Age @key{RET} |- @key{TAB}}.

@tsubheading{Re-aligning and field motion}
@kindex C-c C-c
@item C-c C-c
Re-align the table without moving the cursor.
@c
@kindex @key{TAB}
@item @key{TAB}
Re-align the table, move to the next field.  Creates a new row if
necessary.
@c
@kindex S-@key{TAB}
@item S-@key{TAB}
Re-align, move to previous field.
@c
@kindex @key{RET}
@item @key{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, @key{RET} still does
NEWLINE, so it can be used to split a table.

@tsubheading{Column and row editing}
@kindex M-@key{left}
@kindex M-@key{right}
@item M-@key{left}
@itemx M-@key{right}
Move the current column left/right.
@c
@kindex M-S-@key{left}
@item M-S-@key{left}
Kill the current column.
@c
@kindex M-S-@key{right}
@item M-S-@key{right}
Insert a new column to the left of the cursor position.
@c
@kindex M-@key{up}
@kindex M-@key{down}
@item M-@key{up}
@itemx M-@key{down}
Move the current row up/down.
@c
@kindex M-S-@key{up}
@item M-S-@key{up}
Kill the current row or horizontal line.
@c
@kindex M-S-@key{down}
@item M-S-@key{down}
Insert a new row above (with arg: below) the current row.
@c
@kindex C-c -
@item C-c -
Insert a horizontal line below current row. With prefix arg, the line
is created above the current line.
@c
@kindex C-c ^
@item 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.

@tsubheading{Regions}
@kindex C-c C-x M-w
@item 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
@kindex C-c C-x C-w
@item 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
@kindex C-c C-x C-y
@item C-c C-x C-y
Paste a rectangular region into a table.
The upper right 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
@kindex C-c C-q
@item C-c C-q
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
prefix ARG 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 ARG, the
current field is made blank, and the content is appended to the field
above.

@tsubheading{Calculations}
@cindex formula, in tables
@cindex calculations, in tables
@cindex region, active
@cindex active region
@cindex transient-mark-mode
@kindex C-c +
@item 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 @kbd{C-y}.
@c
@kindex S-@key{RET}
@item S-@key{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
@code{org-table-copy-increment}, integer field values will be
incremented during copy.  This key is also used by CUA-mode
(@pxref{Cooperation}).

@tsubheading{Miscellaneous}
@kindex C-c `
@item C-c `
Edit the current field in a separate window.  This is useful for fields
that are not fully visible (@pxref{Narrow columns}).  When called with a
@kbd{C-u} prefix, just make the full field visible, so that it can be
edited in place.
@c
@item M-x org-table-import
Import a file as a table.  The table should be TAB- or whitespace
1457 1458 1459 1460 1461 1462
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.
Glenn Morris's avatar
Glenn Morris committed
1463 1464 1465 1466 1467 1468 1469
@item C-c |
Tables can also be imported by pasting tabular text into the org-mode
buffer, selecting the pasted text with @kbd{C-x C-x} and then using the
@kbd{C-c |} command (see above under @i{Creation and conversion}.
@c
@item M-x org-table-export
Export the table as a TAB-separated file.  Useful for data exchange with,
1470
for example, spreadsheet or database programs.
Glenn Morris's avatar
Glenn Morris committed
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
@end table

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

@lisp
(setq org-enable-table-editor nil)
@end lisp

@noindent Then the only table command that still works is
@kbd{C-c C-c} to do a manual re-align.

@node Narrow columns, Column groups, Built-in table editor, Tables
@section Narrow columns
@cindex narrow columns in tables

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 limit@footnote{This feature
does not work on XEmacs.} the width of a column, one field anywhere in
the column may contain just the string @samp{<N>} where @samp{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.

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

@noindent
Fields that are wider become clipped and end in the string @samp{=>}.
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
@kbd{C-c `} (that is @kbd{C-c} followed by the backquote).  This will
open a new window with the full field.  Edit it and finish with @kbd{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
@code{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:

@example
#+STARTUP: align
#+STARTUP: noalign
@end example

@node Column groups, orgtbl-mode, Narrow columns, Tables
@section Column groups
@cindex grouping columns in tables

When Org-mode 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 @samp{/}.  The further fields can either
contain @samp{<} to indicate that this column should start a group,
@samp{>} to indicate the end of a column, or @samp{<>} to make a column
a group of its own.  Boundaries between colum groups will upon export be
marked with vertical lines.  Here is an example:

@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))
@end example

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

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

@node orgtbl-mode, The spreadsheet, Column groups, Tables
@section The Orgtbl minor mode
@cindex orgtbl-mode
@cindex minor mode for tables

If you like the intuitive way the Org-mode 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 @kbd{M-x orgtbl-mode}.  To turn it on by default, for
example in mail mode, use

@lisp
(add-hook 'mail-mode-hook 'turn-on-orgtbl)
@end lisp

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

@node The spreadsheet,  , orgtbl-mode, Tables
@section The spreadsheet
@cindex calculations, in tables
@cindex spreadsheet capabilities
@cindex @file{calc} package

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

@menu
* References::                  How to refer to another field or range
* Formula syntax for Calc::     Using Calc to compute stuff
* Formula syntax for Lisp::     Writing formulas in Emacs Lisp
* Field formulas::              Formulas valid for a single field
* Column formulas::             Formulas valid for an entire column
* Editing and debugging formulas::  Fixing formulas
* Updating the table::          Recomputing all dependent fields
* Advanced features::           Field names, parameters and automatic recalc
@end menu

@node References, Formula syntax for Calc, The spreadsheet, The spreadsheet
@subsection References
@cindex references

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

@subsubheading Field references
@cindex field references
@cindex references, to fields

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 @code{B3}, meaning the 2nd field in the 3rd row.
@c Such references are always fixed to that field, they don't change
@c when you copy and paste a formula to a different field.  So
@c Org-mode's @code{B3} behaves like @code{$B$3} in other spreadsheets.

@noindent
Org-mode also uses another, more general operator that looks like this:
@example
@@row$column
@end example

@noindent
Column references can be absolute like @samp{1}, @samp{2},...@samp{N},
or relative to the current column like @samp{+1} or @samp{-2}.

The row specification only counts data lines and ignores horizontal
separator lines (hlines).  You can use absolute row numbers
@samp{1}...@samp{N}, and row numbers relative to the current row like
@samp{+3} or @samp{-1}.  Or specify the row relative to one of the
1646 1647 1648 1649 1650 1651 1652 1653 1654
hlines: @samp{I} refers to the first hline@footnote{Note that only
hlines are counted that @emph{separate} table lines.  If the table
starts with a hline above the header, it does not count.}, @samp{II} to
the second etc.  @samp{-I} refers to the first such line above the
current line, @samp{+I} to the first such line below the current line.
You can also write @samp{III+2} which is the second data line after the
third hline in the table.  Relative row numbers like @samp{-3} will not
cross hlines if the current line is too close to the hline.  Instead,
the value directly at the hline is used.
Glenn Morris's avatar
Glenn Morris committed
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720

@samp{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-mode's references with @emph{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-mode's references with @emph{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:

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

@subsubheading Range references
@cindex range references
@cindex references, to ranges

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

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

@noindent 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 @samp{E} mode switch below).  If there are no non-empty fields,
@samp{[0]} is returned to avoid syntax errors in formulas.

@subsubheading Named references
@cindex named references
@cindex references, named
@cindex name, of column or field
@cindex constants, in calculations

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

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

@noindent
Also properties (@pxref{Properties and columns}) can be used as
1721 1722
constants in table formulas: For a property @samp{:Xyz:} use the name
@samp{$PROP_Xyz}, and the property will be searched in the current
Glenn Morris's avatar
Glenn Morris committed
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
outline entry and in the hierarchy above it.  If you have the
@file{constants.el} package, it will also be used to resolve constants,
including natural constants like @samp{$h} for Planck's constant, and
units like @samp{$km} for kilometers@footnote{@file{Constant.el} can
supply the values of constants in two different unit systems, @code{SI}
and @code{cgs}.  Which one is used depends on the value of the variable
@code{constants-unit-system}.  You can use the @code{#+STARTUP} options
@code{constSI} and @code{constcgs} to set this value for the current
buffer.}.  Column names and parameters can be specified in special table
lines.  These are described below, see @ref{Advanced features}.  All
names must start with a letter, and further consist of letters and
numbers.

@node Formula syntax for Calc, Formula syntax for Lisp, References, The spreadsheet
@subsection Formula syntax for Calc
@cindex formula syntax, Calc
@cindex syntax, of formulas

A formula can be any algebraic expression understood by the Emacs
@file{Calc} package.  @b{Note that @file{calc} has the
non-standard convention that @samp{/} has lower precedence than
@samp{*}, so that @samp{a/b*c} is interpreted as @samp{a/(b*c)}.}  Before
evaluation by @code{calc-eval} (@pxref{Calling Calc from
Your Programs,calc-eval,Calling calc from Your Lisp Programs,calc,GNU
Emacs Calc Manual}),
@c FIXME:  The link to the calc manual in HTML does not work.
variable substitution takes place according to the rules described above.
@cindex vectors, in table calculations
The range vectors can be directly fed into the calc vector functions
like @samp{vmean} and @samp{vsum}.

@cindex format specifier
@cindex mode, for @file{calc}
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-mode uses the standard calc modes (precision
12, angular units degrees, fraction and symbolic modes off.  The display
format, however, has been changed to @code{(float 5)} to keep tables
compact.  The default settings can be configured using the variable
@code{org-calc-default-modes}.

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

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

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

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

@example
if($1<20,teen,string(""))  @r{``teen'' if age $1 less than 20, else empty}
@end example

@node Formula syntax for Lisp, Field formulas, Formula syntax for Calc, The spreadsheet
@subsection Emacs Lisp forms as formulas
@cindex Lisp forms, as table 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
@file{calc} formulas, you can specify modes and a printf format after a
semicolon.  With Emacs Lisp forms, you need to be concious 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 @samp{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
@samp{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, enclode the reference operator itself in double quotes, like
@code{"$3"}.  Ranges are inserted as space-separated fields, so you can
embed them in list or vector syntax.  A few examples, note how the
@samp{N} mode is used when we do computations in lisp.

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

@node Field formulas, Column formulas, Formula syntax for Lisp, The spreadsheet
@subsection Field formulas
@cindex field formula
@cindex formula, for individual table field

To assign a formula to a particular field, type it directly into the
field, preceded by @samp{:=}, for example @samp{:=$1+$2}.  When you
press @key{TAB} or @key{RET} or @kbd{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 @samp{#+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
@samp{@@3$4=$1+$2}.  When inserting/deleting/swapping column and rows
with the appropriate commands, @i{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

@table @kbd
@kindex C-u C-c =
@item C-u C-c =
Install a new formula for the current field.  The command prompts for a
formula, with default taken from the @samp{#+TBLFM:} line, applies
it to the current field and stores it.
@end table

@node Column formulas, Editing and debugging formulas, Field formulas, The spreadsheet
@subsection Column formulas
@cindex column formula
@cindex formula, for table column

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-mode 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 @emph{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 @samp{=$1+$2}.  When you press
@key{TAB} or @key{RET} or @kbd{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 @samp{=}, the previously stored formula for this column is
used.  For each column, Org-mode will only remember the most recently
used formula.  In the @samp{TBLFM:} line, column formulas will look like
@samp{$4=$1+$2}.

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

@table @kbd
@kindex C-c =
@item 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 @samp{#+TBLFM} line, applies it to the current
field and stores it.  With a numerical prefix (e.g. @kbd{C-5 C-c =})
will apply it to that many consecutive fields in the current column.
@end table


@node Editing and debugging formulas, Updating the table, Column formulas, The spreadsheet
@subsection Editing and Debugging formulas
@cindex formula editing
@cindex editing, of table formulas

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

@table @kbd
@kindex C-c =
@kindex C-u C-c =
@item C-c =
@itemx C-u C-c =
Edit the formula associated with the current column/field in the
minibuffer.  See @ref{Column formulas} and @ref{Field formulas}.
@kindex C-u C-u C-c =
@item 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 @kbd{C-c ?}.
@kindex C-c ?
@item 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.
@kindex C-c @}
@item 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 @kbd{C-c C-c}.
@kindex C-c @{
@item C-c @{
Toggle the formula debugger on and off.  See below.
@kindex C-c '
@item 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-mode will automatically highlight
any field or range reference at the cursor position.  You may edit,
remove and add formulas, and use the following commands:
@table @kbd
@kindex C-c C-c
@kindex C-x C-s
@item C-c C-c
@itemx C-x C-s
Exit the formula editor and store the modified formulas.  With @kbd{C-u}
prefix, also apply the new formulas to the entire table.
@kindex C-c C-q
@item C-c C-q
Exit the formula editor without installing changes.
@kindex C-c C-r
@item C-c C-r
Toggle all references in the formula editor between standard (like
@code{B3}) and internal (like @code{@@3$2}).
@kindex @key{TAB}
@item @key{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 @key{TAB} collapses the formula back again.  In the open
formula, @key{TAB} re-indents just like in Emacs-lisp-mode.
@kindex M-@key{TAB}
@item M-@key{TAB}
Complete Lisp symbols, just like in Emacs-lisp-mode.
@kindex S-@key{up}
@kindex S-@key{down}
@kindex S-@key{left}
@kindex S-@key{right}
@item S-@key{up}/@key{down}/@key{left}/@key{right}
Shift the reference at point.  For example, if the reference is
@code{B3} and you press @kbd{S-@key{right}}, it will become @code{C3}.
This also works for relative references, and for hline references.
@kindex M-S-@key{up}
@kindex M-S-@key{down}
@item M-S-@key{up}/@key{down}
Move the test line for column formulas in the Org-mode buffer up and
down.
@kindex M-@key{up}
@kindex M-@key{down}
@item M-@key{up}/@key{down}
Scroll the window displaying the table.
@kindex C-c @}
@item C-c @}
Turn the coordinate grid in the table on and off.
@end table
@end table

Making a table field blank does not remove the formula associated with
the field, because that is stored in a different line (the @samp{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 @samp{#+TBLFM} line.

@kindex C-c C-c
You may edit the @samp{#+TBLFM} directly and re-apply the changed
equations with @kbd{C-c C-c} in that line, or with the normal
recalculation commands in the table.

@subsubheading Debugging formulas
@cindex formula debugging
@cindex debugging, of table formulas
When the evaluation of a formula leads to an error, the field content
becomes the string @samp{#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 @code{Tbl} menu and repeat the
calculation, for example by pressing @kbd{C-u C-u C-c = @key{RET}} in a
field.  Detailed information will be displayed.

@node Updating the table, Advanced features, Editing and debugging formulas, The spreadsheet
@subsection Updating the Table
@cindex recomputing table fields
@cindex updating, table

Recalculation of a table is normally not automatic, but needs to be
triggered by a command.  See @ref{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:

@table @kbd
@kindex C-c *
@item 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
@kindex C-u C-c *
@item C-u C-c *
@kindex C-u C-c C-c
@itemx 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 of the table header.
@c
@kindex C-u C-u C-c *
@kindex C-u C-u C-c C-c
@item C-u C-u C-c *
@itemx C-u C-u C-c C-c
Iterate the table by recomputing it until no further changes occur.
This may be necessary if some computed fields use the value of other
fields that are computed @i{later} in the calculation sequence.
@end table

@node Advanced features,  , Updating the table, The spreadsheet
@subsection Advanced features

If you want the recalculation of fields to happen automatically, or if
you want to be able to assign @i{names} to fields and columns, you need
to reserve the first column of the table for special marking characters.
@table @kbd
@kindex C-#
@item C-#
Rotate the calculation mark in first column through the states @samp{},
@samp{#}, @samp{*}, @samp{!}, @samp{$}.  The meaning of these characters
is discussed below.  When there is an active region, change all marks in
the region.
@end table

Here is an example of a table that collects exam results of students and
makes use of these features:

@example
@group
|---+---------+--------+--------+--------+-------+------|
|   | Student | Prob 1 | Prob 2 | Prob 3 | Total | Note |
|---+---------+--------+--------+--------+-------+------|
| ! |         |     P1 |     P2 |     P3 |   Tot |      |
| # | Maximum |     10 |     15 |     25 |    50 | 10.0 |
| ^ |         |     m1 |     m2 |     m3 |    mt |      |
|---+---------+--------+--------+--------+-------+------|
| # | Peter   |     10 |      8 |     23 |    41 |  8.2 |
| # | Sara    |      6 |     14 |     19 |    39 |  7.8 |
| # | Sam     |      2 |      4 |      3 |     9 |  1.8 |
|---+---------+--------+--------+--------+-------+------|
|   | Average |        |        |        |  29.7 |      |
| ^ |         |        |        |        |    at |      |
| $ | max=50  |        |        |        |       |      |
|---+---------+--------+--------+--------+-------+------|
#+TBLFM: $6=vsum($P1..$P3)::$7=10*$Tot/$max;%.1f::$at=vmean(@@-II..@@-I);%.1f
@end group
@end example

@noindent @b{Important}: Please note that for these special tables,
recalculating the table with @kbd{C-u C-c *} will only affect rows that
are marked @samp{#} or @samp{*}, and fields that have a formula assigned
to the field itself.  The column formulas are not applied in rows with
empty first field.

@cindex marking characters, tables
The marking characters have the following meaning:
@table @samp
@item !
The fields in this line define names for the columns, so that you may
refer to a column as @samp{$Tot} instead of @samp{$6}.
@item ^
This row defines names for the fields @emph{above} the row.  With such
a definition, any formula in the table may use @samp{$m1} to refer to
the value @samp{10}.  Also, if you assign a formula to a names field, it
will be stored as @samp{$name=...}.
@item _
Similar to @samp{^}, but defines names for the fields in the row
@emph{below}.
@item $
Fields in this row can define @emph{parameters} for formulas.  For
example, if a field in a @samp{$} row contains @samp{max=50}, then
formulas in this table can refer to the value 50 using @samp{$max}.
Parameters work exactly like constants, only that they can be defined on
a per-table basis.
@item #
Fields in this row are automatically recalculated when pressing
@key{TAB} or @key{RET} or @kbd{S-@key{TAB}} in this row.  Also, this row
is selected for a global recalculation with @kbd{C-u C-c *}.  Unmarked
lines will be left alone by this command.
@item *
Selects this line for global recalculation with @kbd{C-u C-c *}, but
not for automatic recalculation.  Use this when automatic
recalculation slows down editing too much.
@item
Unmarked lines are exempt from recalculation with @kbd{C-u C-c *}.
All lines that should be recalculated should be marked with @samp{#}
or @samp{*}.
@item /
Do not export this line.  Useful for lines that contain the narrowing
@samp{<N>} markers.
@end table

Finally, just to whet your appetite on what can be done with the
fantastic @file{calc} package, here is a table that computes the Taylor
series of degree @code{n} at location @code{x} for a couple of functions
(homework: try that with Excel :-)

@example
@group
|---+-------------+---+-----+--------------------------------------|
|   | Func        | n | x   | Result                               |
|---+-------------+---+-----+--------------------------------------|
| # | exp(x)      | 1 | x   | 1 + x                                |
| # | exp(x)      | 2 | x   | 1 + x + x^2 / 2                      |
| # | exp(x)      | 3 | x   | 1 + x + x^2 / 2 + x^3 / 6            |
| # | x^2+sqrt(x) | 2 | x=0 | x*(0.5 / 0) + x^2 (2 - 0.25 / 0) / 2 |
| # | x^2+sqrt(x) | 2 | x=1 | 2 + 2.5 x - 2.5 + 0.875 (x - 1)^2    |
| * | tan(x)      | 3 | x   | 0.0175 x + 1.77e-6 x^3               |
|---+-------------+---+-----+--------------------------------------|
#+TBLFM: $5=taylor($2,$4,$3);n3
@end group
@end example

@node Hyperlinks, TODO items, Tables, Top
@chapter Hyperlinks
@cindex hyperlinks

2152 2153
Like HTML, Org-mode provides links inside a file, external links to
other files, Usenet articles, emails, and much more.
Glenn Morris's avatar
Glenn Morris committed
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270