39

I am using org-mode, and the document I am writing has a table name whose name looks like this: tab_weekly_report. When I export the document to HTML, I expect the name to exported as tab_weekly_report, but org-mode treats _ specially (as a markup character). How can I avoid this?

6 Answers 6

36

org-mode exports _ as subscripts and ^ as superscripts

The default export behavior can be customized using the menus Org -> Customize -> Browse Org Group. To update the default behavior for subscripts & superscripts, choose:

  • [-]-\ Group Org Export
    • [-]-\ Group Org Export General
      • — Option Org Export With Sub Superscripts

Org Export With Sub Superscripts Examples

Examples

  1. Interpret them - Default

    • Underscore_subscript becomes Underscoresubscript
    • Hat^superscript becomes Hatsuperscript
  2. Curly brackets only

    • Underscore_WithCurlyBrackets_{subscript} becomes Underscore_WithCurlyBracketssubscript
    • Hat^WithCurlyBrackets^{superscript} becomes Hat^WithCurlyBracketssuperscript
  3. Do not interpret them

    • Underscore_subscript becomes Underscore_subscript
    • Hat^superscript becomes Hat^superscript
    • Underscore_WithCurlyBrackets_{subscript} becomes Underscore_WithCurlyBrackets_{subscript}
    • Hat^WithCurlyBrackets^{superscript} becomes Hat^WithCurlyBrackets^{superscript}

Note: If you don't want to mess around with settings, the quick and easy solution is to disable superscripts and subscripts by setting export option for ^ to nil.

  • To disable superscripts and subscripts, add the following lines to your org file:

    #+OPTIONS: ^:nil
    
6
  • 2
    AFAIK, there is no _ option. The ^ option is called org-export-with-sub-superscripts internally, indicating that it affects both.
    – NickD
    Mar 11, 2019 at 16:50
  • 1
    @NickD - Thanks for catching nonexistent _ option! I’ve removed it from answer.
    – Melioratus
    Mar 11, 2019 at 17:17
  • Is there a way to have subscripts enabled but escape the underlines? \_ doesn't work, which does in LaTeX.
    – HappyFace
    Oct 26, 2022 at 1:31
  • 2
    @HappyFace - I use and recommend using #OPTIONS: ^{} which leaves underscores and hats alone and makes the syntax ^{superscript} and _{subscript} instead.
    – Melioratus
    Nov 4, 2022 at 17:05
  • 1
    @Melioratus As pointed out by a news user who doesn't how comment rights, there is a colon missing between the caret and the braces, so it should be ^:{} instead of ^{}, as in the answer of Joseph Tesfaye. Dec 8, 2022 at 9:23
27

Add the following at the beginning of your file.

#+OPTIONS: ^:nil

It should do the trick. If it doesn't, I'd check org-symbols: http://orgmode.org/worg/org-symbols.html

0
19

Somewhat hard to find, but you can just use foo \under foo or foo\under{}foo.

2
  • 2
    Brilliant! thanks.
    – Uria Mor
    Jul 5, 2020 at 18:24
  • 1
    This should be the best (most upvoted) answer
    – Ajned
    Mar 30, 2021 at 8:45
2

By default the underscore "_" and caret "^" characters are treated as markers of subscripts and superscripts when exporting with org-mode or pandoc. To export them as they are you can add the line

#+OPTIONS: ^:{}

to your org file and then use either org-mode or pandoc to export. If you are using pandoc-mode make sure the region to be exported also include this line before the underscore and caret characters.

1

Summarizing and refining @Melioratus answer/commentary (which is the currently -- 2022-12-07 -- the top and accepted answer)

You can add this directive to your file to prevent underscores getting interpreted as subscripts.

#+OPTIONS: ^:nil  

...or even better, this...

#+OPTIONS: ^:{} 

@Melioratus had mentioned the latter in a comment but it did not work for me. Experimentation has shown that if I change @Melioratus's comment from...

#OPTIONS: ^{}

...to...

#+OPTIONS: ^:{}

...then it works as described.

3
1

If you want to include it in your config directly, instead of setting the option in each file:

(setq org-use-sub-superscripts nil)
(setq org-export-with-sub-superscripts nil)

Your Answer

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

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