emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Filter to put decorative initial letters
@ 2022-01-07  0:41 Juan Manuel Macías
  2022-01-11  0:43 ` William Denton
  0 siblings, 1 reply; 3+ messages in thread
From: Juan Manuel Macías @ 2022-01-07  0:41 UTC (permalink / raw)
  To: orgmode

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 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-11 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07  0:41 Filter to put decorative initial letters Juan Manuel Macías
2022-01-11  0:43 ` William Denton
2022-01-11 16:21   ` Juan Manuel Macías

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).