3

Whenever I export to ASCII, the heading always converts to all capitals. How can I maintain the original capitalisation?

1 Answer 1

6

upcase is hard-coded into org-ascii-template--document-title of Org-version 9.2.6. The following Elisp code neutralizes that upcase by temporarily setting upcase to identity.

Note that one of the preconditions of the advice is that the source code of ox-ascii is available to Emacs. That is the case if you have installed the Melpa version of Org or you have installed the Elisp source package for Emacs. Under Ubuntu the Emacs Elisp source package is emacs26-el.

^;; -*- lexical-binding:t -*-
;; Lexical binding can become relevant for generalized variables
;; (see doc string of `gv-ref').

(require 'cl-lib)

(defcustom org+-ascii-upcase-title nil
  "Default value for :"
  :type 'boolean
  :group 'org-export-ascii)

(eval-after-load 'ox-ascii
  '(eval ;; Avoid expansion of `cl-pushnew' for place `org-export-backend-options' before ox-ascii is loaded.
    '(cl-pushnew (list :ascii-upcase-title nil "ascii-upcase-title" 'org+-ascii-upcase-title)
         (org-export-backend-options (org-export-get-backend 'ascii))
         :test #'equal :key #'car)))

(defun org+-ascii-ignore-upcase (fun info)
  "Neutralize `upcase' if :ascii-upcase-title is not set when calling FUN with INFO."
  (if (assoc-string (plist-get info :ascii-upcase-title) '(yes t on))
      (funcall fun info)
    (cl-letf (((symbol-function 'upcase) #'identity))
      (funcall fun info))))

(advice-add 'org-ascii-template--document-title :around #'org+-ascii-ignore-upcase)

You can switch on upcasing the title by the following option in your org file:

#+OPTIONS: ascii-upcase-title:t

Instead of t also the values on and yes work. Any other value such as no switches upcasing off. You can customize the default with the Elisp variable org+-ascii-upcase-title.

Tested with Emacs 26.3 and Org 9.2.6.

6
  • This gives me the error - let*: Symbol’s function definition is void: (setf\ org-export-backend-options). I am on version 9.1.9 if that's the issue?
    – randouser
    Feb 26, 2020 at 22:53
  • 1
    @randouser I have fixed the bug. Nevertheless, I am not sure why the original version did not work. I will post a question about that later this night.
    – Tobias
    Feb 27, 2020 at 15:25
  • I no longer get the error, but when I export as ascii, the title is still capitalised. On emacs 26.3.
    – randouser
    Feb 28, 2020 at 0:18
  • @randouser I noticed that the org library is not byte-compiled in my setup. It turns out that the symbol upcase is not directly contained in the byte-compiled code but only some reference to the underlying function. So the advice remains without effect for the byte-compiled code. I now enforce the loading of the source of ox-ascii. This should work for you if you have the sources for that package installed on your system.
    – Tobias
    Feb 28, 2020 at 5:41
  • @randouser I have corrected the code after the cause of the problem has been clarified in the answer to my question about with-eval-after-load and pushnew.
    – Tobias
    Mar 4, 2020 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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