3

It's easy to make whole words bold, italic etc. by using the asterisk/slash before and after the word. It's imperative however to also have a space in front of the opener markup, and after the closer markup. In other words, this easy (to use and easy to read) way of marking text is limited to start and end with space boundaries.

When using org-mode with languages that don't use spaces (Japanese, Chinese, etc.), adding a space just to make a word bold in those languages will make the formatting look quite ugly.

For html-export I could do the following, but that's neither handy, nor easy on the eye when looking at the org source.

abc@@html:<b>@@def@@html:</b>ghi

Does org-mode provide a better option?

  • 1
    Is there a way to distinguish word boundaries in these languages? If so, org-emphasis-regexp-components may help. – JeanPierre Nov 30 '15 at 8:39
  • Related answer. – Juancho Nov 30 '15 at 15:05
  • @JeanPierre. No there is not. In Japanese and Chinese there is only characters, no word separators. Sometimes even line-breaks are inserted after a constant number of characters (which are all of the same width), to get "justified text". In that case, the line-break often goes right through a word. – Eugene Beresovsky Dec 1 '15 at 1:05
4

One possibility would be to use Unicode Character 'ZERO WIDTH SPACE' (U+200B). You need to:

  • bind a key for inserting this character,
  • add it to org-emphasis-regexp-components (don't forget to M-x org-reload for it to take effect).
(defun insert-zero-width-space ()
  (interactive)
  (insert-char #x200b))

(define-key org-mode-map (kbd "C-*") 'insert-zero-width-space)

(setq org-emphasis-regexp-components
      '("   ('\"{\x200B" "-     .,:!?;'\")}\\[\x200B" "     
,\"'" "." 1))

You can define more sophisticated bindings: make * (and / etc) insert \x200B* or *\x200B depending on the previous * in the buffer being followed or preceded by \x200B.

In case you don't want this \x200B character to appear in the exported output, you can remove it with an export filter:

(defun my-filter-remove-u200b (text backend info)
  "Remove zero width space character (U+200B) from TEXT."
  (replace-regexp-in-string "\x200B" "" text))

(add-to-list 'org-export-filter-plain-text-functions
         'my-filter-remove-u200b)

This applies to all backends.

  • Works like a charm, looks good in emacs, looks good exported to html. Thanks! – Eugene Beresovsky Dec 1 '15 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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