# Prevent org export from expanding \ as $\backslash$

When using the org's ox-koma-letter, I'm having a problem with org exporting LaTeX commands expanding the leading \ as $\backslash$.

Using the example letter (from Romeo to Juliet) on the orgmode.org site, if I change the closing section as follows:

* Yours truly,                                                      :closing:
#+LaTeX: \hspace{2em}
Romeo of House Montague


But org's export to LaTeX is expanding the line with the \hspace{2em} command as:

\setkomavar{signature}{$\backslash$hspace\{2em\} Romeo of House Montague}


How do I prevent this?

[edited to specify precise environment in which issue is occurring.]

[edit 2: As of 20180702, the org-koma-letter Signature definition in org-contrib is:

 ;; Signature.
(org-string-nw-p
(org-trim
(org-export-data
(org-koma-letter--get-tagged-contents 'closing)
info)))))
(signature (org-string-nw-p (plist-get info :signature)))
(signature-scope (funcall check-scope 'signature)))
(and (or (and signature signature-scope)
(not (and (eq scope 'global) heading-val))
(format "\\setkomavar{signature}{%s}\n"


Which still produces the same issue. ]

• Does not happen with emacs-version 26.1 and org-version 9.1.6. What versions of emacs and org-mode do you have? Does the same problem occur with emacs -Q? – Tobias Jun 23 '18 at 8:49
• I've edited the question above with more detail. I've just tried it with emacs -Q just adding the ox-koma-letter export code, and I get the same behaviour. I'm using emacs 26.1 and org-version 9.1.9. – emacsomancer Jun 23 '18 at 16:33

As a workaround you can replace the Section ;; Signature in function org-koma-letter--build-settings with the following code. I essentially removed org-export-data from there.

 ;; Signature.
(org-string-nw-p
(org-trim
;; (org-export-data
(or (org-koma-letter--get-tagged-contents 'closing) "")
;; info)
))))
(signature (org-string-nw-p (plist-get info :signature)))
(signature-scope (funcall check-scope 'signature)))
(and (or (and signature signature-scope)

They use the translator for the headlines org-koma-letter-headline to extract the :opening: headline and put its stuff into org-koma-letter-special-contents. org-koma-letter--get-tagged-contents retrieves the opening from there. I have the impression that org-koma-letter-headline already gets the translated headline contents and translating it again with org-export-data is a bad idea.
• Is there a good way of doing this (i.e. replacing the Signature bit) without just editing the org-koma-letter file itself? E.g. of programmatically replacing it in .emacs? – emacsomancer Jun 23 '18 at 19:50
• @emacsomancer Nicolas Goaziou notified me about a small problem in his answer to my buf-fix proposal. The case when org-koma-letter--get-tagged-contents must be handled separately. I've corrected the above bugfix in that regard. I've tested the corrected version with org files containing a :closing: and org files not containing any :closing:. Looks like it runs flawless. – Tobias Jun 24 '18 at 10:39
• I've noticed that as of org-contrib of 20180702, the signature bit in org-koma-letter still has error-producing org-export-data lines included (see OP edit). I assumed the fix would have rolled out by now. – emacsomancer Jul 2 '18 at 23:18