How to avoid interpreting just one underscore in orgmode export?

Table of Contents

 

Problem: I need just one literal underscore in my org-exported blog post

I export orgmode to my blogs. However, when I have an underscore (like in a section header) it is interpreted as putting the next thing in a subscript. There are plenty of answers out there for disabling this globaly or for the whole file, but I WANT subscripts sometimes. How do I tell it to leave just a particular _ alone when I export?

In other words, I want some_filename and not somefilename.1

Answers

The quickest answer, which works for my technical blog usecase well, is just to wrap the text in = equal signs, which is for in-line code snippets and retains the literal underscore.2

The more correct answer is given in the manual3, by using #+OPTIONS: ^:{} in your exporting section and then foo_bar will be an underscore foo_{bar} will be a subscript.4 I actually added the following to the :config section of my use-package org in my init:

(org-use-sub-superscripts '{})

Now I can readily control whether my underscores are made into subscripts via judicious use of {}.

Edit: the correct way doesn’t work for my particular markdown-to-hugo export

The “correct” way works fine when exporting directly to html, but my export is passing through markdown and then hugo and somewhere along the may it all gets munged into a subscript. Until I have time and interest in debugging why exactly this is happening, I’ll stick with the equal-sign wrapping.

Footnotes

1 this was first posted as a question in several places, particularly the weekly emacs Tips and Tricks thread at https://www.reddit.com/r/emacs/comments/vxxyb8/comment/ig20udn/?utm_source=share&utm_medium=web2x&context=3

2 This easy solution came from the Emacs Tips and Tricks thread this week, here: https://www.reddit.com/r/emacs/comments/vxxyb8/comment/ig23ftp/?utm_source=share&utm_medium=web2x&context=3

3 Subscripts and Superscripts, here: https://orgmode.org/manual/Subscripts-and-Superscripts.html

4 Big thanks to @neeasade on Twitter for this finding: https://twitter.com/neeasade/status/1547359359390421004?s=20&t=V_YNVZkAbj4-VwU_uiN4Zg

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist