[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Filter to put decorative initial letters
From: |
Juan Manuel Macías |
Subject: |
Filter to put decorative initial letters |
Date: |
Fri, 07 Jan 2022 00:41:03 +0000 |
Hi,
These past holidays I've been experimenting with some little useful, but
fun stuff. This is an export filter to put a decorative initial letter
in the first paragraphs of the first level sections, using the LaTeX
package lettrine (https://www.ctan.org/pkg/lettrine).
A screenshot: https://i.imgur.com/mLQVHFC.png
#+BIND: org-export-filter-parse-tree-functions (lettrine)
#+begin_src emacs-lisp :exports results :results none
(defun lettrine (tree backend info)
(when (org-export-derived-backend-p backend 'latex)
(org-element-map tree 'headline
(lambda (section)
(when (eq 1 (org-element-property :level section))
(let* ((contents (org-element-interpret-data (org-element-contents
section)))
(lettrine-opt (org-export-get-node-property
:LETTRINE_OPTIONS section t))
(contents-lettrine (with-temp-buffer
(insert contents)
(save-excursion
(goto-char (point-min))
(re-search-forward
"\\(\\b.\\)\\([^\s]+\\b\\)" nil t)
(replace-match (concat "\\\\lettrine"
(if
lettrine-opt (format "[%s]"
lettrine-opt) "")
"{" "\\1" "}"
"{" "\\2" "}")
t nil)
(org-element-parse-buffer)))))
(apply #'org-element-set-contents
section
(list contents-lettrine)))))
info)
tree))
#+end_src
Best regards,
Juan Manuel
- Filter to put decorative initial letters,
Juan Manuel Macías <=