org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
568 stars 47 forks source link

Import annotations from Zotero #178

Open bepolymathe opened 3 years ago

bepolymathe commented 3 years ago

Hi,

This request follows a discussion started here. Zotero's new PDF reader allows you to work very efficiently with annotations and comments. These annotations are integrated by BetterBibLatex in the "note" field of a .bib entry but in LaTeX format.

(setq orb-preformat-keywords   '(("citekey" . "=key=") "note" "title" "url" "file" "author-or-editor" "keywords"))
(setq orb-templates
      '(("r" "ref" plain #'org-roam-capture--get-point
         "%^{note}"
         :file-name "${citekey}"
         :head "#+TITLE: ${title}\n#+ROAM_KEY: ${ref}\n
- tags ::
- keywords :: ${keywords}
- author(s) :: ${author-or-editor}
\n* Annotations (zotero)\n\n"
         :unnarrowed t)))

For example, this the result of an extraction image

This template currently allows to get the annotations in an org-mode file (in org-roam) but it would be very useful if it could be directly converted to org-mode format.

We can imagine :

It would be great.

myshevchuk commented 3 years ago

Hi,

thank you for the request. I will look into it as soon as time allows me.

myshevchuk commented 3 years ago

As a quick temporary solution install Pandoc and try this:

(defun my-orb-latex-note-to-org (citekey)
  (let* ((entry (bibtex-completion-get-entry citekey))
         (note (bibtex-completion-get-value "note" entry ""))
         (pandoc-command "pandoc --from latex --to org")
         result)
    (with-temp-buffer
      (shell-command (format "echo \"%s\" | %s" note pandoc-command)
                     (current-buffer))
      (setq result (buffer-substring-no-properties (point-min) (point-max))))))

(setq orb-preformat-keywords   '(("citekey" . "=key=") "note" "title" "url" "file" "author-or-editor" "keywords"))
(setq orb-templates
      '(("r" "ref" plain #'org-roam-capture--get-point
         ""
         :file-name "${citekey}"
         :head "#+TITLE: ${title}\n#+ROAM_KEY: ${ref}\n
- tags ::
- keywords :: ${keywords}
- author(s) :: ${author-or-editor}
\n* Annotations (zotero)\n\n
%(my-orb-latex-note-to-org \"${citekey}\")"
         :unnarrowed t)))

Using the below

BibTeX example ```bibtex @article{my-citekey, author = {authors}, title = {title}, keywords = {keywords}, note = {\section{Lecture pour l’intro du cahiers participation} \par Les éléments suivants sont mis de côté dans le cadre de la préparation de l’introduction du cahier de l’action sur les professionnels de la participations. \par \subsection{Intérêt pour l’introduction du cahiers} \begin{itemize} \item la typologie montre que le rapport à la démocratie participative est envisagée comme une croyance, comme un rapport aux idées. Notre travail qui approchent les choses par les pratiques montre qu’il est moins question de croyance que de logique d’alliance dans l’action. \item la démocratie participative est vue ici dans un rapport aux élus. Le cahier lui apporte un regard nouveau car il laisse de la place à des pratiques de politisation plus larges. \end{itemize} \par --- \par “À la suite du renouvellement des conseils municipaux de mars 2008, où 1 552 conseils de quartier ont été mis en place, 731 postes « d’adjoint·es de quartier » ont été institués. Ces chiffres sont en progression régulière depuis 20022. L’institutionnalisation des conseils de quartier semble donc avoir eu un effet sur la création de mandats d’élu·es délégués. ” (Lefebvre et al., 2020, p. 42) \par \subsection{Problématique} \par “Quelle place pour ces élu·es dans la division du travail politique ? Quelle est leur place en particulier dans les configurations qui se déploient dans les politiques de participation (entre maire, DGS, services dédiés, mairies de quartier...) ? Une forme d’éligibilité à cette fonction se dessine-t-elle, et si oui, autour de quelles ressources ? La variable partisane structure-t-elle ces divers enjeux ? Est-ce que les élu·es à la participation incarnent des entrepreneur·es de la cause participative, ou s’agit-il d’un rapport à leur délégation plus désinvesti ? Dans quelle mesure les trajectoires sociales et politiques, les façons d’entrer dans et de prendre le rôle façonnent-elles le rapport du personnel politique à la participation ? Autrement dit, qu’est-ce qui spécifie un·e adjoint·e à la participation, au sein du groupe des élu·es et dans l’ordre des délégations ? ” (Lefebvre et al., 2020, p. 43) \par }, } ```

The following note is created:

#+TITLE: Title
#+ROAM_KEY: cite:my-citekey

- tags ::
- keywords :: keywords
- author(s) :: authors, 

* Annotations (zotero)

* Lecture pour l'intro du cahiers participation
  :PROPERTIES:
  :CUSTOM_ID: lecture-pour-lintro-du-cahiers-participation
  :END:
Les éléments suivants sont mis de côté dans le cadre de la préparation
de l'introduction du cahier de l'action sur les professionnels de la
participations.

** Intérêt pour l'introduction du cahiers
   :PROPERTIES:
   :CUSTOM_ID: intérêt-pour-lintroduction-du-cahiers
   :END:

- la typologie montre que le rapport à la démocratie participative est
  envisagée comme une croyance, comme un rapport aux idées. Notre
  travail qui approchent les choses par les pratiques montre qu'il est
  moins question de croyance que de logique d'alliance dans l'action.

- la démocratie participative est vue ici dans un rapport aux élus. Le
  cahier lui apporte un regard nouveau car il laisse de la place à des
  pratiques de politisation plus larges.

---

"À la suite du renouvellement des conseils municipaux de mars 2008, où 1
552 conseils de quartier ont été mis en place, 731 postes « d'adjoint·es
de quartier » ont été institués. Ces chiffres sont en progression
régulière depuis 20022. L'institutionnalisation des conseils de quartier
semble donc avoir eu un effet sur la création de mandats d'élu·es
délégués. " (Lefebvre et al., 2020, p. 42)

** Problématique
   :PROPERTIES:
   :CUSTOM_ID: problématique
   :END:
"Quelle place pour ces élu·es dans la division du travail politique ?
Quelle est leur place en particulier dans les configurations qui se
déploient dans les politiques de participation (entre maire, DGS,
services dédiés, mairies de quartier...) ? Une forme d'éligibilité à
cette fonction se dessine-t-elle, et si oui, autour de quelles
ressources ? La variable partisane structure-t-elle ces divers enjeux ?
Est-ce que les élu·es à la participation incarnent des entrepreneur·es
de la cause participative, ou s'agit-il d'un rapport à leur délégation
plus désinvesti ? Dans quelle mesure les trajectoires sociales et
politiques, les façons d'entrer dans et de prendre le rôle
façonnent-elles le rapport du personnel politique à la participation ?
Autrement dit, qu'est-ce qui spécifie un·e adjoint·e à la participation,
au sein du groupe des élu·es et dans l'ordre des délégations ? "
(Lefebvre et al., 2020, p. 43)

Headline levels are not automatically adjusted, but this can be easily done manually meanwhile until I am able to provide a more integrated solution.

bepolymathe commented 3 years ago

Hi @myshevchuk !

Thanks for that ! That’s super useful, it works.

myshevchuk commented 3 years ago

@bepolymathe, great! Actually, you don't even need note in orb-preformat-keywords.

bepolymathe commented 3 years ago

Okay, thanks for the clarification. Have a nice day.

baogiadoan commented 2 years ago

hi i'm wondering if anyone has a working solution for the new org-capture-templates with the current org-roam v2, I tried to install pandoc but the above solution from @myshevchuk is not working for the current version of org-roam v2 that I'm using, some functions are reported void such as pandoc-command that I don't know where that function is from even after I installed pandoc on both Linux and Emacs. I guest these functions are not matching with org-roam v2 or the new template.

myshevchuk commented 2 years ago

Hi @baogiadoan, you have to adjust org-roam-capture-templates accordingly to the v2 format. Pandoc integration is not part of ORB yet. You should copy the custom function my-orb-latex-note-to-org from the solution above to your init file, or evaluate it interactively. Your init file may look something like this:

(defun my-orb-latex-note-to-org (citekey)
  (let* ((entry (bibtex-completion-get-entry citekey))
         (note (bibtex-completion-get-value "note" entry ""))
         (pandoc-command "pandoc --from latex --to org")
         result)
    (with-temp-buffer
      (shell-command (format "echo \"%s\" | %s" note pandoc-command)
                     (current-buffer))
      (setq result (buffer-substring-no-properties (point-min) (point-max))))))

(setq orb-roam-capture-templates
      '(("r" "ref" plain ""
           :target (file+head "${citekey}.org" "#+TITLE: ${title}\n
           \n* Annotations (zotero)\n\n
%(my-orb-latex-note-to-org \"${citekey}\")")
           :unnarrowed t
           :immediate-finish t)))
baogiadoan commented 2 years ago

thanks @myshevchuk it's working now

prashantnag93 commented 2 years ago

Hi @myshevchuk could you please correct my ref-template for org-roam-capture. I am not able to extract annotation from Zotero. This is my capture


(after! org-roam
  (defun my-orb-latex-note-to-org (citekey)
  (let* ((entry (bibtex-completion-get-entry citekey))
         (note (bibtex-completion-get-value "note" entry ""))
         (pandoc-command "pandoc --from latex --to org")
         result)
    (with-temp-buffer
      (shell-command (format "echo \"%s\" | %s" note pandoc-command)
                     (current-buffer))
      (setq result (buffer-substring-no-properties (point-min) (point-max))))))
  (setq org-roam-capture-templates
        '(("d" "default" plain
           "%?"
           :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                              "#+title: ${title}\n#+created: %u\n#+last_modified: %U\n")
           :immediate-finsh t
           :unnarrowed t)
                  ("r" "bibliography reference" plain
           (file "~/Dropbox/org/templates/ref-template.org")
           :target (file+head "literature/${citekey}.org"
                              "#+title: ${citekey}: ${title}\n")
           :unnarrowed t))))

Here is my ref-template.org


#+filetags: %(format ":%s:" (mapconcat #'identity (split-string "%^{keywords}" "," t " ") ":"))

#+OPTIONS: toc:nil

* %^{citekey}
:PROPERTIES:
:Custom_ID: %^{citekey}
:URL: %^{url}
:AUTHOR: %^{author-or-editor}
:NOTER_DOCUMENT: %^{file}
:NOTER_PAGE:
:END:
%?
* Annotations (Zotero)
%(my-orb-latex-note-to-org \"${citekey}\")
myshevchuk commented 2 years ago

Hi @prashantnag93, you should not escape the quote marks " in the template file, only in Elisp. Furthermore, it's better to use the %^{...}-style placeholders in a template file rather than ${...} to avoid being prompted to type in the field value. This is how the non-native to Org capture templates${...} placeholders currently work in template files with Org-roam/ORB.

That part of your template file may thus look as follows:

* Annotations (Zotero)
%(my-orb-latex-note-to-org "%^{citekey}")
prashantnag93 commented 2 years ago

Thank you @myshevchuk for your help. It is working now.