egh / zotxt-emacs

140 stars 11 forks source link

zotxt needs examples and a tutorial. #59

Open EmmanuelCharpentier opened 3 years ago

EmmanuelCharpentier commented 3 years ago

I have used used bibtex for 34 years (and counting...). I recently started to use org-mode, where I use org-ref with .bib files, and dabbled lightly with markdown (via pandoc), again using .bib files.

I have, however, a strong incentive to use Zotero with as little interim steps as possible : Zotero is the base bibliographic tool of by workplace, where most of the work is done with Word, and none of my coworker is a LaTeX, org-mode or markdown user.

I tried, again, to figure out how to use zotxt : installation is easy, and I am able to use org-zotxt-insert-reference-link (C-c " i) to search for a publication and insert a "zotero link" in the buffer (a reference to the Zotero database and the (simplified) text of a citation).

But I am unable to figure out how to use this link :

I am probably erring by drifting too close to the LaTeX/org-mode/pandoc model. A tutorial explaining the use of these links would be useful (notwithstanding the fact that the only commands bound to keys are org-zotxt-insert-reference-link and zotxt-citekey-insert) ; an example file, quicker to create, could be sufficient.

ChauhanT commented 3 years ago

I am on doom emacs. I just want to see my list of zotero refs and create links to the underlying PDF files :D Can't figure out how to do this! But the fact that he software exists and is maintained is amazing <3 I think Emacs has a package for almost everything!

egh commented 3 years ago

Hi @EmmanuelCharpentier

Yes, I agree :smile: and I'm sorry, as you can see by my late response I can't promise anything - I've been busy with other things.

In general, if you use org-mode, you probably can't (at the moment) end up with a proper paper with references and a bibliography - but you can insert links. If you use markdown + pandoc, you should be able to insert references.

However, with the merge of the org-cite stuff, it should be possible to make the interaction work better.

titaniumbones commented 2 years ago

@egh I'd love to see this move forward. Is there anythhing I can do to make it easier to use zotero directly in my org cites?

egh commented 2 years ago

Hi @titaniumbones ! Sorry for the delay.

Yes, my top priority is making zotxt work properly with org cite. I think it will be pretty easy to do.

If you set

 (setq org-zotxt-link-description-style :citation)

You should be able to insert org-cite citations with C-" k (if you enabled zotxt-citekey-mode) You'll need to manually add [cite:...]

You'll still need to export a JSON or BibTeX file manually for use in your org document, but I'm hoping it will be pretty easy to to hook it up so you don't have to do this.

Awannaphasch2016 commented 2 years ago

I do agree that popular packages should always have strong example, tutorial, and documentation.

But the nature of open source doesn't take developer time and populatiry projection into account.

It is best to have ability to read and figure out code your self. I wouldn't say that this is a hard constraint, but if you going to go emacs route. 95 percent of the time you can blaze through the problem, but the last 5 percent will fall into similar problem you are having now.

I am excited for a great documentation, nontheless.

Good luck!.

Stwerp commented 7 months ago

If you set

 (setq org-zotxt-link-description-style :citation)

You should be able to insert org-cite citations with C-" k (if you enabled zotxt-citekey-mode) You'll need to manually add [cite:...]

This does seem to be working. In the line at https://github.com/egh/zotxt-emacs/blob/3f24b29e9b9a6401416e67ed11b486cba60bbad5/zotxt.el#L412 if that is changed to

(format "cite:&%s" (plist-get item :citekey)))

then things seem to work well for me with org-ref.

My steps were: 1) Install orgtxt Zotero plugin, and the orgtxt package from melpa for emacs 2) Download a betterbibtex export from Zotero and place it in my current directory 3) Point to the csl style with #+csl-style: ieee.csl 4) Make the bibliography with bibliography:refs.bib at the end of the org file. 5) Insert references with the citekey mode you described. 5) When I export with org-ref, things seem to be working well!

There was a weird thing about needing to set the default library to ":all" to work with shared libraries, but that seemed to just need to be a custom variable to set, and it seems to be smooth sailing.

Maybe breaking off the link formatting in the line linked to above so that we could write a custom function, or making a custom variable would help. It sounds like the one as-is is built around markdown formatting? I'm not sure what makes since here, besides just re-defining the whole function for now in my config files.

Stwerp commented 7 months ago

And replying to my last message here in case anyone else runs into this. There's an issue with the deferred package related to scope of variables in the the let statement (see https://github.com/kiwanami/emacs-deferred/issues/54 ). It doesn't seem to be affecting zotxt for now, but when I redefined my zotxt-citekey-insert function to change the citation format, it worked when evaluated from the scratch buffer, it worked when I modified the function in the zotxt.el directly, but would return a void-variable error in when I defined the function in my config files. The solution is to quote the deferred chain lambda. Here's my redefine. I put this in the :config section of my (use-package zotxt) statement:

(defun zotxt-citekey-insert (arg)
    "Insert a citekey.

Prompts for search to choose item.  If prefix argument ARG is used,
will insert the currently selected item from Zotero.  If double
prefix argument is used the search method will have to be
selected even if `zotxt-default-search-method' is non-nil"
    (interactive "p")
    (let ((mk (point-marker)))
      (deferred:$
       (zotxt-choose-deferred arg)
       (deferred:nextc it
                       (lambda (items)
                         (zotxt-mapcar-deferred (lambda (item)
                                                  (zotxt-get-item-deferred item :citekey))
                                                items)))
       (deferred:nextc it
                       `(lambda (items)
                          (let ((current-buffer (current-buffer)))
                            (with-current-buffer current-buffer

                              (goto-char (marker-position ,mk))
                              (insert (mapconcat
                                       (lambda (item)
                                         (format "cite:&%s" (plist-get item :citekey)))
                                       items " "))))))
       (deferred:error it #'zotxt--deferred-handle-error)
       (if zotxt--debug-sync (deferred:sync! it)))))

Key being the backtick for the lambda, and then the comma before mk.

jacobkasper commented 6 months ago

And replying to my last message here in case anyone else runs into this. There's an issue with the deferred package related to scope of variables in the the let statement (see kiwanami/emacs-deferred#54 ). It doesn't seem to be affecting zotxt for now, but when I redefined my zotxt-citekey-insert function to change the citation format, it worked when evaluated from the scratch buffer, it worked when I modified the function in the zotxt.el directly, but would return a void-variable error in when I defined the function in my config files. The solution is to quote the deferred chain lambda. Here's my redefine. I put this in the :config section of my (use-package zotxt) statement:

(defun zotxt-citekey-insert (arg)
    "Insert a citekey.

Prompts for search to choose item.  If prefix argument ARG is used,
will insert the currently selected item from Zotero.  If double
prefix argument is used the search method will have to be
selected even if `zotxt-default-search-method' is non-nil"
    (interactive "p")
    (let ((mk (point-marker)))
      (deferred:$
       (zotxt-choose-deferred arg)
       (deferred:nextc it
                       (lambda (items)
                         (zotxt-mapcar-deferred (lambda (item)
                                                  (zotxt-get-item-deferred item :citekey))
                                                items)))
       (deferred:nextc it
                       `(lambda (items)
                          (let ((current-buffer (current-buffer)))
                            (with-current-buffer current-buffer

                              (goto-char (marker-position ,mk))
                              (insert (mapconcat
                                       (lambda (item)
                                         (format "cite:&%s" (plist-get item :citekey)))
                                       items " "))))))
       (deferred:error it #'zotxt--deferred-handle-error)
       (if zotxt--debug-sync (deferred:sync! it)))))

Key being the backtick for the lambda, and then the comma before mk.

Thanks, this is great! How do you handle citing multiple citations simultaneously? Mine show up as (Smith, 2020) (Rabbit, 2021).

Stwerp commented 6 months ago

I ended up manually editing the links with multiple citations. So the zotxt commands would insert cite:&key1cite:&key2 and I would edit it to cite:&key1;&key2 by hand. It's a little clunky, but at that point the org-ref engine could take over and put it correctly per the CSL file's specifications.