From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Juan Manuel Macías" <maciaschain@posteo.net>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: [Question] Custom parse tree filter
Date: Sun, 16 May 2021 17:59:47 +0200 [thread overview]
Message-ID: <871ra6zn2k.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87fsym3dbe.fsf@posteo.net> ("Juan Manuel Macías"'s message of "Sun, 16 May 2021 15:31:33 +0000")
Hello,
Juan Manuel Macías <maciaschain@posteo.net> writes:
> 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!
I think you are operating at the wrong level. Higher level headlines
contain lower level ones. I suggest to operate on sections instead.
Also, using `org-element-interpret-data' is meh because you're operating
at the parse tree level. You can insert export-snippet objects directly.
Here's a proposal. This could be refactored, but you get the idea.
--8<---------------cut here---------------start------------->8---
(defun my-custom-filters/fontspec-headline (tree backend info)
(when (org-export-derived-backend-p backend 'latex)
(org-element-map tree 'section
(lambda (section)
(let ((font (org-export-get-node-property :FONT section t))
(fontfeature (org-export-get-node-property :FONTFEATURE section t))
(create-export-snippet
;; Create "latex" export-snippet with value V.
(lambda (v)
(org-element-create 'export-snippet (list :back-end "latex" :value v)))))
(cond
(font
(apply #'org-element-set-contents
section
(append (list (funcall create-export-snippet "%font start\n"))
(org-element-contents section)
(list (funcall create-export-snippet "%font end\n")))))
(fontfeature
(apply #'org-element-set-contents
section
(append (list (funcall create-export-snippet "%fontfeature start\n"))
(org-element-contents section)
(list (funcall create-export-snippet "%fontfeature end\n"))))))))
info)
tree))
--8<---------------cut here---------------end--------------->8---
Also, when "org-cite-wip" is merged, you will be able to replace, e.g.,
(funcall create-export-snippet "%fontfeature start\n")
with
(org-export-raw-string "%fontfeature start\n")
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2021-05-16 16:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 15:31 [Question] Custom parse tree filter Juan Manuel Macías
2021-05-16 15:59 ` Nicolas Goaziou [this message]
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:
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=871ra6zn2k.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=maciaschain@posteo.net \
/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).