This article describes how to configure Org mode to create a pleasant and distraction-free writing environment, aka. ricing Org mode.

Ricing Org Mode: A Beautiful Writing Environment

Peter Prevos

Peter Prevos |

1970 words | 10 minutes

Share this content

A plain text editor helps you focus on content over form. Having said this, the default Emacs experience can be harsh on the eyes. This article describes how to improve Emacs by ricing Org mode for a more pleasant writing experience.

Ricing is a term often used by hackers as the activity to make a system look nicer. The Urban Dictionary defines it as: "To rice, or to soup up a crappy car with the mistaken idea that […] performance yellow paint makes it go faster."

Emacs Writing Studio

Emacs Writing Studio

A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.

The source files of the book and EWS configuration are also freely available on GitHub.

Org mode as a Text Processor

The main difference between a text editor and a Word processor is that in Emacs, the design of the text (font, colour and so on) is based on meaning and not the writer's choice. The purpose of the buffer design is to help you navigate the document. This will not be the way it looks when you export the text. The articles about publishing articles and books and the article about creating websites show how to export buffers.

The default design of an Org mode buffer is a bit bland, shown in the image below. This article will show you how to step-by-step improve the look-and-feel. These improvements are not beautification for the sake of aesthetics. Removing leading stars, indentation, converting $\LaTeX$ and line spacing facilitates the writing process by giving your eyes focus on content instead of form.

Before ricing org mode
Before ricing Org mode.

All the configuration explained in this series of articles is available as an init file on GitHub.

Org mode Tweaks

Org mode needs some tweaks to remove clutter from the screen. We can change the etxt alignment, change the way fonts of rich text and special characters are displayed and preview images by default.

    ;; Improve org mode looks
    (setq-default org-startup-indented t
                  org-pretty-entities t
                  org-use-sub-superscripts "{}"
                  org-hide-emphasis-markers t
                  org-startup-with-inline-images t
                  org-image-actual-width '(300))

Indentation

Org mode aligns text to the left of the buffer and all the stars of headings are visible. You can also remove leading stars and align subheadings and text below its respective heading to create a more pleasant layout. To globally turn on Org Indent mode for all files, set the variable org-startup-indented to t, which removes the leading stars for a nice clean view.

 

Rich Text and Special Characters

The following three lines in the configuration instruct Org mode to display special characters and improve how we view rich text.

Pretty entities in Org mode relate to special symbols, such as superscript and subscript (x^{2} or x_{2}) and other LaTeX special characters, such as \pi, which display as x², x2 and π.

You can toggle this behaviour with the C-c C-x \ keystroke (org-toggle-pretty-entities). For more complex mathematical expressions, see below.

By default, Org mode does not require curly braces for sub- and superscripts. But this can cause confusion if you like to write something using snake_case. This configuration limits applying sub- and superscripts to characters between curly braces by setting the org-use-sub-superscripts variable to {}.

Org mode uses various markers to indicate rich text. Emacs will adapt the text display, but the markers remain visible, which adds to the clutter on your screen. You can remove these markers by setting the org-hide-emphasis-markers variable.

The only problem with hiding emphasis markers is that rich text becomes hard to edit because it is unclear whether your cursor is on the marker or the first or last character. The org-appear package helps by displaying the markers while the cursor is on a rich text word.

  (use-package org-appear
    :hook
    (org-mode . org-appear-mode))

Preview Images

Org mode includes images as file links, but it can also preview the image itself. The penultimate line in this configuration instructs Org mode to preview all images in a buffer. You can toggle this with C-c C-x C-v (org-toggle-inline-images) for each open buffer.

You need to restrict the size of previews because they can get unwieldy when working with high-resolution images. You can set the default width of a preview in pixels, which in this example is 300. If you like to increase the size of a specific image, then place the cursor on it and use the plus and minus keys.

The code above shows the number of pixels in a list '(300) instead of just the number. This method instructs Org mode to override this setting for individual images with the #+attr_org: :width set. In this example, the image is displayed at a width of 100 pixels.

  #+caption: Image caption.
  #+attr_org: :width 100
  [[file:path/to/image.png]]

Prettify Special Symbols

When using Org mode or similar approaches, there a lot of characters that are not content but indicate semantics, such as the asterisks at the start of a header. These symbols are practical but look a bit rough. The previous configuration already removed the leading stars to reduce clutter. Now we will replace these symbols with some nicer looking bullets.

Emacs can change the way a text file is displayed by either hiding or replacing characters. The Org-Modern package implements a configurable package to rice your Org mode buffers. The package can style headline indicators, keywords, tables and source blocks. This configuration disables some of the functionality because hiding indicators is not always a good idea.

  (use-package org-modern
    :hook
    (org-mode . global-org-modern-mode)
    :custom
    (org-modern-keyword nil)
    (org-modern-checkbox nil)
    (org-modern-table nil))

LaTeX previews

If you have a working LaTeX installation, then Org Mode can preview LaTeX fragments, such as formulas, as images. To preview the fragment under the cursor, press C-c C-x C-l (org-latex-preview) to, for example, convert $\sum_1^\infty \frac{1}{x}$ to $\sum_1^\infty \frac{1}{x}$. Org mode created a subdirectory named

The org-fragtog package provides some nice functionality that toggles between the source and the preview of the formulas, which means you don't have to use the org-latex-preview function repeatedly. The package is loaded after the Org package has loaded.

  ;; LaTeX previews
  (use-package org-fragtog
    :after org
    :custom
    (org-startup-with-latex-preview t)
    :hook
    (org-mode . org-fragtog-mode)
    :custom
    (org-format-latex-options
     (plist-put org-format-latex-options :scale 2)
     (plist-put org-format-latex-options :foreground 'auto)
     (plist-put org-format-latex-options :background 'auto)))

The org-format-latex-options variable controls the way the Emacs presents fragments. By default, the text is a bit small. This variable is a list with properties such as colours and size. The plist-put function lets you change one of these options in the list. The foreground and background are set to take the same colour as your text. If you change from dark to light mode or vice versa, you need to evaluate the org-latex-preview function to change the way formulas are displayed.

 

Line Spacing

When the text is a bit too compact for your liking, then change the line-spacing variable. Setting it to nil results in a cramped reading space, so best to add some whitespace between lines. Space between paragraphs is formed by adding an empty line.

If the value is an integer, it indicates the number of pixels below each line. A decimal number is a scaling factor relative to the current window's default line height. The setq-default function sets this for all buffers. Otherwise, it only applies to the current open buffer. Try the value that best suits your preferences.

  ;; Increase line spacing
  (setq-default line-spacing 2)

A Clean Writing Interface

Writing takes total concentration to produce creative prose. Distractions are the natural enemy of concentration. While your computer is your most important writing tool, it can also be a source of distractions.

Distraction-free writing means that your computer screen is free of clutter and, just like an old typewriter, only shows the text you are working on. In the article about configuring Emacs, we already removed the menu bar and other on-screen distractions.

Olivetti is a simple Emacs minor mode that facilities distraction-free writing. The name Olivetti derives from the famous typewriter brand.

You activate Olivetti mode with M-x olivetti-mode. This minor mode reduces the width of the text to seventy characters and centres the text in the middle of the window. The width of the text is changeable with the M-x olivetti-set-with command or C-c \.

I have written a new function that makes Olivetti mode a bit easier to use. This code stores your window configuration when you hit F9 (or whatever key you prefer) and activates Olivetti mode. It also increases the text by two steps to create a nice focussed screen. Finally, typing F9 again restores the previous window settings.

This snippet of code is a simple example of the flexibility of Emacs and how relatively easy it is to change its behaviour to suit your preferences. The ews-distraction-free function checks whether Olivetti mode is currently active. If this is not the case, then it saves the current window configuration to a register and activates Olivetti mode with enlarged font size. If Olivetti mode is active, then the text is sized to its default and olivetti mode disabled. If the original window configuration had more than two open windows, then this is restored so you are back where you left off.

As a side note, all functions specifically written for the Emacs Writing Studio start with ews-, which is in line with best-practice naming conventions in Emacs Lisp where all functions start with their package name.

  ;; Distraction-free writing
  (defun ews-distraction-free ()
    "Distraction-free writing environment using Olivetti package."
    (interactive)
    (if (equal olivetti-mode nil)
        (progn
          (window-configuration-to-register 1)
          (delete-other-windows)
          (text-scale-set 2)
          (olivetti-mode t))
      (progn
        (if (eq (length (window-list)) 1)
            (jump-to-register 1))
        (olivetti-mode 0)
        (text-scale-set 0))))

  (use-package olivetti
    :demand t
    :bind
    (("<f9>" . ews-distraction-free)))

Ricing Org Mode

By ricing Org mode we have moved somewhere between pure plain text and a graphical interface. There is no functional need to do so other than convenience. While it might seem that we have moved away from the What You See is What You Mean approach, that is not quite the case. The way the screen is presented in Emacs is different from the way it looks in your final output.

For example, if you create a website, any Org mode text surrounded by a forward slash (/example/) is translated as <i>example</i>/. For LaTeX output, it becomes \emph{example}. The HTML style sheet or LaTeX document class determines the way this code looks in the final output (the "what you get" in WYSIWYG). This example is italic by default, but it could be something different.

The results of our efforts have made a difference, as shown by the image below. Your chosen theme will change the background and text colours.

After ricing org mode
Enhanced Org mode screen.

Emacs Writing Studio

If you like to support my work, then please purchase the Emacs Writing Studio book.

Emacs Writing Studio

Emacs Writing Studio

A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.

You can find the source files for the book and the latest configuration files on GitHub:

Emacs is a malleable system, so everybody will have their personal preferences. Any article on how to use Emacs is thus opinionated. If you have a different way of doing things, please complete the contact form to send me an email or contact me on social media through the links in the footer.

Now that you have written a nice article or a new book, it is time to publish your work as an ebook or a physical book.

Share this content

You might also enjoy reading these articles

Writing Prose with Emacs

Exploring Your Ideas With the Denote-Explore Package

Reading eBooks with Emacs