5
votes

I am trying to export a literal string from Emacs Org-mode to Latex for subsequent export to PDF. The literal string is:

str1\__str2

I have tried the following input in the Org file:

\verb+str1\__str2+

This produces the following code in the .tex file:

\verb+str1\hspace{3ex}str2+

I expected the following code in the .tex file:

\verb+str1\__str2+

I have also tried the following in the Org file:

\begin{verbatim}
str1\__str2
\end{verbatim}

This produces the following code in .tex file:

\begin{verbatim}
str1\hspace{3ex}str2
\end{verbatim}

Including the following option in the Org file has no effect on the output:

#+OPTIONS:     ^:{}
3

3 Answers

2
votes

If you don't mind the verbatim block, which you indicated above you're ok with, then this:

#+BEGIN_EXAMPLE
   str1\__str2
#+END_EXAMPLE

Produces this:

\begin{verbatim}
str1\__str2
\end{verbatim}
2
votes

You can use org-entities-user to create your own entities with different translations on export.

Setting it to e.g. (("textbackslash" "\\textbackslash" nil "\\" "\\" "\\" "\\")) will translate \textbackslash to \textbackslash on LaTeX output and to \ for all other outputs.

1
votes

This ugly workaround may help:

| str1\textbackslash{}\_\_str2  |

I cannot get the backslash thing out of the way, which will not look good on HTML export.