emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: Filter to put decorative initial letters
Date: Fri, 07 Jan 2022 00:41:03 +0000	[thread overview]
Message-ID: <871r1kwf6o.fsf@posteo.net> (raw)

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 


             reply	other threads:[~2022-01-07  0:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07  0:41 Juan Manuel Macías [this message]
2022-01-11  0:43 ` Filter to put decorative initial letters William Denton
2022-01-11 16:21   ` Juan Manuel Macías

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871r1kwf6o.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).