emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Price <moptop99@gmail.com>
To: Matt Price <moptop99@gmail.com>, Org Mode <emacs-orgmode@gnu.org>
Subject: Re: modify citation links in a derived HTML backend
Date: Sun, 4 Jul 2021 12:12:01 -0400	[thread overview]
Message-ID: <CAN_Dec-dVBCde8tZwEthzfB6=sNVHEn5XfKrEatTAB4mtWxD0A@mail.gmail.com> (raw)
In-Reply-To: <87h7haw83x.fsf@wi.uni-muenster.de>

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

On Sun, Jul 4, 2021 at 8:56 AM Jens Lechtenboerger <
lechten@wi.uni-muenster.de> wrote:

> On 2021-07-03, Matt Price wrote:
>
> > I've added some comments in the issue you linked to, but in the meantime
> > I've also come up with what seems to be at least a semi-viable hack for
> > adding native CSL citation support to org-re-reveal. It involves creating
> > two new variables and then let-setting `citeproc-fmt--formatters-alist`
> in
> > `org-re-reveal-export-to-html`. Something similar could presumably be
> done
> > in other derived backends.
> >
> > I find it quite hackish and I don't know whether perhaps some more
> general
> > solution could be found, but in any case here is the code, which I have
> > inserted into org-re-reveal.el locally:
>
> Thank you for sharing your code, Matt!
>
> What is the general state of this new citation handling with respect
> to export backends?  Did you create the settings for HTML from
> scratch or did you take inspiration from HTML export functionality?
> I guess that basic support should go into ox-html, while small
> modifications could than take care of specifics for reveal.js
> presentations...
>
> Best wishes
> Jens
>

Thanks Jens!

So, there is a rather complicated chain of dependencies and I'm not sure
how best to procee in the specific case of org-re-reveal.

Here is how I understand the current state of affairs (and I think Bruce,
Nicolas, and Andras are all likely to have corrections to my explanation):

- the new syntax and processors are available in the wip-cite-new branch of
hte org git repo, and will likely be merged into the master branch pretty
soon.
- at present, and likely for some time, the best citation processor for
html export is defined in `oc-csl.el` and relies on the citeproc-el
library.  My code will only have an effect if the org file contains lines
like
--------------
#+bibliography: food-studies.bib
#+cite_export: csl "/home/matt/src/styles/chicago-author-date-mod.csl"
----------------
- oc-csl.el relies on citeproc-el to actually process the citations.
- citeproc-el is a fairly complex package with many moving parts. It
supports processing of citations in html and latex backends, but not in any
others (I think this is right!)
- citation formatting is handled in the file citation-formatters. el (
https://github.com/andras-simonyi/citeproc-el/blob/master/citeproc-formatters.el),
which, importantly, uses lexical binding. That file defines:
  -  a *structure* citeproc-formatter (
https://github.com/andras-simonyi/citeproc-el/blob/0857973409e3ef2ef0238714f2ef7ff724230d1c/citeproc-formatters.el#L35
),
 - a *function* citeproc-formatter-fun-create (
https://github.com/andras-simonyi/citeproc-el/blob/0857973409e3ef2ef0238714f2ef7ff724230d1c/citeproc-formatters.el#L51
)
- a *constant* citeproc-fmt--html-alist (
https://github.com/andras-simonyi/citeproc-el/blob/0857973409e3ef2ef0238714f2ef7ff724230d1c/citeproc-formatters.el#L142
)
- and a *variable* citeproc-fmt--formatters-alist (
https://github.com/andras-simonyi/citeproc-el/blob/0857973409e3ef2ef0238714f2ef7ff724230d1c/citeproc-formatters.el#L232)
that creates a set of formatters using citeproc-formmater-fun-create,
bassing it the value of citeproc-fmt--html-alist as raw material for the
html formatter.

The latter is what we need to change for our export -- we want to change
just one of the lambda functions used by the formatter for the duration of
export, without updating the global value of citeproc-fmt--formatters-alist.

Because all these variables are lexically bound -- making the resultant
closure values pretty confusing for me to inspect -- and because the
process of creating a formatter is a bit complex, I was a little  confused
about how best to modify the code, and I'm still not quite sure how to go
about it.  It's pretty easy to do this using the dash library:

-----
(let ((org-re-reveal-citeproc-fmt-alist
       (--map-when (eq  (car it) 'cited-item-no)
              `(cited-item-no . ,(lambda (x y) (concat "<a
href=\"#slide-bibliography\">" x "</a>")))
              citeproc-fmt--html-alist)))
 [do some exporting stuff])
-------
or just

-----
(defcustom org-re-reveal-citeproc-fmt-alist
 (--map-when (eq  (car it) 'cited-item-no)
              `(cited-item-no . ,(lambda (x y) (concat "<a
href=\"#slide-bibliography\">" x "</a>")))
              citeproc-fmt--html-alist)
:group org-re-reveal
:type alist)
------

But I'm not sure how best to do it without that.

In any case, the code I have provided here and in gitlab (
https://gitlab.com/oer/org-re-reveal/-/merge_requests/33) is quite hackish
and doubtless likely to error out in many circumstances. Probably I should,
in org-re-reveal-export-to-html,  at least test if the function
citeproc-formatter-fun-create is bound, so:

----------
(let ((citeproc-fmt--formatters-alist
          (and (functionp 'citeproc-formatter-create)
               `((html . ,(citeproc-formatter-create
                  :rt (citeproc-formatter-fun-create
org-re-reveal-citeproc-fmt-alist)
                  :bib #'citeproc-fmt--html-bib-formatter))))))
....do stuff)

(actually, I simplified my merge request to use all this code).

Does that help the explanation? And what do you think?

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

      reply	other threads:[~2021-07-04 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02 17:53 modify citation links in a derived HTML backend Matt Price
2021-07-03  7:53 ` Jens Lechtenboerger
2021-07-03 21:32   ` Matt Price
2021-07-04 12:56     ` Jens Lechtenboerger
2021-07-04 16:12       ` Matt Price [this message]

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='CAN_Dec-dVBCde8tZwEthzfB6=sNVHEn5XfKrEatTAB4mtWxD0A@mail.gmail.com' \
    --to=moptop99@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).