From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GOrMCONBoWC5dAEAgWs5BA (envelope-from ) for ; Sun, 16 May 2021 18:01:39 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id sAxsBONBoWDfDAAAB5/wlQ (envelope-from ) for ; Sun, 16 May 2021 16:01:39 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5E25712963 for ; Sun, 16 May 2021 18:01:38 +0200 (CEST) Received: from localhost ([::1]:49996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liJCy-0000Hr-El for larch@yhetil.org; Sun, 16 May 2021 12:01:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liJBL-0000Hd-Vk for emacs-orgmode@gnu.org; Sun, 16 May 2021 11:59:55 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:39973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liJBJ-0004v4-MJ for emacs-orgmode@gnu.org; Sun, 16 May 2021 11:59:55 -0400 Received: (Authenticated sender: admin@nicolasgoaziou.fr) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 8112DFF802; Sun, 16 May 2021 15:59:48 +0000 (UTC) From: Nicolas Goaziou To: Juan Manuel =?utf-8?Q?Mac=C3=ADas?= Subject: Re: [Question] Custom parse tree filter References: <87fsym3dbe.fsf@posteo.net> Mail-Followup-To: Juan Manuel =?utf-8?Q?Mac=C3=ADas?= , orgmode Date: Sun, 16 May 2021 17:59:47 +0200 In-Reply-To: <87fsym3dbe.fsf@posteo.net> ("Juan Manuel =?utf-8?Q?Mac=C3=AD?= =?utf-8?Q?as=22's?= message of "Sun, 16 May 2021 15:31:33 +0000") Message-ID: <871ra6zn2k.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=217.70.183.199; envelope-from=mail@nicolasgoaziou.fr; helo=relay9-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: orgmode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621180898; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qu/iCt1DwNEK7cxDB4n/iVJjaOXHdzNolUVjeD+7dII=; b=gUZCPD6wI0yhXl2l6cTSF/+FT5d5XErJ0aZO1rx72VDfMoMc8aJ2fRdCFv+HVJj1pSJ4IZ cUhGmCmzxhnaRROa4GEiUjULLqOG/yj776Kw/ex0QQxncHEJA/JGFfRzdU+vgr9d4YYTtt wizvrDct9+8DnbTyELFc9L56u3nwPgsDzrDcFKYOTbDxIjNuHxpgil76LtBMgcRFuXXHZn OsRVHBJ9AASBRa56wWAvkY6gfaQWwKtzTa70IBzHdrlbci7qnGvxoHZrEo4EXgyIHkEWVc 6DWKNj98fgB2wvU/3crNXcD6El4T9CpKDQsc5ASstemPxPsW7dDa6IXDhJKwTg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621180898; a=rsa-sha256; cv=none; b=rasrYJMMCTK8rexXJYqvoB5NWM0jekr+eMqizsUTLEbkoWfLetMlSd2YHPZTpJhIaHdDBu QHOg417DZJSIYjP03ip/uiopaEE9aUWvhvr28O1OcwN7ijuvsAWXdrQ+bSYg2Lj8Otseja IAUKqRGdYwmr33tSW1wb7orjVS+epN3ER3SQT1GZYLURLvNtCpg7+qY28dz4wtZRljU7x7 ibTYGQg+8LGxNxWEpj9YZoR7ZOa6fCaNsdHFaZwKGjSF9vEkxAsPFWrhfTT2ZFZlbrtMPg U0OlXZ4r9e40qy+zFkobBProIlBx03ChGpk84KWGyr83rOYxiFZ4OEJZWmaUdw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -0.95 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 5E25712963 X-Spam-Score: -0.95 X-Migadu-Scanner: scn0.migadu.com X-TUID: pifgLYd161jp Hello, Juan Manuel Mac=C3=ADas 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 secti= on 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 star= t\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 "%fontfeatu= re start\n")) (org-element-contents section) (list (funcall create-export-snippet "%fontfeatu= re 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=20 (org-export-raw-string "%fontfeature start\n") Regards, --=20 Nicolas Goaziou