Kelvin Hu
Kelvin Hu

Reputation: 1423

How do I escape slash in org-mode?

Take foo /bar/ baz as example, when exported to HTML, it becomes foo <i>bar</i> baz, now I want to export it with the original style foo /bar/ baz, how to achieve this ? I have tried foo \/bar\/ baz, but the output becomes foo \/bar\/ baz.

I know this is an easy question, I have googled a lot, but only find this one: Escape pipe-character in org-mode, the answer says slash escaping works fine, but for me, it seems not fine.


edit:

After searching org mode mailing list, I find a discussion and solution here: http://thread.gmane.org/gmane.emacs.orgmode/50743

There are two ways to do this:

  1. set option #+OPTIONS: *:nil to turn off all emphasis symbols
  2. modify variable org-emphasis-alist, remove relevant content

For me, the first solution is acceptable, and also it is simple.

Upvotes: 15

Views: 4954

Answers (4)

Placing a zero width space (\u200B) before and after the character you want to escape does the trick.

I did a function that can insert the character you want between these two spaces.

(defun org-insert-literal-character (c)
  "Insert a literal character at point."
  (interactive "cWhat character?")
  (insert ?\u200B c ?\u200B))

(define-key org-mode-map (kbd "C-c i l") 'org-insert-literal-character)

Given an emphasized sentence:

Ready to insert the slash

Move the point to where you want to insert the character and press 'C-c i l' and '/':

Slash inserted

Also, here is an example of an org html generated website using this:

Website with emphasized slash

Upvotes: 0

Louis Strous
Louis Strous

Reputation: 1074

Put a zero-width space (U+200B; insert in Emacs using Ctrl-x 8 RET 200B RET) between the whitespace and the forward slash.

org-mode text

What do we see?
- /foo/
- ​/foo/

with a zero-width space inserted just before the first forward slash on the second "foo" line (not visible, because it has zero width) yields the following HTML after exporting:

<div id="content">
<h1 class="title">What do we see?</h1>

<ul>
<li><i>foo</i>
</li>
<li>​/foo/
</li>
</ul>

</div>

The zero-width space is exported, too, and ends up between the <li> and the /foo/ where you'd expect it.

Upvotes: 7

(I'll re-post my answer here for the sake of completeness...)

You could also format the relevant text as verbatim or code:

Text in the code and verbatim string is not processed for Org mode specific syntax; it is exported verbatim.

So you might try something like =foo | bar= (code) or foo ~|~ bar (verbatim). It does change the output format, though.

Upvotes: 1

Ista
Ista

Reputation: 10437

If you can tolerate a space between the slashes, foo / bar / bas will export with literal slashes. Alternatively you can make the whole string verbatim with =foo /bar/ baz=.

I suspect that neither of these is exactly what you want, but they can be done easily and may be good enough.

EDIT If you need slashes for a URL you should use orgmode link syntax, e.g., [[http://foo/bar.baz]].

Upvotes: 1

Related Questions