redetho logo

Zur deutschen Version.

Documentation about Org Mode

Unicorn

EMACS org-mode is immensely powerful. I use it primarily to write documentation, especially for software and hardware development.

While learning org-mode, I wrote below lines to capture items I felt were most relevant for me, like on a cheat sheet. This might be useful to other people who have similar requirements.

To Outline the Document

Headings

One or more asterisks (stars) plus a space.

Indent/Out-Dent

M-← or M-→

Whole sub-tree:

M-S-← or M-S-→

Change the bullet or enumeration type or style

S-← or S-→

This only works, when the cursor is located on the bullet character. If this is 1. or 1) then the cursor may be at the numeral or at the . or ).

For headings this will toggle to TODO or DONE. Only headings can be TODO items.

Move a whole tree up or down

M-↑ or M-↓

Aligning Text

The usual EMACS M-q only works correctly, when a bullet or enumeration is already properly indented.

Insert a Date

C-c ! inserts a date (more precisely: an "inactive date", that does not make it into the agenda)

On the other hand, C-c . inserts an "active date".

Insert Links

I often need to insert relative links. This can be achieved by customizing the variable org-link-file-path-type, i.e. you can put in init.el

'(org-link-file-path-type (quote relative))

Then C-u C-c C-l brings up the mini-buffer, where you can specify a relative path, e.g. by starting with ../ or ./ and using tab-completion to navigate the file system. Note that the out-right "Insert Link" command C-c C-l does not offer tab-completion.

Inserting Special Characters

I recommend to use UTF-8 encoding in files. This is not specific to org-mode, but applies to EMACS in general. But I list it here anyway:

Any Unicode character can be inserted using

C-x 8 RET code RET

For code you could supply a hexadecimal number or a name. The name can be completed using Tab. Caveat: there are many UTF-8/Unicode characters. Hence you might want to limit the search by providing some hints to the search.

Examples:

My Description Glyph Hexadec. Unicode Name
Simple, short, thin arrow to the left 2190 LEFTWARDS ARROW
Simple, short, thin arrow up 2191 UPWARDS ARROW
Simple, short, thin arrow to the right 2192 RIGHTWARDS ARROW
Simple, short, thin arrow down 2193 DOWNWARDS ARROW
Simple, short, thin arrow to the right and to the left 2194 LEFT RIGHT ARROW
Fixed space   00A0 NO-BREAK SPACE
Fixed minus 2011 NON-BREAKING HYPHEN
Soft hyphen ­ 00AD SOFT HYPHEN
Minus to match + 2212 MINUS SIGN
Plus-minus ± 00B1 PLUS-MINUS SIGN
Almost equal to 2248 ALMOST EQUAL TO
Dot operator 22C5 DOT OPERATOR
Times sign × 00D7 MULTIPLICATION SIGN
Less Or Equal 2264 LESS-THAN OR EQUAL TO
Greater or equal 2265 GREATER-THAN OR EQUAL TO
Micro µ 00B5 MICRO SIGN
Degree ° 00B0 DEGREE SIGN
EUR currency symbol 20AC EURO SIGN

I put Fixed Space, Fixed Minus and Soft Hyphen onto function keys (see my init.el), so that i can insert them quickly.

When working with UTF-8/Unicode characters, you can check what font EMACS is using to render a character on screen by typing C-u C-x = with the cursor on the character.

I noticed EMACS v25.1 slowing down considerably, when including specific symbols. On Windows 10, the fonts used by EMACS were for example "MS Gothic" and "Malgun Gothic", whereas I had set "Consolas" as the default font. In other words: If EMACS could find the glyph in Consolas, then there was no slow-down. If it needed to pick from those other fonts, things slowed down.

Under Windows, you might want to check which glyphs are available in a font using the "Character Map" utility.

On Linux, e.g. "Inconsolata" and "DejaVu Sans Mono" are alternatives to "Consolas".

Hard Line Break in a Table Cell

In an org-mode table cell, you can force a line break by writing

line1 @<br/> line2

but that will work only in HTML export.

Inserting Literal Text

Either using a ":" (colon) followed by a blank:

: Literal text

or using the following syntax

#+BEGIN_EXAMPLE -i
Literal text
#+END_EXAMPLE

The -i switch preserves indentation.

View

Hierarchy

TAB to fold/unfold

S-TAB to fold/unfold the whole hierarchy

Images

To toggle between viewing the images and viewing the links:

C-c C-x C-v (also works with CUA mode, as long as nothing is selected)

or

M-x org-toggle-inline-images

Export Tricks

To achieve an image as a clickable html link do

#+MACRO: imglnk @@html:<a href="$1"><img src="$2"/></a>@@

{{{imglnk(./Out.pdf,./Out-Sch_316x217.gif)}}}

Downside: the image does not show in EMACS.

Caveats

org-mode hogs keyboard shortcuts. E.g. C-TAB ‑ which I want to use to switch buffers ‑ I need to re-assign deliberately in my init.el.

My org-mode Settings (via EMACS Customize)

Compatibility with CUA-Mode

To have org-mode work with CUA-Mode, I set org‑replace‑disputed‑keys to TRUE (found this in the org-mode FAQ under "15.10.2 Packages that conflict with Org mode")

To use "Shift-Select" (which I use often) org‑support‑shift‑select has to be set.

Show Long Lines

I set org‑startup‑truncated to "off", to have long lines shown rather than only see an arrow at the end of a long line.

Show Images when Opening a File

Go to Org, Customize Group: Org Startup, Org Startup With Inline Images and set to non-nil. This writes

 '(org-startup-with-inline-images t)

to init.el

The same can be forced per file by putting

#+STARTUP: inlineimages

at the top in the file. See https://www.orgmode.org/manual/In_002dbuffer-settings.html

Simple To-Do List Set-up

As guidance used http://pragmaticemacs.com/emacs/org-mode-basics-vi-a-simple-todo-list/ and https://orgmode.org/worg/org-tutorials/orgtutorial_dto.html

To-do lists are headings marked TODO in ordinary org-mode files. Agendas are views onto such files generated by org-mode.

Setup

First I need to specify where org finds my to-do lists: the relavant variable is org-agenda-files. Its default is ".". Using EMACS' customise, I changed it to contain two files: ~/org/mytodo.org and ~/org/prj.org. The directory ~/org and the two files I had created before my self.

I choose two files, to learn how to split to-do items across multiple *.org files.

Test

Important commands:

How org-mode links open

You might want to determine, how links in org-mode files are opened, for example a link to the HOME directory:

[[~/.][Link to Home with no link type]]

Link to Home with no link type

[[file+emacs:~/.][Link to Home with link type file+emacs]]

Link to Home with link type file+emacs

Normally, mouse click or C-c C-o opens the link in Windows Explorer, if it is a directory. On MACOS it opens in Finder. Linux is unclear.

I want to open the link by default in dired, rather than a GUI file manager in Linux. Searching the Internet showed:

Below is from https://emacs.stackexchange.com/questions/10426/org-mode-link-to-open-directory-in-dired

There are (at least) two ways. First, typing C-u C-c C-o on a link should force it to be opened in EMACS, rather than in an external app. Second, you can permanently override the default behavior by adding an entry to the variable org-file-apps:

(add-to-list 'org-file-apps '(directory . emacs))

which tells org-mode to use dired for all directory links. Alternatively, you could use customize-variable to achieve the same.

The reason that the default behavior is different between OS X and Linux is that org-file-apps-default-macosx contains a fall-through entry (t . "open %s")

You can modify the link description as follows :

[[file+emacs:~/projects][Projects]]

It will open the link in Emacs with typing C-c C-o.

FYI: it works but when M-x org-lint it shows

Deprecated "file+emacs" link type.

org-version 9.2.6 – junnu Oct 10 '19 at 13:22

Interesting org-mode links

http://ehneilsen.net/notebook/orgExamples/org-examples.html


Last change: 2023-02-26
© 2002-2023 Dr. Thomas Redelberger redethogmx.de