From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MsIJG3pgomDJXwAAgWs5BA (envelope-from ) for ; Mon, 17 May 2021 14:24:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id yH8BFnpgomBEXQAAbx9fmQ (envelope-from ) for ; Mon, 17 May 2021 12:24:26 +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 AF50B1E718 for ; Mon, 17 May 2021 14:24:25 +0200 (CEST) Received: from localhost ([::1]:48284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1licIK-0003CL-JB for larch@yhetil.org; Mon, 17 May 2021 08:24:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1licER-0007sw-8Z for emacs-orgmode@gnu.org; Mon, 17 May 2021 08:20:23 -0400 Received: from mout01.posteo.de ([185.67.36.65]:51707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1licEO-0008Cs-JF for emacs-orgmode@gnu.org; Mon, 17 May 2021 08:20:22 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 388CD240027 for ; Mon, 17 May 2021 14:20:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1621254014; bh=Bds8c1NF3v+VqOuyeYJaTxE65fUlu7CJpiaDbslhv+M=; h=From:To:Cc:Subject:Date:From; b=Bmq30uCroBL4LhqMePqoNjpE8aSjjY+aL1MKvmKSl0i5E45cRBNxsP+RwdXZTT7qv q5F4zkcktNfioq6Dq/nzJDD9xzqrtOMuYhswBvDDmHuUq3nKZ7YnUw8x/Ah5DDUFrZ n5v5gPc2NCqfhMzuzerugqvIH0sarerIgwfFl+iuUEbMXAF6wV7EoGXh9XxDXv1VN5 9ChyJRq3PGeK++nBjWXTHmOpiVKgleck7w5D8uetA2Eig0aXCiOPTy4fIcsYc5kVi8 MTuMUVQ974L8aLhRTzD6WwNRBWSWCudd76iHYfWpeAhBOYzAKCxsQeeadpP4RZsUTg VjLp6xx1uDG3g== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FkJ9n3cM8z6tmJ; Mon, 17 May 2021 14:20:12 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: Nicolas Goaziou Subject: Re: [Question] Custom parse tree filter References: <87fsym3dbe.fsf@posteo.net> <871ra6zn2k.fsf@nicolasgoaziou.fr> Date: Mon, 17 May 2021 12:20:11 +0000 In-Reply-To: <871ra6zn2k.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sun, 16 May 2021 17:59:47 +0200") Message-ID: <8735ul7ds4.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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=1621254266; 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:dkim-signature; bh=n13WcVfKXsIlvSIMKvatCy5rI3EXvU6VjWzYxJy9fZQ=; b=eTfdVBnxpBDMCoMxJspFg229LQhau7SCE/1RlzId/eMAnC0pePTnCeNvGOAjetb6uSBVzz A2sZhZBDIaSnjg/mfR6/7xYgDNRoU0I5pBAY6ZxJyAt2o8uMQg1+d89HWaJgGcm1XEJe/0 xU+yh1rptW09UV3i7gEJohbF4pN3r0RhYs4CWo85LBfxYCfynj5ltqxg9a4hGgE5LaMFvd bVfVOyCY0BTjaikehlOtj3luJlzRVAPMjdLOf7uRuLmmFRVGy+uGnjXQZT51e1F4IFVqVf kYH5c5GmXnxPbTGGqwNlGyst6FmdjwcCdH+SV3WeFeGrw11izqogs4dciPkuVQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621254266; a=rsa-sha256; cv=none; b=CjwGSEcrPszjR4/Q82D6DyHztcDm7X90HfCC9t9+oKGGCYDT44vpiiHoqdZBnStb9oyrJ3 yUNa3p8K63ij+Vx4W+N0Hl8zdo4HMMSp13+LOJDTai33rehmJ7fQuLMGUaQ/WKHHL0Iqy/ NPXgAGTVgtO72nV15CVQJsXzYU0Cu2eTIiYXbzxkW6wKuksWovrR65vQJMv0vqy/pu2Jr/ EavIAa5dk6ZcDyvj22RKs2c4DKeVtMh7P2xocuA7URdwZtK5QhVINphzbjvXccjtosvGkp S9fhsROCimxg1s31B9gtHOlCvJ6R/wFcCkk3hkNFFJGDkwc9OVYO6stbcKbGUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Bmq30uCr; dmarc=pass (policy=none) header.from=posteo.net; 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: -1.64 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Bmq30uCr; dmarc=pass (policy=none) header.from=posteo.net; 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: AF50B1E718 X-Spam-Score: -1.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: Ik2O5c/7SOSy Hi Nicolas, Thank you very much for your excelent explanation, which has helped me to learn new and valuable things. I chose `headline' instead of `section' because in the scenario where I want to apply those LaTeX groups I was looking for something like this: {level 1 - group 1 {level 2 group 1 + group 2 {level 3 group 1 + group 2 + group 3 {etc. }}}} I have tested your function and it works fine when all headers are at the same level, but with different levels the filter understands both properties as `font' (?). Anyway, and only for practical purposes, and because I think that my initial idea of 2 properties was uneconomical, I have slightly modified your function with a single property `:fontspec:'. Now, with a couple of marks and some regexp both the \fontspec group and the one with \addfontfeature are extracted: | :fontspec: font ! optional: features | \fontspec{font}[features] | |----------------------------------------+---------------------------| | :fontspec: > features | \addfontfeature{features} | then the variable `fontspec': (let* ((font ) (fontfeature ) (fontspec (cond (font font) (fontfeature fontfeature)))) is passed as an argument of `(funcall create-export-snippet ...)' With a single property it works fine, although I have to test more... Thak you very much! Best regards, Juan Manuel=20 Nicolas Goaziou writes: > 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. > > (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 sec= tion t)) > (create-export-snippet > ;; Create "latex" export-snippet with value V. > (lambda (v) > (org-element-create 'export-snippet (list :back-end "lat= ex" :value v))))) > (cond > (font > (apply #'org-element-set-contents > section > (append (list (funcall create-export-snippet "%font st= art\n")) > (org-element-contents section) > (list (funcall create-export-snippet "%font en= d\n"))))) > (fontfeature > (apply #'org-element-set-contents > section > (append (list (funcall create-export-snippet "%fontfea= ture start\n")) > (org-element-contents section) > (list (funcall create-export-snippet "%fontfea= ture end\n")))))))) > info) > tree)) > > 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,