notes from /dev/null

by Charles Choi 최민수


10 Apr 2024

Exporting UTF-8 Smart Quotes from Org Mode

Count me as one who really likes using smart quotes when exporting from Org. To enable this requires that you set the variable org-export-with-smart-quotes to t. So far, so good yes? Not quite. Apparently by default when exporting to HTML or Markdown, Org will use the HTML character entity representation of a smart quote which I see as overly conservative in 2024. As most contemporary software now can handle UTF-8, it seems to me more sensible to use smart quote characters that are likewise UTF-8. For English these are:

  • left and right double quote
  • left and right single quote
  • apostrophe (right single quote)

Apparently Org has an alist variable that captures the different representations of the above for different languages and for different export targets. This variable is called org-export-smart-quotes-alist and sure enough it captures the UTF-8 set of characters for each language. Empowered with this knowledge, here’s some Elisp code to reconfigure org-export-smart-quotes-alist so that exporting to HTML or Markdown uses the UTF-8 representation for English (en).

(defun cc/reconfig-org-smart-quotes-lang (lang)
  "Reconfigure Org smart quotes to use utf-8 per LANG."
  (let* ((db-entry (assoc-string lang org-export-smart-quotes-alist))
         (utf8-primary-opening (plist-get (assoc-default 'primary-opening db-entry) :utf-8))
         (utf8-primary-closing (plist-get (assoc-default 'primary-closing db-entry) :utf-8))
         (utf8-secondary-opening (plist-get (assoc-default 'secondary-opening db-entry) :utf-8))
         (utf8-secondary-closing (plist-get (assoc-default 'secondary-closing db-entry) :utf-8))
         (utf8-apostrophe (plist-get (assoc-default 'apostrophe db-entry) :utf-8))
         )

    (setf (plist-get
           (assoc-default 'primary-opening
                          (assoc-string lang org-export-smart-quotes-alist))
           :html)
          utf8-primary-opening)

    (setf (plist-get
           (assoc-default 'primary-closing
                          (assoc-string lang org-export-smart-quotes-alist))
           :html)
          utf8-primary-closing)

    (setf (plist-get
           (assoc-default 'secondary-opening
                          (assoc-string lang org-export-smart-quotes-alist))
           :html)
          utf8-secondary-opening)

    (setf (plist-get
           (assoc-default 'secondary-closing
                          (assoc-string lang org-export-smart-quotes-alist))
           :html)
          utf8-secondary-closing)

    (setf (plist-get
           (assoc-default 'apostrophe
                          (assoc-string lang org-export-smart-quotes-alist))
           :html)
          utf8-apostrophe)))

(add-hook 'org-mode-hook (lambda ()
                           (cc/reconfig-org-smart-quotes-lang "en")))

The above code is tested on Emacs 29.1, Org 9.6.25.

If you export to different languages, be sure to run cc/reconfig-org-smart-quotes-lang with your language of choice.

I leave it as an exercise to motivated readers more experienced in Elisp to write a cleaner version of this code. As it stands, this works well enough to achieve my desired goal.

emacs   org mode

Past Articles

24
MAR
2024

Announcing Casual - An opinionated porcelain for Emacs Calc

Announcing the first public release of Casual - an opinionated Transient-based porcelain to support the casual usage of Emacs Calc.

read more
18
FEB
2024

cc-isearch-menu now on MELPA

My first Emacs package, cc-isearch-menu is now available on MELPA. It is a Transient menu for isearch.

read more
15
FEB
2024

Computing Truth Tables in Org

Truth tables are a great way to design and verify combinational logic. That said, they are a PITA to make. With some Emacs Elisp and Org, making truth tables becomes effortless, leaving you to focus on solving your logic problem.

read more
31
JAN
2024

Administering MacPorts

Some learnings I've made using MacPorts for the past two decades.

read more
16
JAN
2024

Enhancing Dired Sorting With Transient

Out of the box, Dired sorting is rather underwhelming. This post remedies that with Transient and a context menu.

read more
10
JAN
2024

Highlighting with isearch

isearch highlighting is a really great feature that can actually be usable given a Transient menu. This post shows you how.

read more
18
DEC
2023

Improving Emacs isearch Usability with Transient

Emacs isearch has many powerful features that are largely unusable because of poor keybindings. A Transient menu can change all that.

read more
12
DEC
2023

Personalizing Emacs Doc Navigation

I never have liked the default settings for reading Emacs documentation. That changes today.

read more
6
DEC
2023

Flavor #9 🎄

Yours truly providing vinyl selections for Flavor #9 at Harlan Records. December 14, 2023, 5-9pm. Roll in for holiday libations.

read more

Page 1 / 11   >

 

AboutMastodonInstagramGitHub

Feeds & TagsGet Captee for macOS

Powered by Pelican