0

I want to have intra-word font changes in org mode -- eg. "Teacher vs teaching" -- works fine here in SE markdown. Doesn't in org.

There is this old question. Is it possible to combine two answers there? I want to use user81065's use of zero width space along with itsjeyd's suggestion to tweak org-emphasis-regexp-components. This is for org mode export in general. ie I'd rather avoid latex/html/odt specific methods (as some other answers suggest) and stick to pure org to work with any back-end.

Basically using zero width space shows as an ugly grey blob in odt export. Can we use the regexp-components to recognize the zero width space as a delimiter and then throw it away?

6
  • Please clarify the question, to cover what's needed from the other question. It's not clear just what you're doing. Where & when do you want these "font changes" - when doing what?
    – Drew
    Jul 9, 2022 at 15:38
  • I don't know but what's not clear. Anyways added an extra line in 1st & 2nd para
    – Rusi
    Jul 9, 2022 at 16:36
  • In LibreOffice, disable Menu Bar -> View -> Field Shadings. The "ugly grey blob" will go away. IOW, you have configured LIbreOffice to alert you about the presence of these characters, which are "normally" invisible.
    – user31220
    Jul 10, 2022 at 3:03
  • @whitetrillium One typically uses odt (doc) export to send the document to some vanilla non emacs user. So I don't merely ZWSP to dissappear; it should not be present -- just as org "disappears" stars #+BEGIN_XYZ and much else. IOW the ZWSP is an org-artifact not document-content
    – Rusi
    Jul 10, 2022 at 3:29
  • Hey @whitetrillium Since you understand org export filters Pls take a look at emacs.stackexchange.com/q/73123/5223
    – Rusi
    Aug 17, 2022 at 7:31

1 Answer 1

1

To get this

Intra-word emphasis using Zero Width Space

export the org snippet below after eval-ling the setup code.

(Note that both the setup code and org snippet have ZERO WIDTH SPACES and you CANNOT SEE these either in this stackexchange post or in your Emacs buffer. The fontification in Emacs buffer will give you a clue where the ZERO WIDTH SPACE characters are)

#+options: author:nil broken-links:nil c:nil creator:nil
#+title: Intra-word emphasis using Zero Width Spaces

Teach​*er* vs teach​*ing*

/Method/​-s and =Class=​es

- HiDPI :: *Hi*​gh *D*​ots *P*​er *I*​nch

#+begin_src emacs-lisp :exports results
  ;; Tell `whitespace-mode' that we are only interested
  ;; in ZERO WIDTH SPACE chars

  (custom-set-variables
   '(whitespace-display-mappings
     '((space-mark 8203
           [8857])))
   '(whitespace-space-regexp "\\(​+\\)")
   '(whitespace-style
     '(face spaces space-mark)))

  (custom-set-faces
   '(whitespace-space
     ((t
       (:background "yellow" :foreground "firebrick")))))

  ;; Put the `org' buffer in `whitespace-mode', so that we can 
  (whitespace-mode +1)

  ;; Use `C-x r i SPC' to insert ZERO WIDTH SPACE easily
  (set-register ?  "​")

  ;; Remove ZERO WIDTH SPACE from output
  (require 'ox)
  (add-to-list
   'org-export-filter-final-output-functions
   (defun my-org-export-filter-plain-text-functions
       (text backend _info)
     (replace-regexp-in-string "​" "" text t t)))

  ;; Report `org' version
  (format "Demo-ed with `Org-%s'" org-version)
#+end_src


Here I have extracted the setup emacs-lisp code separately


;; Tell `whitespace-mode' that we are only interested
;; in ZERO WIDTH SPACE chars
(custom-set-variables
 '(whitespace-display-mappings
   '((space-mark 8203
                 [8857])))
 '(whitespace-space-regexp "\\(​+\\)")
 '(whitespace-style
   '(face spaces space-mark)))

(custom-set-faces
 '(whitespace-space
   ((t
     (:background "yellow" :foreground "firebrick")))))

;; Put the `org' buffer in `whitespace-mode', so that we can 
(whitespace-mode +1)

;; Use `C-x r i SPC' to insert ZERO WIDTH SPACE easily
(set-register ?  "​")

;; Remove ZERO WIDTH SPACE from output
(require 'ox)
(add-to-list
 'org-export-filter-final-output-functions
 (defun my-org-export-filter-plain-text-functions
     (text backend _info)
   (replace-regexp-in-string "​" "" text t t)))

;; Report `org' version
(format "Demo-ed with `Org-%s'" org-version)


5
  • I guess the last 8-10 lines is what I'm looking for. The rest as I mentioned (other comment) is potentially useful but not quite my use case. I need to get onto a machine and try (bit later)
    – Rusi
    Jul 10, 2022 at 3:39
  • The last require... and add-to-list... seem to have worked -- Thanks! For now +1. [I only eval-ed that much] If you make that the main part of the answer (and the rest as auxiliary for those who may want) I'll accept as well. Thanks again!
    – Rusi
    Jul 10, 2022 at 13:52
  • This may be worth a separate answer. But right now various links are broken including the download one.
    – Rusi
    Sep 20, 2022 at 11:29
  • 1
    Fixed the links. Filter functions in that library are "better" ones than the ones suggestion here.
    – user31220
    Sep 21, 2022 at 3:11

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.