1

I use org-mode lists, both plain-text lists and numbered lists. I precede my lists with a "list title," which for me is any line ending in a colon.

Grocery list:
- tomatoes
- spinach
- blueberries

I'd like these list titles to be automatically italicized in export to HTML and LaTeX PDF.

I don't want to do this by making it a headline, since by design, as we know, there is no way to end an org-heading and return to the parent level without creating a new heading.

So instead, I want org to automatically consider any lines ending with a colon as list titles. (Even better would be to exclude headlines and lines that have a period somewhere before the ending colon.)

I figured out how to fontify such lines within the Emacs buffer itself by defining a new face:

(defface list-title-face
'((t (:background "pale green")))
"fontify list titles")

 (font-lock-add-keywords 'org-mode
'(("^.*:[ ]*$" . 'list-title-face)))

But how do I create an org-emphasis type so that the emphasis will be respected in org-export?

UPDATE: org-emphasis-regexp-components looks promising.

2

Org provides a variety of hooks to modify text on export. So, re-using your regular expression and org's italic emphasis, one way would be

(add-hook 'org-export-before-parsing-hook (lambda (backend)
            (replace-regexp "^\\(.*:\\)[ ]*$" "/\\1/")))    

Of course, then it will only appear in the exported document. So you may want to define a custom face and add a hook for the export.

  • Wouldn't it be simpler to define an org-emphasis type? What about using org-emphasis-regexp-components? – incandescentman Nov 22 '15 at 5:06
  • Org emphasis types require a character to mark the start and end, as far as I know, it won't match an arbitrary regex. – user2699 Nov 22 '15 at 5:16
  • This seems like a promising approach. However, it creates some unintended consequences. Here's an example. (The last line should not appear, however it does appear and is converted to italics.) Source is here: incandescentman.github.io/stackexchange/example.org – incandescentman Jan 22 '16 at 7:25
  • I guess it needs a way to distinguish between list titles and org-mode tags. – incandescentman Jan 22 '16 at 7:26

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.