How to create cleaner structured notes?

Hi!
I posted this message on Slack, but I want to put here to see if others have faced the same problem.

I want to know how to create cleaner structured notes (a hub or compilation of several notes). I like a lot the way the Archive (https://zettelkasten.de/the-archive/) formats its notes. It uses only the timestamp as unique ID and all the notes are linked that way.

For example, if I write,

The logistic regression

Normally org-roam will replace the text with the proper link to file

The [[file:20200612000001-definition_logistic_regression.org][Logistic regression]]...

However, imagine that you have lot of references in your paragraph specially in structured notes.

The definition in A explains B and C, and therefore we conclude D.

(Here A, B, C, D are links to notes)

This could be cumbersome, especially if the names in the notes are large.

Ideally, I would like that fuzzy links autocomplete the sentence like this

The logistic regression [[file:20200612000001-definition_logistic_regression.org][20200612000001]]...

But it should change a lot of the internals of org-roam.

One excellent solution given by @Zetagon is to use footnotes to reference the text.

I’m experimenting with this format for my notes:

The logistic regression [fn:20200612000001] ....

* Footnotes
[fn:20200612000001] [[file:20200612000001-definition_logistic_regression.org][Logistic regression]]

I extract the timestamp using the function cdlatex-insert-filename and erasing the slug part.

Of course this is not as clean as I would, but it works.

Other option is to extract the ROAM_KEY as the key for the footnote. However, I don’t have any idea how to easily extract those in a buffer.

Does anybody have any idea to make this smoother or any additional suggestion?

Thanks.

Hi!

if I understand you correctly, you dislike long links in your notes.

A solution could be to change the link text after the linking. You can do this by calling org-insert-link while your cursor is on the link to edit the text as you like.

Alternatively you could write the link label, mark it and then call org-roam-insert or org-roam-find-file. The inserted link will use the marked text as label.

Does that solve your problem?

1 Like

Yes indeed. I’m experimenting using ids as linking form, but yes this is an excellent tip. Thanks.

I think this may be of interest to anyone else who comes along https://discord.com/channels/406534637242810369/695219268358504458/781858450069782538

(defun my/org-roam-insert (&optional lowercase completions filter-fn description link-type)
  "Find an Org-roam file, and insert a relative org link to it at point.
Return selected file if it exists.
If LOWERCASE is non-nil, downcase the link description.
LINK-TYPE is the type of link to be created. It defaults to \"file\".
COMPLETIONS is a list of completions to be used instead of
`org-roam--get-title-path-completions`.
FILTER-FN is the name of a function to apply on the candidates
which takes as its argument an alist of path-completions.
If DESCRIPTION is provided, use this as the link label.  See
`org-roam--get-title-path-completions' for details."
  (interactive "P")
  (unless org-roam-mode (org-roam-mode))
  ;; Deactivate the mark on quit since `atomic-change-group' prevents it
  (unwind-protect
      ;; Group functions together to avoid inconsistent state on quit
      (atomic-change-group
        (let* (region-text
               beg end
               (_ (when (region-active-p)
                    (setq beg (set-marker (make-marker) (region-beginning)))
                    (setq end (set-marker (make-marker) (region-end)))
                    (setq region-text (buffer-substring-no-properties beg end))))
               (completions (--> (or completions
                                     (org-roam--get-title-path-completions))
                                 (if filter-fn
                                     (funcall filter-fn it)
                                   it)))
               (title-with-tags (org-roam-completion--completing-read "File: " completions
                                                                      :initial-input region-text))
               (res (cdr (assoc title-with-tags completions)))
               (title (or (plist-get res :title)
                          title-with-tags))
               (target-file-path (plist-get res :path))
               (description (or description region-text title))
               (description (if lowercase
                                (downcase description)
                              description)))
          (cond ((and target-file-path
                      (file-exists-p target-file-path))
                 (when region-text
                   (delete-region beg end)
                   (set-marker beg nil)
                   (set-marker end nil))
                 (insert "[[fn:" (org-roam--path-to-slug target-file-path) "]]")
                 (save-excursion
                   (org-footnote-goto-definition (org-roam--path-to-slug target-file-path) (org-footnote-create-definition (org-roam--path-to-slug target-file-path)))
                   (insert " " (org-roam-format-link target-file-path description link-type))))
                (t
                 (let ((org-roam-capture--info `((title . ,title-with-tags)
                                                 (slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
                       (org-roam-capture--context 'title))
                   (setq org-roam-capture-additional-template-props (list :region (org-roam-shield-region beg end)
                                                                          :insert-at (point-marker)
                                                                          :link-type link-type
                                                                          :link-description description
                                                                          :finalize 'insert-link))
                   (org-roam-capture--capture))))
          res))
    (deactivate-mark)))

With possibly this instead

 (insert "[fn:" (org-roam--path-to-slug target-file-path) "]")```
1 Like

Thanks, @emiller. I’ll definitely will use it.

Given the imminent transition to V2, I just want to update the previous function for the new node-link scheme.

Basically is a copy of the org-roam-node-insert from V2, but with an additional conditional to add footnote like links.

In my doom config I have

  (map! :leader
        :prefix "r"
        :desc "org-roam" "l" #'org-roam-buffer-toggle
        :desc "org-roam-node-insert" "i" #'org-roam-node-insert
        :desc "org-roam-node-insert" "I" #'maikol/org-roam-node-insert
        :desc "org-roam-node-find" "f" #'org-roam-node-find
        :desc "org-roam-ref-find" "r" #'org-roam-ref-find
        :desc "org-roam-show-graph" "g" #'org-roam-graph
        :desc "org-roam-capture" "c" #'org-roam-capture
        :desc "org-roam-dailies-capture-today" "j" #'org-roam-dailies-capture-today)
(setq org-roam-footnote-style t)

  (defun maikol/org-roam-node-insert (&optional filter-fn)
    "Find an Org-roam file, and insert a relative org link to it at point.
Return selected file if it exists.
If LOWERCASE is non-nil, downcase the link description.
FILTER-FN is the name of a function to apply on the candidates
which takes as its argument an alist of path-completions."
    (interactive)
    (unwind-protect
        ;; Group functions together to avoid inconsistent state on quit
        (atomic-change-group
          (let* (region-text
                 beg end
                 (_ (when (region-active-p)
                      (setq beg (set-marker (make-marker) (region-beginning)))
                      (setq end (set-marker (make-marker) (region-end)))
                      (setq region-text (org-link-display-format (buffer-substring-no-properties beg end)))))
                 (node (org-roam-node-read region-text filter-fn))
                 (description (or region-text
                                  (org-roam-node-title node))))
            (if (org-roam-node-id node)
                (progn
                  (when region-text
                    (delete-region beg end)
                    (set-marker beg nil)
                    (set-marker end nil))
                  (if org-roam-footnote-style
                      (progn
                        (insert "[fn:" (org-roam-node-id node) "]")
                        (save-excursion
                          (org-footnote-goto-definition (org-roam-node-id node)
                                                        (org-footnote-create-definition (org-roam-node-id node)))
                          (insert " " (org-link-make-string
                                       (concat "id:" (org-roam-node-id node))
                                       description))))
                    (insert (org-link-make-string
                             (concat "id:" (org-roam-node-id node))
                             description))
                    ))
              (org-roam-capture-
               :node node
               :props (list :region (when (and beg end)
                                      (cons beg end))
                            :insert-at (point-marker)
                            :link-description description
                            :finalize 'insert-link)))))
      (deactivate-mark)))

  )
1 Like