GNU Emacs
Org
Markup for Rich Contents
Org 9.8.5 org

Markup for Rich Contents

Org is primarily about organizing and searching through your plain-text notes. However, it also provides a lightweight yet robust markup language for rich text formatting and more. For instance, you may want to center or emphasize text. Or you may need to insert a formula or image in your writing. Org offers syntax for all of this and more. Used in conjunction with the export framework (see Exporting), you can author beautiful documents in Org—like the fine manual you are currently reading.

Paragraphs

Paragraphs are separated by at least one empty line. If you need to enforce a line break within a paragraph, use \\ at the end of a line.

To preserve the line breaks, indentation and blank lines in a region, but otherwise use normal formatting, you can use this construct, which can also be used to format poetry.

#+BEGIN_VERSE
 Great clouds overhead
 Tiny black birds rise and fall
 Snow covers Emacs

    ---AlexSchroeder
#+END_VERSE

When quoting a passage from another document, it is customary to format this as a paragraph that is indented on both the left and the right margin. You can include quotations in Org documents like this:

#+BEGIN_QUOTE
Everything should be made as simple as possible,
but not any simpler ---Albert Einstein
#+END_QUOTE

If you would like to center some text, do it like this:

#+BEGIN_CENTER
Everything should be made as simple as possible, \\
but not any simpler
#+END_CENTER

Emphasis and Monospace

You can make words *bold*, /italic/, _underlined_, =verbatim= and ~code~, and, if you must, +strike-through+. Text in the code and verbatim string is not processed for Org specific syntax; it is exported verbatim. Org provides a single command as entry point for inserting the marker character.

C-c C-x C-f (org-emphasize)

Prompt for a marker character and insert or change an emphasis. If there is an active region, change that region to a new emphasis. If there is no region, just insert the marker characters and position the cursor between them.

To turn off fontification for marked up text, you can set org-fontify-emphasized-text to nil. To narrow down the list of the fontified markup syntax, you can customize ~org-emphasis-alist~(note: The markup will still be recognized. Just not highlighted visually in Emacs.).

To hide the emphasis markup characters in your buffers, set org-hide-emphasis-markers to t.

Sometimes, when marked text also contains the marker character itself, the result may be unsettling. For example,

/One may expect this whole sentence to be italicized, but the
following ~user/?variable~ contains =/= character, which effectively
stops emphasis there./

You can use zero width space to help Org sorting out the ambiguity. See Escape Character for more details.

Subscripts and Superscripts

^ and _ are used to indicate super- and subscripts. To increase the readability of ASCII text, it is not necessary, but OK, to surround multi-character sub- and superscripts with curly braces. For example

The radius of the sun is R_sun = 6.96 x 10^8 m.  On the other hand,
the radius of Alpha Centauri is R_{Alpha Centauri} = 1.28 x R_{sun}.

If you write a text where the underscore is often used in a different context, Org's convention to always interpret these as subscripts can get in your way. Configure the variable org-use-sub-superscripts and/or org-export-with-sub-superscripts to change this convention. For example, when setting these variables to {}, a_b is not displayed/exported(note: The underlying markup still remains a sub/superscript. Only the visual display and export behavior changes.) as a subscript, but a_{b} is.

You can set both org-use-sub-superscripts org-export-with-sub-superscripts in a file using the export option ^: (see Export Settings). For example, #+OPTIONS: ^:{} sets the two options to {} and limits super- and subscripts to the curly bracket notation.

You can also toggle the visual display of super- and subscripts:

C-c C-x \ (org-toggle-pretty-entities)

This command formats sub- and superscripts in a WYSIWYM way.

Set both org-pretty-entities and org-pretty-entities-include-sub-superscripts to t to start with super- and subscripts visually interpreted as specified by the option org-use-sub-superscripts.

Special Symbols

You can use LaTeX-like syntax to insert special symbols—named entities—like \alpha to indicate the Greek letter, or \to to indicate an arrow. Completion for these symbols is available, just type \ and maybe a few letters, and press M-TAB to see possible completions. If you need such a symbol inside a word, terminate it with a pair of curly brackets. For example

Pro tip: Given a circle \Gamma of diameter d, the length of its
circumference is \pi{}d.

A large number of entities is provided, with names taken from both HTML and LaTeX; you can comfortably browse the complete list from a dedicated buffer using the command org-entities-help. It is also possible to provide your own special symbols in the variable org-entities-user.

During export, these symbols are transformed into the native format of the exporter backend. Strings like \alpha are exported as α in the HTML output, and as \(\alpha\) in the LaTeX output. Similarly, \nbsp becomes   in HTML and ~ in LaTeX.

If you would like to see entities displayed as UTF-8 characters, use the following command(note: You can turn this on by default by setting the variable org-pretty-entities, or on a per-file basis with the STARTUP option entitiespretty.):

C-c C-x \ (org-toggle-pretty-entities)

Toggle display of entities as UTF-8 characters. This does not change the buffer content which remains plain ASCII, but it overlays the UTF-8 character for display purposes only.

In addition to regular entities defined above, Org exports in a special way(note: This behavior can be disabled with - export setting (see Export Settings).) the following commonly used character combinations: \- is treated as a shy hyphen, -- and --- are converted into dashes, and ... becomes a compact set of dots.

Embedded LaTeX

Plain ASCII is normally sufficient for almost all note-taking. Exceptions include scientific notes, which often require mathematical

symbols and the occasional formula. LaTeX37 is widely used to typeset scientific documents. Org mode supports embedding LaTeX code into its files, because many academics are used to writing and reading LaTeX source code, and because it can be readily processed to produce pretty output for a number of export backends.

LaTeX fragments

Org mode can contain LaTeX math fragments, and it supports ways to process these for several export backends. When exporting to LaTeX, the code is left as it is. When exporting to HTML, Org can use either MathJax (see Math formatting in HTML export) or transcode the math into images (see Previewing LaTeX fragments).

LaTeX fragments do not need any special marking at all. The following snippets are identified as LaTeX source code:

  • Environments of any kind38. The only requirement is that the \begin statement appears on a new line, preceded by only whitespace.
  • Text within the usual LaTeX math delimiters. Prefer \(...\) for inline fragments. The $...$ alternative has some restrictions and may be a source of confusion. To avoid conflicts with currency specifications, single $ characters are only recognized as math delimiters if the enclosed text contains at most two line breaks, is directly attached to the $ characters with no whitespace in between, and if the closing $ is followed by whitespace or punctuation (but not a dash). Sometimes, it may be necessary to have a literal dollar symbol even when it is recognized as LaTeX math delimiter. Org provides \dollar and \USD entities (see Special Symbols) that are rendered as $ for such scenarios. Also, see Escape Character.

For example:

\begin{equation}                        % arbitrary environments,
x=\sqrt{b}                              % even tables, figures, etc
\end{equation}

If $a^2=b$ and \( b=2 \), then the solution must be
either $$ a=+\sqrt{2} $$ or \[ a=-\sqrt{2} \].

LaTeX processing can be configured with the variable org-export-with-latex. The default setting is t which means MathJax for HTML, and no processing for ASCII and LaTeX backends. You can also set this variable on a per-file basis using one of these lines:

#+OPTIONS: tex:t Do the right thing automatically (MathJax)
#+OPTIONS: tex:nil Do not process LaTeX fragments at all
#+OPTIONS: tex:verbatim Verbatim export, for jsMath or so

Previewing LaTeX fragments

If you have a working LaTeX installation and dvipng, dvisvgm or

convert installed39, LaTeX fragments can be processed to produce images of the typeset expressions to be used for inclusion while exporting to HTML (see LaTeX fragments), or for inline previewing within Org mode.

You can customize the variables org-format-latex-options and org-format-latex-header to influence some aspects of the preview. In particular, the :scale (and for HTML export, :html-scale) property of the former can be used to adjust the size of the preview images.

C-c C-x C-l (org-latex-preview)

Produce a preview image of the LaTeX fragment at point and overlay it over the source code. If there is no fragment at point, process all fragments in the current entry—between two headlines.

When called with a single prefix argument, clear all images in the current entry. Two prefix arguments produce a preview image for all fragments in the buffer, while three of them clear all the images in that buffer.

You can turn on the previewing of all LaTeX fragments in a file with

#+STARTUP: latexpreview

To disable it, simply use

#+STARTUP: nolatexpreview

Using CDLaTeX to enter math

CDLaTeX mode is a minor mode that is normally used in combination with a major LaTeX mode like AUCTeX in order to speed-up insertion of environments and math templates. Inside Org mode, you can make use of some of the features of CDLaTeX mode. You need to install cdlatex.el and texmathp.el (the latter comes also with AUCTeX). The cdlatex package can be installed from NonGNU ELPA with the Emacs packaging system. Do not use CDLaTeX mode itself under Org mode, but use the special version Org CDLaTeX minor mode that comes as part of Org. Turn it on for the current buffer with M-x org-cdlatex-mode, or for all Org files with

(add-hook 'org-mode-hook #'turn-on-org-cdlatex)

When this mode is enabled, the following features are present (for more details see the documentation of CDLaTeX mode):

C-c {

Insert an environment template.

TAB

The TAB key expands the template if point is inside a LaTeX fragment(note: Org mode has a method to test if point is inside such a fragment, see the documentation of the function org-inside-LaTeX-fragment-p.). For example, TAB expands fr to \frac{}{} and position point correctly inside the first brace. Another TAB gets you into the second brace.

Even outside fragments, TAB expands environment abbreviations at the beginning of a line. For example, if you write equ at the beginning of a line and press TAB, this abbreviation is expanded to an equation environment. To get a list of all abbreviations, type M-x cdlatex-command-help.

^, _

Pressing _ and ^ inside a LaTeX fragment inserts these characters together with a pair of braces. If you use TAB to move out of the braces, and if the braces surround only a single character or macro, they are removed again (depending on the variable cdlatex-simplify-sub-super-scripts).

`

Pressing the backquote followed by a character inserts math macros, also outside LaTeX fragments. If you wait more than 1.5 seconds after the backquote, a help window pops up.

'

Pressing the single-quote followed by another character modifies the LaTeX symbol before point with an accent or a font. If you wait more than 1.5 seconds after the single-quote, a help window pops up. Character modification works only inside LaTeX fragments; outside the quote is normal.

Literal Examples

You can include literal examples that should not be subjected to markup. Such examples are typeset in monospace, so this is well suited for source code and similar examples.

#+BEGIN_EXAMPLE
  Some example from a text file.
#+END_EXAMPLE

There is one limitation, however. You must insert a comma right before lines starting with either *, ,*, #+ or ,#+, as those may be interpreted as outlines nodes or some other special syntax. Org transparently strips these additional commas whenever it accesses the contents of the block.

#+BEGIN_EXAMPLE
,* I am no real headline
#+END_EXAMPLE

For simplicity when using small examples, you can also start the example lines with a colon followed by a space. There may also be additional whitespace before the colon:

Here is an example
   : Some example from a text file.

If the example is source code from a programming language, or any other text that can be marked up by Font Lock in Emacs, you can ask

for the example to look like the fontified Emacs buffer40. This is done with the code block, where you also need to specify the name

of the major mode that should be used to fontify the example41, see Structure Templates for shortcuts to easily insert code blocks.

#+BEGIN_SRC emacs-lisp
  (defun org-xor (a b)
    "Exclusive or."
    (if a (not b) b))
#+END_SRC

Both in example and in src snippets, you can add a -n switch to the #+BEGIN line(note: In the src snippets, switches must be placed right after the language name and before the header arguments), to get the lines of the example numbered. The -n takes an optional numeric argument specifying the starting line number of the block. If you use a +n switch, the numbering from the previous numbered snippet is continued in the current one. The +n switch can also take a numeric argument. This adds the value of the argument to the last line of the previous block to determine the starting line number.

#+BEGIN_SRC emacs-lisp -n 20
  ;; This exports with line number 20.
  (message "This is line 21")
#+END_SRC

#+BEGIN_SRC emacs-lisp +n 10
  ;; This is listed as line 31.
  (message "This is line 32")
#+END_SRC

In literal examples, Org interprets strings like (ref:name) as labels, and use them as targets for special hyperlinks like [[#_0028name_0029][(name)]]—i.e., the reference name enclosed in single parentheses. In HTML, hovering the mouse over such a link remote-highlights the corresponding code line(note: This requires some JavaScript which is not automatically included in the HTML output: you have to customize the variable org-html-head-include-scripts to t to have it included (it is nil by default).), which is kind of cool.

You can also add a -r switch which removes the labels from the source code(note: Adding -k to -n -r keeps the labels in the source code while using line numbers for the links, which might be useful to explain those in an Org mode example code.). With the -n switch, links to these references are labeled by the line numbers from the code listing. Otherwise, links use the labels with no parentheses. Here is an example:

#+BEGIN_SRC emacs-lisp -n -r
  (save-excursion                 (ref:sc)
     (goto-char (point-min))      (ref:jump)
#+END_SRC
In line [[#_0028sc_0029][(sc)]] we remember the current position. [[#_0028jump_0029][Line (jump)]]
jumps to point-min.

Source code and examples may be indented in order to align nicely with the surrounding text, and in particular with plain list structure (see Plain Lists). By default, Org only retains the relative indentation between lines, e.g., when exporting the contents of the block. However, you can use the -i switch to also preserve the global indentation, if it does matter. See Editing Source Code.

If the syntax for the label format conflicts with the language syntax, use a -l switch to change the format, for example

#+BEGIN_SRC pascal -n -r -l "((%s))"

See also the variable org-coderef-label-format.

HTML export also allows examples to be published as text areas (see Text areas in HTML export).

Because the #+BEGIN#+END patterns need to be added so often, a shortcut is provided (see Structure Templates).

C-c ' (org-edit-special)

Edit the source code example at point in its native mode. This works by switching to a temporary buffer with the source code. You need to exit by pressing C-c ' again. The edited version then replaces the old version in the Org buffer. Fixed-width regions—where each line starts with a colon followed by a space—are edited using Artist mode(note: You may select a different mode with the variable org-edit-fixed-width-region-mode.) to allow creating ASCII drawings easily. Using this command in an empty line creates a new fixed-width region.

Calling org-store-link (see Handling Links) while editing a source code example in a temporary buffer created with C-c ' prompts for a label. Make sure that it is unique in the current buffer, and insert it with the proper formatting like (ref:label) at the end of the current line. Then the label is stored as a link (label), for retrieval with C-c C-l.

Captions

You can assign a caption to a specific part of a document by inserting a CAPTION keyword immediately before it:

#+CAPTION: This is the caption for the next table (or link)
| ... | ... |
|-----+-----|

Optionally, the caption can take the form:

#+CAPTION[Short caption]: Longer caption.

Even though images and tables are prominent examples of captioned structures, the same caption mechanism can apply to many others—e.g., LaTeX equations, source code blocks. Depending on the export backend, those may or may not be handled.

Horizontal Rules

A line consisting of only dashes, and at least 5 of them, is exported as a horizontal line.

Creating Footnotes

A footnote is started by a footnote marker in square brackets in column 0, no indentation allowed. It ends at the next footnote definition, headline, or after two consecutive empty lines. The footnote reference is simply the marker in square brackets, inside text. Markers always start with fn:. For example:

The Org website[fn:1] now looks a lot better than it used to.
...
[fn:50] The link is: https://orgmode.org

Org mode extends the number-based syntax to named footnotes and optional inline definition. Here are the valid references:

[fn:NAME]
A named footnote reference, where NAME is a unique label word, or, for simplicity of automatic creation, a number.
(note: This is the inline definition of this footnote)
An anonymous footnote where the definition is given directly at the reference point.
[fn:NAME: a definition]
An inline definition of a footnote, which also specifies a name for the note. Since Org allows multiple references to the same note, you can then use [fn:NAME] to create additional references.

Footnote labels can be created automatically, or you can create names yourself. This is handled by the variable org-footnote-auto-label and its corresponding STARTUP keywords. See the docstring of that variable for details.

The following command handles footnotes:

C-c C-x f
The footnote action command.

When point is on a footnote reference, jump to the definition. When it is at a definition, jump to the—first—reference.

Otherwise, create a new footnote. Depending on the variable ~org-footnote-define-inline~(note: The corresponding in-buffer setting is: #+STARTUP: fninline or #+STARTUP: nofninline.), the definition is placed right into the text as part of the reference, or separately into the location determined by the variable org-footnote-section.

When this command is called with a prefix argument, a menu of additional options is offered:

s Sort the footnote definitions by reference sequence.
r Renumber the simple fn:N footnotes.
S Short for first r, then s action.
n Rename all footnotes into a fn:1fn:n sequence.
d Delete the footnote at point, including definition and references.

Depending on the variable ~org-footnote-auto-adjust~(note: The corresponding in-buffer options are #+STARTUP: fnadjust and #+STARTUP: nofnadjust.), renumbering and sorting footnotes can be automatic after each insertion or deletion.

C-c C-c

If point is on a footnote reference, jump to the definition. If it is at the definition, jump back to the reference. When called at a footnote location with a prefix argument, offer the same menu as C-c C-x f.

C-c C-o or mouse-1/2

Footnote labels are also links to the corresponding definition or reference, and you can use the usual commands to follow these links.

Footnotes

  1. 37

    LaTeX is a macro system based on Donald E. Knuth's TeX system. Many of the features described here as "LaTeX" are really from TeX, but for simplicity I am blurring this distinction.

    Backrefs: 1

  2. 38

    When MathJax is used, only the environments recognized by MathJax are processed. When dvipng, dvisvgm, or ImageMagick suite is used to create images, any LaTeX environment is handled.

    Backrefs: 1

  3. 39

    These are respectively available at https://sourceforge.net/projects/dvipng/, http://dvisvgm.bplaced.net/ and from the ImageMagick suite. Choose the converter by setting the variable org-preview-latex-default-process accordingly.

    Backrefs: 1

  4. 40

    This works automatically for the HTML backend (it requires version 1.34 of the htmlize.el package, which you need to install). Fontified code chunks in LaTeX can be achieved using either the listings LaTeX package, minted LaTeX package, or by using engrave-faces. Refer to org-latex-src-block-backend for details.

    Backrefs: 1

  5. 41

    Source code in code blocks may also be evaluated either interactively or on export. See Working with Source Code for more information on evaluating code blocks.

    Backrefs: 1

Manual
Org Mode 9.8.5
Source Ref
release_9.8.5
Source
View upstream