From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SJfnEIrlBWHIUwAAgWs5BA (envelope-from ) for ; Sun, 01 Aug 2021 02:06:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UEGeDIrlBWFBRwAA1q6Kng (envelope-from ) for ; Sun, 01 Aug 2021 00:06:34 +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 56692BE27 for ; Sun, 1 Aug 2021 02:06:33 +0200 (CEST) Received: from localhost ([::1]:33306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9yzv-0000ps-B2 for larch@yhetil.org; Sat, 31 Jul 2021 20:06:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9yzQ-0000ph-Uq for emacs-orgmode@gnu.org; Sat, 31 Jul 2021 20:06:00 -0400 Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]:46966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m9yzO-0001H1-Ko for emacs-orgmode@gnu.org; Sat, 31 Jul 2021 20:06:00 -0400 Received: by mail-ua1-x933.google.com with SMTP id t25so3733288uar.13 for ; Sat, 31 Jul 2021 17:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0O5eEW6Wi0JsDy61vZesqeu397QRcZrSX+1aimFYyGg=; b=hophseYOrTUloMfvgtrBgaLIeX19EX1EPpcQ7LwQSvfsS1qYr6FhDr2//vc4p8MaBz 6R71RKdpYvE+qc6aXyDEwo2WimVNWFstNae+uHpU0KL2HYYrU8AuzfMhXy4ByOplBDWY LbhMGbOrvYKIrvh6lxx7DpzkBDq3dBGV+pNh89Kw1DZ1OLTyOVMMECpQdVI4Jtu7OpNS MR4mLthO2foQLzrMa9vjBmeU0QxAIrTdiEnnb//Z4ct6CdR8Ksoa+1bUc5Bi47gNDgZ+ zmktqm7tRJVwS6AVwfTb1OO1wEgy7rzUZFmEe94U5kM8pKZssnQOiI0QS2zdwu+VJzdH vrhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0O5eEW6Wi0JsDy61vZesqeu397QRcZrSX+1aimFYyGg=; b=qxTujZHPonFESJZ87tKIEcMUb1IGDNjeMC1FDKWu/1odSJGf9XJZwIFdrbfwCa9g+e CfzeCaM7PhaqLKemgvNm3CsRdm+KpBeFJJK/30YP91SDaeq2PVGypc+3DZVlXL23lGXO LkCq/1UjvQBJ9eB4aIPpm7nDr0p56HoByZi0SO/WRUe3Z10vV/38ErD60HTCZsLPi8HO ez4cfGFyUosVGwAGvMv2ZgMXAdyDa5KPVk1ppOg44W25RbnufQR1UNPCBct0MqIQlDbV 6tcsbRUXTK7CnTCotgxL9gpJ9jDzXOvrizzjObpmdYr6/FqElYtl+2ZlQaBy3uJj6OAv gVag== X-Gm-Message-State: AOAM5320kUBj2bWHxP2ydMz6TfqYdMxIp1XDYc0SHJVQKT4Nz8xEde7i YWmssPI+LKGdytrSwS0X+Leb/dTABlMEiZcCPgk= X-Google-Smtp-Source: ABdhPJw34/xZ6sU0wqnn3WrNmL3WyWwtZB1UxPJAtvnhzFCgOSZR5N2DaqC2B7GWKL/tOrdOkOjGQ/qJvD6M3yucJIA= X-Received: by 2002:a05:6130:3a6:: with SMTP id az38mr7222543uab.102.1627776356860; Sat, 31 Jul 2021 17:05:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Matt Price Date: Sat, 31 Jul 2021 20:05:45 -0400 Message-ID: Subject: Re: add a heading w/ #+print_bibliography to parse tree on export To: John Kitchin Content-Type: multipart/alternative; boundary="00000000000086460105c87437ed" Received-SPF: pass client-ip=2607:f8b0:4864:20::933; envelope-from=moptop99@gmail.com; helo=mail-ua1-x933.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: Org Mode 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=1627776394; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=0O5eEW6Wi0JsDy61vZesqeu397QRcZrSX+1aimFYyGg=; b=fvxZZlgv+b4eFFigI4UZaTH3w2J3LhuH6LrCW4ANeDRHi2kJNibH1+GWKJhZSGRItxCpJO yBiCezjq0XLdGLU6RG9f3eDA87urbEMs25mJdYYGmiFnV60/pO9/RYrwQVCT/9/MH5SNML 6ScPajfJ0J4iOL0tPNyUsTMeKUf56ulWYyx2a1hDnHa9xCSbXa79AWn8rE76Yhs5giR8vE XQCcOTbBTkEjS+NBRc8ZDFTPKjENvyfTShzjG2dsLmvj0PpDBnbMaJRAUK4ZhDWmWj+6Kj +a3gkD78jOStCAgceMiCipWaBr0SyFnvmyhrPUkzPQTpUoRBWNdyOKSZ3acvFg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1627776394; a=rsa-sha256; cv=none; b=FAdHfctqg084GkVN7nOcW3+Y9X+Lxt4AORFRO/wIOIF2A57OnohdHSoLMNls5M5uXQkxGW PzqAunplIGk4flGCdP3hEnGcs9fsOpaXzWFeGYTpx7zGahMIsQp2SHGItz2+OGJ33+//HB rseZ8YQ1ID0+kk2p9BcOEDa3QUgGA/BsHRhessLNLJDPz4yZde7cNmuFPfBgh74urmX22K N2CCVjVzQI6jdnxGlL2n7zFs1fr3kASiAEbkDX5hxHlZ4Prub94L1ac6AJFDZjEHUQvawG oyZSgMTwrNIMwVwpH966nBO9Qj8C/ku62XKgj1gxfPYo/ncGTzvwRzwbCZ31Gg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=hophseYO; dmarc=pass (policy=none) header.from=gmail.com; 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: -3.12 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=hophseYO; dmarc=pass (policy=none) header.from=gmail.com; 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: 56692BE27 X-Spam-Score: -3.12 X-Migadu-Scanner: scn1.migadu.com X-TUID: zuzHYbIE5cfx --00000000000086460105c87437ed Content-Type: text/plain; charset="UTF-8" thanks John, On Fri, Jul 30, 2021 at 9:01 PM John Kitchin wrote: > I think the way to do this is to use a function in > org-export-before-processing-hook to add it if you don't find it. > > you can still use org-ml to generate the string that gets inserted. I > guess you would just go to the end of the buffer and insert it. > > this is what I came up with. I don't know if it might be useful to others, or if maybe a modified version might be worth putthing into some kind of package. (use-package org-cite :config (defcustom org-export-ensure-biblio t "Whether or not to create bibliography slide when missing from document" :group 'org-export :type 'string) (defcustom org-export-biblio-heading-id "bibliography" "custom id for bibliography slide heading in org-re-reveal" :group 'org-export :type 'string :package-version '(org-re-reveal . 1.5)) (defcustom org-export-biblio-heading-text "Sources" "Default Title to display above bibliography in org-re-reveal" :group 'org-export :type 'string ) (defun mwp-add-biblio-export-hook (&optional backend) "If there's a citation object, search for a bibliography keyword; if that's missing, create a new headline with the keyword. Intended for use with org-export-before-parsing-hook" (save-excursion (when (and org-export-ensure-biblio (not (re-search-forward "^[ ]?+#\\+print_bibliography:" nil t)) (progn (goto-char (point-min)) (re-search-forward org-element-citation-key-re (point-max) t))) (let* ((title (or org-export-biblio-heading-text "Sources")) (id (or org-export-biblio-heading-id "bibliography"))) (goto-char (point-max)) (insert (org-ml-to-trimmed-string (org-ml-build-headline :title `(,title) (org-ml-build-section (org-ml-build-property-drawer (org-ml-build-node-property "CUSTOM_ID" id)) (org-ml-build-keyword "print_bibliography" ""))))))))) (add-hook org-export-before-parsing-hook 'mwp-add-biblio-export-hook)) Matt > John > > ----------------------------------- > Professor John Kitchin (he/him/his) > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > > > > On Fri, Jul 30, 2021 at 8:18 PM Matt Price wrote: > >> Goal: >> conditionally add a headline with content to parse tree using either >> org-export-before-parsing-hook or org-export-filter-parse-tree-functions >> >> Explanation: >> I use org-re-reveal to make lecture slides from subtrees. Often I forget >> to add a heading with #+print_bibliography: and as a result org-cite does >> not generate the bibliography, and my citations are not wrapped in links. >> I'd like to search *either* the parse tree *or* the temporary export >> buffer for the #+print_bibliography keyword, and if it's not found, add a >> headline to the end of the subtree/parse-tree with the appropriate >> information. >> >> I can easily generate the proper lisp object with the org-ml package: >> >> (org-ml-build-headline :title '("Sources") >> (org-ml-build-section >> (org-ml-build-property-drawer >> (org-ml-build-node-property "CUSTOM_ID" >> "bibliography")) >> (org-ml-build-keyword "print_bibliography" "" ) >> )) >> >> And if I want I can turn that into a string by wrapping it in >> (org-ml-to-trimmed-string ...) >> >> However, I'm not sure how best to add it to the exported data. I believe >> I can add a function to either org-export-before-parsing-hook or >> org-export-filter-parse-tree-functions, but beyond that I'm a bit lost. >> It's not immediately obvious how to find the last headline and append >> another headline after that headline's section. Looking at the nesting >> confuses me somewhat and I'm afraid I'll break the data structure. >> >> Has anyone done something like this before and do you have ideas? >> >> Thank you! >> > --00000000000086460105c87437ed Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
thanks John,

=
On Fri, Jul 30, 2021 at 9:01 PM John = Kitchin <jkitchin@andrew.cmu.= edu> wrote:
I think the=C2=A0way to do this is to use a functi= on in org-export-before-processing-hook to add it if you don't find it.= =C2=A0=C2=A0

you can still use org-ml to generate = the string that gets inserted. I guess you would just go to the end of the = buffer and insert it.

=

this is what I came up with. I don't know if it mig= ht be useful to others, or if maybe a modified version might be worth putth= ing into some kind of package.

(use-package org-ci= te
=C2=A0 :config
=C2=A0 (defcustom org-export-ensure-biblio
=C2= =A0 =C2=A0 t
=C2=A0 =C2=A0 "Whether or not to create bibliography s= lide when missing from document"
=C2=A0 =C2=A0 :group 'org-expo= rt
=C2=A0 =C2=A0 :type 'string)

=C2=A0 (defcustom org-export-= biblio-heading-id
=C2=A0 =C2=A0 "bibliography"
=C2=A0 =C2= =A0 "custom id for bibliography slide heading in org-re-reveal"=C2=A0 =C2=A0 :group 'org-export
=C2=A0 =C2=A0 :type 'string=C2=A0 =C2=A0 :package-version '(org-re-reveal . 1.5))

=C2=A0 = (defcustom org-export-biblio-heading-text
=C2=A0 =C2=A0 "Sources&qu= ot;
=C2=A0 =C2=A0 "Default Title to display above bibliography in o= rg-re-reveal"
=C2=A0 =C2=A0 :group 'org-export
=C2=A0 =C2=A0= :type 'string
=C2=A0 =C2=A0 )

=C2=A0 (defun mwp-add-biblio-e= xport-hook (&optional backend)
=C2=A0 =C2=A0 "If there's a = citation object, search for a bibliography keyword;
if that's missin= g, create a new headline with the keyword. Intended for use with
org-exp= ort-before-parsing-hook"
=C2=A0 =C2=A0 (save-excursion
=C2=A0 = =C2=A0 =C2=A0 (when (and org-export-ensure-biblio
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(not (re-search-forward "^[ ]= ?+#\\+print_bibliography:" nil t))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (point-min))
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(re-search-forward = org-element-citation-key-re (point-max) t)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= (let* ((title (or org-export-biblio-heading-text "Sources"))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(id (or org-export-b= iblio-heading-id "bibliography")))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 (goto-char (point-max))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (inse= rt
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-ml-to-trimmed-string =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-ml-build-headline
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:title `(,title)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-ml-build-section
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-ml-build-property-drawer
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-ml-build-node-p= roperty "CUSTOM_ID" id))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (org-ml-build-keyword "print_bibliography" "&q= uot;)))))))))

=C2=A0 (add-hook org-export-before-parsing-hook 'm= wp-add-biblio-export-hook))

Matt
=C2= =A0
John
=
-----------------------------------
Professor John Kitchin (he/him/h= is)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie= Mellon University
Pittsburgh, PA 15213
412-268-7803
=


On Fri, Jul 30, 2021 at 8:18 PM Matt Price <moptop99@gmail.com>= ; wrote:
Goal:
conditionally add a headline with conte= nt to parse tree using either org-export-before-parsing-hook or org-export-= filter-parse-tree-functions

Explanation:
I use org-re-reveal to make lecture slides from subtrees. Often I for= get to add a heading with #+print_bibliography: and as a result org-cite do= es not generate the bibliography, and my citations are not wrapped in links= . I'd like to search *either* the parse tree=C2=A0 *or* the temporary e= xport buffer for the #+print_bibliography keyword, and if it's not foun= d, add a headline to the end of the subtree/parse-tree with the appropriate= information.=C2=A0

I can easily generate the= proper lisp object with the org-ml package:

(org-= ml-build-headline :title '("Sources")
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-ml-b= uild-section
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (org-ml-build-property-drawer
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(o= rg-ml-build-node-property "CUSTOM_ID" "bibliography"))<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (org-ml-build-keyword "print_bibliography" "&q= uot; )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 ))

And if I want I can turn t= hat into a string by wrapping it in (org-ml-to-trimmed-string ...)

However, I'm not sure how best to add it to the export= ed data.=C2=A0 I believe I can add a function to either org-export-before-p= arsing-hook or org-export-filter-parse-tree-functions, but beyond that I= 9;m a bit lost. It's not immediately obvious how to find the last headl= ine and append another headline after that headline's section. Looking = at the nesting confuses me somewhat and I'm afraid I'll break the d= ata structure.

Has anyone done something like this= before and do you have ideas?

Thank you!
--00000000000086460105c87437ed--