# How do I escape special characters in Org mode?

Here is a bit of Org code:

Here's a bit of OCaml: ~let x' = 1 in x' + x'~.
Many ~x~s in there, no?
And this one is worse: ~x ~!~ x <> 0~


Exporting to PDF yields this:

How do I

• Escape the ' to fix the first line?
• Escape the s to fix the second line?
• Escape the ~ to fix the third line?

I did not find any mention of this is the org manual.

Escape the ' to fix the first line?

Works for me with the development version.

Escape the s to fix the second line?

I don't think that's possible ATM in Org syntax. You might need something like @@latex:\texttt{x}s@@.

Escape the ~ to fix the third line?

=x ~!~ x <> 0=

• Re the third one: that won't do; I do need a difference between Code and Verbatim. – Clément Aug 1 '16 at 17:31
• how about src_ocaml{x ~!~ x <> 0}? – rasmus Aug 2 '16 at 9:09
• Woops. Not sure how I missed your comment. I just came across these. Feel free to expand your answer, and I'll delete mine. – Clément Aug 8 '16 at 0:25
• Although src_ is broken as well: src_c{int main \{} keeps the escape character in there, and src_c{a{}b} stops at the first closing brace... – Clément Aug 8 '16 at 0:50
• You were right about the first one: it was fixed in org 9. – Clément Aug 10 '16 at 1:46

Using inline code blocks fixes some of these issues; I'm not sure why I didn't come across them before:

#+PROPERTY: header-args :exports code

Here's a bit of OCaml: src_ocaml{let x' = 1 in x' + x'}.
Many src_ocaml{x}s in there, no?
And this one is worse: src_ocaml{x ~!~ x <> 0}.


And the output:

Here's a bit of OCaml: \texttt{let x' = 1 in x' + x'}.
Many \texttt{x}s in there, no?
And this one is worse: \texttt{x \textasciitilde{}!\textasciitilde{} x <> 0}.


It's not a panacea, of course: both src_c{int main \{} and src_c{a{}b} are broken...