emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* add a heading w/ #+print_bibliography to parse tree on export
@ 2021-07-31  0:17 Matt Price
  2021-07-31  1:01 ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Price @ 2021-07-31  0:17 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1595 bytes --]

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!

[-- Attachment #2: Type: text/html, Size: 2002 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: add a heading w/ #+print_bibliography to parse tree on export
  2021-07-31  0:17 add a heading w/ #+print_bibliography to parse tree on export Matt Price
@ 2021-07-31  1:01 ` John Kitchin
  2021-08-01  0:05   ` Matt Price
  0 siblings, 1 reply; 3+ messages in thread
From: John Kitchin @ 2021-07-31  1:01 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

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.

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 <moptop99@gmail.com> 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!
>

[-- Attachment #2: Type: text/html, Size: 3180 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: add a heading w/ #+print_bibliography to parse tree on export
  2021-07-31  1:01 ` John Kitchin
@ 2021-08-01  0:05   ` Matt Price
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Price @ 2021-08-01  0:05 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 4255 bytes --]

thanks John,

On Fri, Jul 30, 2021 at 9:01 PM John Kitchin <jkitchin@andrew.cmu.edu>
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 <moptop99@gmail.com> 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!
>>
>

[-- Attachment #2: Type: text/html, Size: 6090 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-01  0:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  0:17 add a heading w/ #+print_bibliography to parse tree on export Matt Price
2021-07-31  1:01 ` John Kitchin
2021-08-01  0:05   ` Matt Price

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