Escaping Org Examples in Org

From Karl Voit we have this really useful piece of advice:

If you follow the link to Stack Overflow you'll discover the proper way to include Org markup as an example in an Org file. For a trivial example of this see yesterday's post in which I included a small bit of Org markup.

The idea is that you put the example in an Org source block rather than, say, an Example block:

#+BEGIN_SRC org
* A heading
** Subhead
   With a bunch of other stuff
#+END_SRC

but that's not quite enough. In my Org source file for this post the above was entered as:

#+BEGIN_SRC org
  ,#+BEGIN_SRC org
  ,* A heading
  ,** Subhead
     With a bunch of other stuff
  ,#+END_SRC
#+END_SRC

As you can see, the Org markup that you want to appear as the example (and not be acted on) is escaped by a comma. Although the Stack Overflow post does not make it clear, the easy way to do this is to insert the #+BEGIN_SRC org and #+END_SRC markers and then call org-edit-special, which is normally bound to 【Ctrl+c '】, and enter your Org example without worrying about escaping. When you finish by typing 【Ctrl+c '】 again, Org mode will automatically add the escaping for you.

I'm really glad to learn this trick. Trying to add Org mode markup in an example never worked well for me. Yesterday, I saw Voit's tweet and, serendipitously, was able to use it immediately in my next post.

This entry was posted in General and tagged , . Bookmark the permalink.
  • I use it to tangle other org documents and it works great.