Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import annotations from Zotero #178

Open
bepolymathe opened this issue Mar 14, 2021 · 11 comments
Open

Import annotations from Zotero #178

bepolymathe opened this issue Mar 14, 2021 · 11 comments
Labels
1. enhancement New feature or request

Comments

@bepolymathe
Copy link

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 :

  • \section{} began an headline
  • \par began a citation with #+BEGIN_QUOTE

It would be great.

@myshevchuk
Copy link
Member

Hi,

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

@myshevchuk
Copy link
Member

myshevchuk commented Mar 14, 2021

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

@myshevchuk myshevchuk added the 1. enhancement New feature or request label Mar 14, 2021
@bepolymathe
Copy link
Author

Hi @myshevchuk !

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

@myshevchuk
Copy link
Member

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

@bepolymathe
Copy link
Author

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

@baogiadoan
Copy link

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
Copy link
Member

myshevchuk commented Jul 16, 2022

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
Copy link

thanks @myshevchuk it's working now

@prashantnag93
Copy link

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
Copy link
Member

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants