5.16 Custom Org emphasis faces

Org provides the user option org-emphasis-alist which associates a character with a face, list of faces, or face attributes. The default specification of that variable looks like this:

(setq org-emphasis-alist
      '(("*" bold)
        ("/" italic)
        ("_" underline)
        ("=" org-verbatim verbatim)
        ("~" org-code verbatim)
        ("+" (:strike-through t))))

With the exception of org-verbatim and org-code faces, everything else uses the corresponding type of emphasis: a bold typographic weight, or italicized, underlined, and struck through text.

The best way for users to add some extra attributes, such as a foreground color, is to define their own faces and assign them to the given emphasis marker/character.

This is a custom face that extends the standard bold face with a red foreground value (so it colorises the text in addition to the bold weight):

(defface my-org-emphasis-bold
  '((default :inherit bold)
    (((class color) (min-colors 88) (background light))
     :foreground "#a60000")
    (((class color) (min-colors 88) (background dark))
     :foreground "#ff8059"))
  "My bold emphasis for Org.")

This face definition reads as follows:

Same principle for how to extend italic and underline with, for example, green and yellow hues, respectively:

(defface my-org-emphasis-italic
  '((default :inherit italic)
    (((class color) (min-colors 88) (background light))
     :foreground "#005e00")
    (((class color) (min-colors 88) (background dark))
     :foreground "#44bc44"))
  "My italic emphasis for Org.")

(defface my-org-emphasis-underline
  '((default :inherit underline)
    (((class color) (min-colors 88) (background light))
     :foreground "#813e00")
    (((class color) (min-colors 88) (background dark))
     :foreground "#d0bc00"))
  "My underline emphasis for Org.")

In the case of a strike-through effect, we have no generic face to inherit from, so we can write it as follows to also change the foreground to a more subtle gray:

(defface my-org-emphasis-strike-through
  '((default :strike-through t)
    (((class color) (min-colors 88) (background light))
     :foreground "#505050")
    (((class color) (min-colors 88) (background dark))
     :foreground "#a8a8a8"))
  "My strike-through emphasis for Org.")

Or we can just change the color of the line that strikes through the text to, for example, a shade of red:

(defface my-org-emphasis-strike-through
  '((((class color) (min-colors 88) (background light))
     :strike-through "#972500")
    (((class color) (min-colors 88) (background dark))
     :strike-through "#ef8b50"))
  "My strike-through emphasis for Org.")

It is possible to combine those effects:

(defface my-org-emphasis-strike-through
  '((((class color) (min-colors 88) (background light))
     :strike-through "#972500" :foreground "#505050")
    (((class color) (min-colors 88) (background dark))
     :strike-through "#ef8b50" :foreground "#a8a8a8"))
  "My strike-through emphasis for Org.")

One may inspect the variables modus-themes-operandi-colors and modus-themes-vivendi-colors for possible color values. Or call the command modus-themes-list-colors to show a buffer that previews each entry in the palette.

Visualize the active Modus theme’s palette.

Once we have defined the faces we need, we must update the org-emphasis-alist. Given that org-verbatim and org-code are already styled by the themes, it probably is best not to edit them:

(setq org-emphasis-alist
      '(("*" my-org-emphasis-bold)
        ("/" my-org-emphasis-italic)
        ("_" my-org-emphasis-underline)
        ("=" org-verbatim verbatim)
        ("~" org-code verbatim)
        ("+" my-org-emphasis-strike-through)))

That’s it! For changes to take effect in already visited Org files, invoke M-x org-mode-restart.