I use a lot of overline (in statistical formulae) and so I have the following in my .emacs:

     (quote (("*" bold)
             ("/" italic)
             ("_" underline)
             ("=" org-verbatim verbatim)
             ("+" (:strike-through t))
             ("~" (:overline t) verbatim))))
     '(org-hide-emphasis-markers t)
     '(org-pretty-entities t))

In other words, I want ~ to define overline and I want it to render in-line in Emacs.

This works great, however I cannot follow that emphasis (or any emphasis for that matter) with more characters such as superscript or subscript numbers. For example, ~X~_1 renders as literally ~X~ followed by a subscript 1. The X is overlined until I type the underscore, then the emphasis tildes reappear.

I assume the solution has something to do with modifying org-emphasis-regexp-components and maybe use of a zero-width space between the emphasis and the subscript, but there I get lost.

Also I would love my PDF exports to render the same (at the moment, since I am using the ~ for overline, my overlined segments get rendered as code) so for a part 2, if we can update the PDF export to render overlines properly too, that would be amazing.

1 Answer 1


You are right about having to modify org-emphasis-regexp-components. In particular, you have to add _ and ^ to the regexp for the post component (be careful where you add them: leave the dash at the very beginning and leave the opening square bracket at the very end - I added them after the initial dash below):

  #+begin_src emacs-lisp
    (setf (nth 1 org-emphasis-regexp-components) "-_^[:space:].,:!?;'\")}\\[")

    (setf (nth 4 org-emphasis-alist) '("~" (:overline t) verbatim))


After setting the latter, you need to reload Org mode as its doc string states: M-x org-reload RET.

That should take care of subscripts and superscripts in the buffer.

For PDF rendering, a possible implementation is to replace the current rendering of the code markup with an overline rendering. The relevant data structure is org-latex-text-markup-alist: we replace the code element with one of our own devising:

  #+begin_src emacs-lisp
    (require 'ox-latex)

    (delete (assoc 'code org-latex-text-markup-alist) org-latex-text-markup-alist)
    (add-to-list 'org-latex-text-markup-alist '(code . "\\ensuremath{\\overline{%s}}"))

That uses the \overline macro (which is only defined in math environments, hence the \ensuremath). That seems to work in the simple cases in your question. No guarantees however: there may be more complicated cases that break this.

The require might be needed in order to pick up the definition of the variable org-latex-text-markup-list.

  • Thanks for the answer! The first section works brilliantly. The latex markup section errors out though: "delete: Symbol’s value as variable is void: org-latex-text-markup-alist". Emacs 26.3 (Cygwin build). Commented Sep 7, 2020 at 19:46
  • Ah, you may be running an older version of Org mode that does not have that variable. What version are you running? M-x org-version RET will tell, C-u M-x org-version RET will insert it in a buffer so you can cut-and-paste and you should update your question with that information ... or you might need to (require 'ox-latex) to get the definition of the variable.
    – NickD
    Commented Sep 7, 2020 at 20:23
  • The require will probably resolve it: the variable was introduced way back before 8.3.7.
    – NickD
    Commented Sep 7, 2020 at 20:37
  • The require did it! Looks fantastic and the use-cases I need it for all seem to render properly in emacs and PDF export. Thanks so much! Will tag it as answered. As an aside, any idea how I can, both in emacs and PDF export, render a d with a ^ above it? This is an estimate of Cohen's d (i.e. d-hat) in statistics-land. Thanks! Commented Sep 9, 2020 at 4:59
  • Please ask a new question: tacking on another question in a comment is generally discouraged.
    – NickD
    Commented Sep 9, 2020 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.