I'm writing some pseudo code having some symbols like λ (\lambda). Enabling org-toggle-pretty-entities converts \lambda to λ in buffer, however when I export to HTML or latex, they are not converted. How can I use these symbols in src block.

I'm okay with using example, verse block or any other way of preserving newlines.

  • what's the language within your src_block? – dangom Apr 7 '17 at 11:12
  • @dangom: like I said, I'm writing pseudo code, which looks like lisp. These are small snippets, I'm not that interested in having code highlight. I'm happy with pre formatting for newlines and symbols. – Anurag Peshne Apr 7 '17 at 20:16
  • Doesn't matter. What is the name of the language that you give to your source block?! That is what defines the functionality you get. You can't just write any Pseudocode that comes to mind and expect Org mode to know how to parse it. – dangom Apr 7 '17 at 20:21
  • @dangom I gave 'Scheme'. – Anurag Peshne Apr 7 '17 at 21:43
  • What happens if you just insert the Unicode symbol for lambda directly on the buffer? – dangom Apr 7 '17 at 21:45

Within Org SRC_BLOCK blocks, LaTeX inputs are not interpreted nor converted to symbols on export. You can tweak the export, though, to achieve what you want:

The following filter replaces \lambda by their equivalent Unicode symbol:

#+BEGIN_SRC emacs-lisp
      (defun my-lambda-to-unicode (output backend info)
        "Convert lambda to Unicode on export to html."
        (when (and (eq backend 'html)
                   (string-match "\\\\lambda" output))
          (replace-match "λ" nil nil output)))

      (add-to-list 'org-export-filter-final-output-functions

A simpler workaround, though, consists in entering the equivalent Unicode symbol directly into the buffer. To make the process easier you can use abbrev-mode, and have lambda be converted to the Unicode small greek lambda automatically. Here's a tutorial on how to deal with Unicode in Emacs.

An alternative is to use yasnippet and have snippets to insert symbols. The abbrev seems more efficient, though.

  • Since this is a work around, I'll wait a day or two to accept this answer. I've an impression that there is nothing which cannot be changed in Emacs. I'm sure there must be some way to tweak export to interpret LaTeX symbols. – Anurag Peshne Apr 7 '17 at 22:16
  • Just edited to add what you want. – dangom Apr 7 '17 at 22:36
  • You were right, directly adding Unicode is much simpler for someone who don't deal with Unicode everyday. – Anurag Peshne Apr 7 '17 at 22:54

Another way to do it is to directly begin a lstlisting environment instead of using #+begin_src. Of course this might not work with HTML exports though.

You would also need to add \lstset{basicstyle=\ttfamily, mathescape} in your LaTeX headers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.