weirdNox / org-noter

Emacs document annotator, using Org-mode
GNU General Public License v3.0
1.07k stars 101 forks source link

Customizable variable for note template? #45

Open yanghaoxie opened 6 years ago

yanghaoxie commented 6 years ago

I use helm-bibtex, I sometime create new notes from helm-bibtex interface. helm-bibtex has a variable bibtex-completion-notes-template-one-file which customize the note entries of new notes.

It will be consistent and smooth, if we can customize the org-noter note-template, such that it is consistent with helm-bibtex.

I know a little elisp, and I read some source code of org-noter, however, I did not find some similar options.

weirdNox commented 6 years ago

Hello! What should be the template in order to be compatible? Do you want to create the note from the bibtex interface?

yanghaoxie commented 6 years ago

Hi! Thanks for your contributions, the package helps a lot!

  1. About question one.

Just some thoughts, maybe they are stupid or wrong. I would like to hear your comments.

weirdNox commented 5 years ago

Thanks for the comment :)

About your request, what should a note have in order to be compatible?

Like you said, as the other way is more flexible and knows about your articles organization, it is trivial to do. I have this in my config:

(use-package org-ref :ensure
  :after bibtex
  :demand
  :config
  (setq! org-ref-default-bibliography '("~/Documents/Bibliography/References.bib")
         org-ref-bibliography-notes "~/Documents/Bibliography/Notes.org"
         org-ref-pdf-directory "~/Documents/Bibliography/PDFs/"
         reftex-default-bibliography org-ref-default-bibliography
         bibtex-completion-bibliography (car org-ref-default-bibliography)
         bibtex-completion-notes-path org-ref-bibliography-notes
         bibtex-completion-library-path org-ref-pdf-directory

         ;; NOTE(nox): Key generation
         bibtex-autokey-names 2
         bibtex-autokey-names-stretch 1
         bibtex-autokey-name-separator "-"
         bibtex-autokey-additional-names "-et_al"
         bibtex-autokey-year-length 4
         bibtex-autokey-year-title-separator "_")

  (require 'org-ref-ivy))

(use-package ivy-bibtex :ensure
  :config
  (setq! bibtex-completion-notes-template-one-file (format "* ${title} - ${year}
:PROPERTIES:
:Custom_ID: ${=key=}
:NOTER_DOCUMENT: %s${=key=}.pdf
:END:
"
                                                           org-ref-pdf-directory)
         bibtex-completion-display-formats
         '((t . "${=type=:7} | ${title:*} ${author:20} ${year:4} ${=has-pdf=:1}${=has-note=:1}  ${keywords:80}")))

  (defun nox*disable-completion-notes-mode (&optional _) (widen))
  (advice-add #'bibtex-completion-notes-mode :override #'nox*disable-completion-notes-mode))

When you say note, are you talking about a note in a page or the collection of notes annotating a document. Like, each note, or the parent heading with NOTER_DOCUMENT?

yanghaoxie commented 5 years ago

Sorry for wait so long to reply. I am going to give examples of what I mean.

Example 1. Create notes when there is not an heading for current file.

my ivy-bibtex configuration is like this

(use-package ivy-bibtex
  :ensure t
  :defer t
  :init
  (my/leader-keys
    "ib" 'ivy-bibtex)
  (setq bibtex-completion-pdf-field "file"
    bibtex-completion-find-additional-pdfs t
    bibtex-completion-bibliography "~/Dropbox/software/Zotero/bibtex/main.bib"
    bibtex-completion-notes-path "~/Dropbox/document/org/references/ref-notes.org"
    bibtex-completion-notes-template-one-file
    "\n* ${title} cite:${=key=}\n  :PROPERTIES:\n  :Custom_ID:  :${=key=}\n  :NOTER_DOCUMENT: ${file}\n  :END:\n\n"))

If I execute ivy-bibtex, all I browse all my bibtex items, if I hit M-o, I can choose to edit notes for the bibtex entry, and ivy-bibtex will create the heading for this bibtex item (following the value of bibtex-completion-notes-template-one-file). An example is here,

* Mobile Edge Computing: A Survey cite:AbbasMobile2018
  :PROPERTIES:
  :Custom_ID:  :AbbasMobile2018
  :NOTER_DOCUMENT: /home/yhxie/Zotero/storage/9ZQFTBDD/AbbasMobile2018.pdf
  :END:

However, if I execute org-noter when the focus is in AbbasMobile2018.pdf, org-noter will creat a heading like this (If there is not a heading in my ref-notes.org for this file)

* AbbasMobile2018
  :PROPERTIES:
  :NOTER_DOCUMENT: ../../../../Zotero/storage/9ZQFTBDD/AbbasMobile2018.pdf
  :NOTER_PAGE: 1
  :END:

You see, ivy-bibtex and org-noter create different heading for the same bibtex entry.

Example 2. Create notes when I first create note heading using org-noter, then I choose Edit notes in ivy-bibtex.

* AbbasMobile2018
  :PROPERTIES:
  :NOTER_DOCUMENT: ../../../../Zotero/storage/9ZQFTBDD/AbbasMobile2018.pdf
  :NOTER_PAGE: 1
  :END:

* Mobile Edge Computing: A Survey cite:AbbasMobile2018
  :PROPERTIES:
  :Custom_ID:  :AbbasMobile2018
  :NOTER_DOCUMENT: /home/yhxie/Zotero/storage/9ZQFTBDD/AbbasMobile2018.pdf
  :END:

It seems like that ivy-bibtex does not recognize heading created by org-noter

Example 3.

Create notes using ivy-bibtex, and execute org-noter in corresponding files.

* Mobile Edge Computing: A Survey cite:AbbasMobile2018
  :PROPERTIES:
  :Custom_ID:  :AbbasMobile2018
  :NOTER_DOCUMENT: /home/yhxie/Zotero/storage/9ZQFTBDD/AbbasMobile2018.pdf
  :NOTER_PAGE: 1
  :END:

It seems like that org-noter can recognize heading created by ivy-bibtex.

Discussion

  1. In Example 1, can we make the two heads be the same.
  2. In Example 2, this seems a unwanted feature(bug).
  3. In Example 3, this works fine.
  4. Therefore, it would be nice if no matter how I create the notes, the headings are the same, and no duplicated headings.
weirdNox commented 5 years ago

Ohhh, I see! Thanks for the examples, this helps a lot!

The PDF name is "KEY.pdf" right? That may be a way to get the Custom_ID you need, which would be enough for ivy-bibtex to find the heading. Now, the title itself I don't know how to generate, we probably would have to query ivy-bibtex itself in order fetch it from the .bib file. I'll see if that's possible!

Sidenote: I noticed you are using Zotero with ivy-bibtex, do you have that documented somewhere? I tried to do that, but didn't find that much information about it...

yanghaoxie commented 5 years ago

You are welcome! And thanks your such fast reply!

  1. The name of PDF indeed is "KEY.pdf"

  2. The Custom_ID just my setting, maybe someone else like other properties. Anyway, best way is fetch filed from bibtex entry. In this way, we could generate any heading using any information that the pdf has (if the pdf associated to a bibtex entry).

  3. About Zotero.

a. It seems like I use this guide http://iflysib14.iflysib.unlp.edu.ar/tomas/en/blog/reference-management.html.

b. In addition, I use another very useful function (my/org-ref-open-pdf-at-point). I use org-ref to manage references when I take notes in org-mode, my/org-ref-open-pdf-at-point can open pdf if your cursor is at one org-ref cite key(e.g., cite:ShiEdge2016) (of cause, this bibtex entry should have a file filed which shows the absolute path of the file, and this can be exported by zotero).

(defun my/org-ref-open-pdf-at-point ( )
  "Open the pdf for bibtex key under point if it exists."
  (interactive)
  (let* ((results (org-ref-get-bibtex-key-and-file))
         (key (car results))
         (pdf-file (car (bibtex-completion-find-pdf key))))
    (if (file-exists-p pdf-file)
        (org-open-file pdf-file)
      (message "No PDF found for %s" key))))
weirdNox commented 5 years ago

Thanks!

Also, I just skimmed through bibtex-completion.el and found bibtex-completion-get-entry, which seems to return the key, type, title, etc. It seems to be it! I'm thinking of a way to integrate this to my package.

yanghaoxie commented 5 years ago

You are welcome!

That is cool. Hope it will make org-noter nicer.

samspo commented 5 years ago

Hello,

Thanks for org-noter, a very nice package. An integration with ivy/helm-bibtex would be very useful. It could simplify a lot my note taking process.

Someone already have done something that can help (https://github.com/hitswint/.emacs.d/blob/c77907cefc6e0003bbee08801c55a9e41ce0c39c/lisp/setup_org_mode.el#L508)

For me, the perfect solution would be that we only need the Custom_ID to open the pdf file. No need of the ":NOTER_DOCUMENT:" property. --> Thanks to the custom_id and the .bib file used by ivy/helm-bibtex (or org-ref) we could open the document

Concerning zotero integration (this suppose that the bibtex file has been exported), see here: https://github.com/tmalsburg/helm-bibtex

If the BibTeX entries have a field that specifies the full path to the PDFs, that field can also be used. For example, JabRef and Zotero store the location of PDFs in a field called File: (setq bibtex-completion-pdf-field "File")

There is also a direct integration between zotero and org noter here (but don't know if it works): https://gitlab.com/egh/zotxt-emacs/blob/master/org-zotxt.el#L230

weirdNox commented 5 years ago

Yes, that's a great idea, @samspo, thanks!

yiufung commented 5 years ago

This might be of use for someone: to synchronize org-ref and org-noter, you may change org-ref template, so that org-noter will find it.

  ;; Add NOTER_DOCUMENT to org-ref template
  (setq org-ref-note-title-format
        "** TODO %y - %t
 :PROPERTIES:
  :Custom_ID: %k
  :AUTHOR: %9a
  :NOTER_DOCUMENT: %F
  :JOURNAL: %j
  :YEAR: %y
  :VOLUME: %v
  :PAGES: %p
  :DOI: %D
  :URL: %U
 :END:
")

Make sure you have / ending in org-ref-pdf-directory, so that org-ref concatenates the correct path.

ghost commented 4 years ago

It would be great if org-noter could read the (setq bibtex-completion-pdf-field "File") entry as Zotero and better bib(la)tex export the file field as a jabref link Full Text PDF:files/982/Zimmerman - 2017 - The Youth of Things Life and Death in the Age of .pdf:application/pdf

averter commented 4 years ago

Very interesting thread! I am using a combo of helm-bibtex+org-ref+pdf-tools+org-noter having migrated originally from Zotero. Because of that, my pdfs are partly in zotero-made directories (ZD) and partly in the org-ref-pdf-directory (ORD). As a consequence, when taking notes at a pdf in the ZD it creates a new * header from org-noter, and otherwise it creates/updates an org-ref header (which I prefer). Although it has already been pointed out that the pdf is the ID used to find notes, I just wanted to report that when using org-noter, if migrating from Zotero, it is possible to see this bipolar behavior. Any updates regarding a fix for this issue? Thanks!

jlteekiste commented 3 years ago

Hi, I am completely new to emacs, having recently discovered it can do all the things I am looking for in terms of note-taking and text-production for my PhD. I'm in awe of the tool that has been collectively crafted by so many people - thanks for this package.

I am having a hard time figuring out how to get org-noter and helm-bibtex (and perhaps org-ref?) to work together and I think my use-case is the same as those described in this thread, but I'm not sure if there is a solution yet:

I came across this configuration which seems to have achieved that by adding this to the bibtex-completion file template (though multiple files in this case) : ":NOTER_DOCUMENT: %(orb-process-file-field \"${=key=}\")\n" Unfortunately I am completely illiterate when it comes to code but I hoped that replacing orb-process-file-fieldwith bibtex-completion-find-pdfwould produce the desired outcome, but I got an Error in NOTER_DOCUMENT (I'll be using org-roam too, but separately from this notes file. )

Can this be done?