Emacs tweaks: Export Org checkboxes using UTF-8 symbols

Posted: - Modified: | emacs, org, tips
UPDATE 2014-03-28: Newer versions of org have the org-html-checkbox-type variable, which you can set to unicode. Use M-x customize-variable org-html-checkbox-type to see if you have it.

This snippet turns - [X] into ☑ and - [ ] into ☐.

(defun sacha/org-html-checkbox (checkbox)
  "Format CHECKBOX into HTML."
  (case checkbox (on "<span class=\"check\">&#x2611;</span>") ; checkbox (checked)
        (off "<span class=\"checkbox\">&#x2610;</span>")
        (trans "<code>[-]</code>")
        (t "")))
(defadvice org-html-checkbox (around sacha activate)
  (setq ad-return-value (sacha/org-html-checkbox (ad-get-arg 0))))

To find this code, I searched ox-html.el for [. Eventually I found org-html-checkbox, which is directly called by org-html-format-list-item instead of being a function variable that you can change. So that meant I needed to override the behaviour of org-html-checkbox through defadvice. You can see above how I wrap advice around org-html-checkbox and replace the return value with my own function. For more about advice, read the Emacs Lisp Intro manual.

To find the hex codes for the UTF-8 characters, I searched Google for UTF-8 checkbox and found BALLOT BOX WITH CHECK. I used the hex code so that I didn't have to worry about encoding issues. I tested it by updating one of my weekly reviews. Tada!

Inspired by Grant from Wisdom and Wonder.

You can view 7 comments or e-mail me at sacha@sachachua.com.

7 comments

Grant Rettke

2014-03-27T02:40:42Z

That works perfectly. Thank you for that!

Hi, thank you for your post,it is really attractive, but why my org-mode does not possess that variable? Of course, the function does not work, too.

If you're using the Org built into Emacs 24, that's still version 7, which could explain why that doesn't work. You can install Org from MELPA in order to upgrade to a newer version. You will need to start with emacs -q, then follow the instructions from MELPA's getting started guide (http://melpa.milkbox.net/#/... to load package and add MELPA to your sources list. Then you can use M-x package-install to install org. Hope that helps!

Many thanks. I will try as you said, and I think it will work absolutely!

I use the latest version of Org 8.2.6, but still cannot find org-html-checkbox-type variable. Could you give me some advise?

Fernando Basso

2016-08-17T13:35:29Z

I wanted to use ✔ in place of those X in emacs itself. Could not find a way so far...

Thanks for the solution!