Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reference unique id across emacs org-mode files

Tags:

emacs

org-mode

I have several .org files, and I'd like to be able to create links between them using an ID. I am using DOIs as unique identifiers. I can link within a file by using properties:

* Paper 1
  :PROPERTIES:
  :CUSTOM_ID: 10.1088/0953-8984/23/21/213001
  :END:

* Paper 2
  :PROPERTIES:
  :CUSTOM_ID: 10.1038/nphys2935
See also [[#10.1088/0953-8984/23/21/213001]]

Is there a way to make the custom_id global, so I can reference it from another file?

I think that org-id is what I need to go further, but I've found the documentation a little confusing. I tried adding the following lines in my .emacs

;; Use global IDs
(require 'org-id)
(setq org-id-link-to-org-use-id use-existing)

;; Update ID file .org-id-locations on startup
(org-id-update-id-locations)

but the file .emacs.d/.org-id-locations only has nil.

It seems like global links won't be automatically generated (Assign IDs to every entry in Org-mode). I tried (with cursor on the heading) to use M-x org-id-get-create, but this does not seem to do anything.

EDIT: (Based on helpful comment)

Within one session, I can store and create links using M-x org-store-link while on the heading (Paper 1 in my example above). Then I can use M-x org-insert-link, and type the ID to insert the link. The link looks like [[id:10.1088/0953-8984/23/21/213001][Paper 1]]. But I am running into two problems: (1) I'd like the ids to be stored automatically. (2) The links don't work when I close and re-open the file.

EDIT: A related question:

https://emacs.stackexchange.com/questions/2186/have-org-modes-exported-html-use-custom-id-when-linking-to-sub-sections-in-toc

like image 785
amd Avatar asked Nov 25 '14 16:11

amd


People also ask

How do you add a link in Org mode?

Links in Org are plain text, and you can type or paste them straight into the buffer. By using this command, the links are automatically enclosed in double brackets, and you will be asked for the optional descriptive text.

How do I enter Org Mode in Emacs?

Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document.

Does Org mode come with Emacs?

Emacs has included Org Mode as a major mode by default since 2006. Bastien Guerry is the current maintainer, in cooperation with an active development community. Since its success in Emacs, some other systems now provide functions to work with org files.

How do you make a table in Org mode?

The easiest way to create a table is to directly type the "|" character at the beginning of a line, or after any amount of white space. This will put you in the first field of an atomic table. Once you've finished editing this cell, you can jump to the next one by pressing TAB .


1 Answers

So here's the solution I came up with.

  1. In my .emacs configuration, I have kept the same settings as in my question:

    (require 'org-id)
    (setq org-id-link-to-org-use-id use-existing)
    
    ;; Update ID file on startup
    (org-id-update-id-locations)
    
  2. The files need to be part of the agenda list (or added to the list of additional files using org-id-extra-files (See org-id documentation))

  3. Use ID instead of CUSTOM_ID in the PROPERTIES drawer:

    * Paper 1
      :PROPERTIES:
      :ID: 10.1088/0953-8984/23/21/213001
      :END:
    
  4. Each ID needs to be created (if necessary; in my case I already have them), and a link added to the ID file (links are stored in .emacs.d/.org-id-locations). This is done using org-id-get-create: with the cursor on the heading, call it using

    M-x org-id-get-create
    
  5. Link to an ID using [[id:10.1088/0953-8984/23/21/213001][Paper 1]].

I have to think a little bit more about when I'd like the ID to be created; I can automate the process by tying the ID storing to another function that I'll do to all the headings.

like image 178
amd Avatar answered Nov 06 '22 01:11

amd