12
votes

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.

3
I appreciate the answers people are giving, but they only illustrate that orgmode really needs a proper escaping mechanism. I've run into many situations like this with markup in orgmode, they're not always solveable with workarounds like this. - Ken Williams
For example, a newline breaks /italics/ processing, so AFAIK I have to put whole paragraphs on one line if I want them italicized. - Ken Williams

3 Answers

6
votes

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.

1
votes

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]].

1
votes

(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.