5

I make substantial use of prettify-symbols in my programming buffers. A snippet of some of my python symbols:

(add-hook 'python-mode-hook
        (lambda ()
          (mapc (lambda (pair) (push pair prettify-symbols-alist))
                '(("for" .      ?∀)
                  ("in" .       ?∊)
                  ("not in" .   ?∉)
                  ("return" .  ?⟼)))))

This works fine for all cases except (html) exporting.

Pretty symbols from source code, or even directly from org-mode text, will not transfer over after exporting.

Eric Kaschalk
  • 281
  • 1
  • 6

1 Answers1

0

The code below was too long to post as a comment, so I'm posting an answer even though it doesn't work. I thought it might be of some help. The problem I encountered was that prettify-symbols-alist was empty.

(defun ess/org-pretty-symbols-to-html (backend)
  (when (equal backend 'html)
    (goto-char (point-max))
    (while (ignore-errors (org-babel-previous-src-block))
      (org-narrow-to-element)
      (mapc
       (lambda (x)
         (goto-char (point-max))
         (while (re-search-backward (car x) nil t)
           (replace-match (cdr x) nil t)))
       prettify-symbols-alist)
      (widen))))

(add-hook 'org-export-before-parsing-hook 'ess/org-pretty-symbols-to-html)
Erik Sjöstrand
  • 826
  • 4
  • 14
  • 1
    The doc for `org-export-before-parsing-hook` says it is run on a *copy* of the original buffer. Since `prettify-symbols-alist` is buffer local, this may be the cause of the problem. – JeanPierre Feb 03 '17 at 14:49