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: [Question] Custom parse tree filter
Date: Sun, 16 May 2021 15:31:33 +0000	[thread overview]
Message-ID: <87fsym3dbe.fsf@posteo.net> (raw)

Hi all,

I am writing a custom parse tree filter that does the following (LaTeX
backend): if a heading has the ':font:' property, the content of that
heading is enclosed in a LaTeX group. If the property is ':fontfeature:',
then the content is enclosed in a different group. The filter works fine
when all the headings are at the same level. But with different levels,
it does not returns the expected result. It's evident that I'm doing
something catastrophically wrong :-). I wonder if anyone could put me on
the track of the origin of my error...

Below, the offender function and a sample. Thanks in advance!

Best regards,

Juan Manuel 

#+BIND: org-export-filter-parse-tree-functions (my-custom-filters/fontspec-headline)
#+begin_src emacs-lisp :exports results :results none
  (defun my-custom-filters/fontspec-headline (tree backend info)
    (when (org-export-derived-backend-p backend 'latex)
      (org-element-map tree 'headline
	(lambda (hl)
	  (cond ((org-element-property :FONT hl)
		 (let* ((font (org-element-property :FONT hl))
			(contents (org-element-interpret-data (org-element-contents hl)))
			(contents-new (concat
				       (replace-regexp-in-string "\s*\\(\\[.+\\]\\)\s*" "" font)
				       (if (string-match "\\(\\[.+\\]\\)" font)
					   (concat "@@latex:" (match-string 1 font) "%@@\n\n")
		   (org-element-set-contents hl (with-temp-buffer
						  (insert contents-new)
		((org-element-property :FONTFEATURE hl)
		 (let* ((fontfeature (org-element-property :FONTFEATURE hl))
			(contents (org-element-interpret-data (org-element-contents hl)))
			(contents-new (concat
		   (org-element-set-contents hl (with-temp-buffer
						  (insert contents-new)

* Minion Pro
  :font: Minion Pro [Style=Historic,Color=teal]

Lorem ipsum dolor.

** Lowercase Numbers
   :fontfeature: Numbers=Lowercase

Lorem ipsum dolor 1234567890.

*** Letter Space
    :fontfeature: LetterSpace=14.6

Lorem ipsum dolor 1234567890.

             reply	other threads:[~2021-05-16 15:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-16 15:31 Juan Manuel Macías [this message]
2021-05-16 15:59 ` [Question] Custom parse tree filter Nicolas Goaziou
2021-05-17 12:20   ` 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:

  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=87fsym3dbe.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \


* 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


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).